{"id":336865,"date":"2022-08-10T15:00:46","date_gmt":"2022-08-10T15:00:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=336865"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=336865","title":{"rendered":"<span>\u041f\u0440\u043e\u0441\u0442\u043e\u0435 REST api \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u0430 \u043d\u0430 php \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0440\u0435\u0441\u0442 \u0430\u043f\u0438 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0421\u041f\u0410 (Vue, React \u0438\u043b\u0438 \u0434\u0440.) \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, CMS \u0438\u043b\u0438 \u0447\u0435\u0433\u043e-\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c php \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u043e\u043c \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0443\u0441\u0438\u043b\u0438\u044f\u043c\u0438 \u043d\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443. \u00a0\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0430\u043c \u0436\u0435 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0438 \u0441\u0430\u043c \u0441\u0430\u0439\u0442 \u0421\u041f\u0410 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430 vue).<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 php \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u0430\u043f\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 php \u0444\u0430\u0439\u043b\u044b, \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u043f\u0430\u043f\u043a\u0430\u0445 \u043d\u0430 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u043d\u0438\u043c. \u0418 \u0445\u043e\u0442\u044f, \u0432\u0438\u0434\u0438\u043c\u043e \u0432 \u0441\u0432\u043e\u0451 \u0432\u0440\u0435\u043c\u044f, \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b \u0448\u0438\u0440\u043e\u043a\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044e php \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043b\u0435\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0441\u043a\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0430\u043f\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Node.js Express \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u0435\u043d, \u0438 \u043f\u0440\u043e\u0441\u0442 \u0434\u043b\u044f \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 &#171;pecee\/simple-router&#187;.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u0434\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e (LAMP, XAMP, docker) \u0438\u043b\u0438 \u043a\u0430\u043a-\u0442\u043e \u0438\u043d\u0430\u0447\u0435 \u0438 \u0443 \u0432\u0430\u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u044b\u0439 \u0444\u0430\u0439\u043b (index.php). \u041a\u0440\u043e\u043c\u0435, \u0442\u043e\u0433\u043e \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 composer.<\/p>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<figure class=\"float bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fd8\/08a\/15d\/fd808a15d62397072c27b66d077058c0.png\" alt=\"\u041d\u0430 \u0420\u0438\u0441.1. \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043e\u0431\u0449\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0422\u043e\u0447\u043a\u043e\u0439 \u0432\u0445\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b \" title=\"\u041d\u0430 \u0420\u0438\u0441.1. \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043e\u0431\u0449\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0422\u043e\u0447\u043a\u043e\u0439 \u0432\u0445\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b \" width=\"355\" height=\"472\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fd8\/08a\/15d\/fd808a15d62397072c27b66d077058c0.png\"\/><figcaption>\u041d\u0430 \u0420\u0438\u0441.1. \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043e\u0431\u0449\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0422\u043e\u0447\u043a\u043e\u0439 \u0432\u0445\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b <\/figcaption><\/figure>\n<p>      index.php\u0432 \u043f\u0430\u043f\u043a\u0435 web. \u0421\u0430\u043c\u0430 \u043f\u0430\u043f\u043a\u0430 web\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0439 \u043f\u0430\u043f\u043a\u043e\u0439, \u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043a\u0430\u043a \u043a\u043e\u0440\u043d\u0435\u0432\u0430\u044f. \u0412 \u043f\u0430\u043f\u043a\u0435 config\u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0440\u043e\u0443\u0442\u043e\u0432 \u043d\u0430\u0448\u0438\u0445 \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432. \u0412 \u043f\u0430\u043f\u043a\u0435 controller\u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432. \u0412 \u043f\u0430\u043f\u043a\u0435 middlewares\u043c\u044b \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0440\u043e\u0443\u0442\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430. \u0412 \u043f\u0430\u043f\u043a\u0430\u0445 exceptions, views \u0438 models \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, html \u0448\u0430\u0431\u043b\u043e\u043d \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438.  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/i-luka\/api-php\/tree\/revision1\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<h3>\u0418\u043d\u0441\u0442\u0430\u043b\u043b\u044f\u0446\u0438\u044f \u0438 \u0437\u0430\u043f\u0443\u0441\u043a<\/h3>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 composer.json (composer install \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430).<\/p>\n<pre><code class=\"json\">\/\/ composer.json {     \"require\": {         \"pecee\/simple-router\": \"*\",         \"lcobucci\/jwt\": \"^3.4\",         \"ext-json\": \"*\"     },     \"autoload\": {         \"psr-4\": {             \"app\\\\\": \"\"         }     } } <\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u2018app\\\u2019 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e \u043a\u0430\u043a \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f namespace. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u0435\u0439\u043c\u0441\u043f\u0435\u0439\u0441\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a \u0432\u0441\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 Router::route() \u0432 \u0444\u0430\u0439\u043b\u0435 index.php<\/p>\n<pre><code class=\"php\">&lt;?php \/\/index.php  use Pecee\\SimpleRouter\\SimpleRouter as Router;  require_once __DIR__ . '\/..\/vendor\/autoload.php'; require_once (__DIR__ . '\/..\/config\/routes.php');      Router::start();<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0442\u0443\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u0440\u043e\u0443\u0442\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0439\u043b\u0435 config\/routes.php.<\/p>\n<h3>\u00a0\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 SPA \u043d\u0430 Vue.js 2 \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443 \u043d\u0430 php<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0437\u0432\u0451\u0440\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u0441\u0431\u043e\u0440\u043a\u0443 vue \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u0430\u043f\u0438, \u0442\u043e \u044d\u0442\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u043e, \u043a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 vue \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043f\u0430\u043f\u043a\u0443 web. \u00a0\u0412 \u0444\u0430\u0439\u043b\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 (\u2018\/config\/routes.php\u2019) \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0434\u0432\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php  use Pecee\\{     SimpleRouter\\SimpleRouter as Router };  Router::setDefaultNamespace('app\\controllers'); Router::get('\/', 'VueController@run'); \/\/ \u043f\u0440\u0430\u0432\u0438\u043b\u043e 1 Router::get('\/controller', 'VueController@run')     ->setMatch('\/\\\/([\\w]+)\/'); \/\/ \u043f\u0440\u0430\u0432\u0438\u043b\u043e 2 <\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0443\u0441\u0442\u043e\u0433\u043e (\u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e) \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 &#8216;\/&#8217; \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 run \u043a\u043b\u0430\u0441\u0441\u0430 VueController. \u0412\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0447\u0442\u043e \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u044f\u0432\u043d\u043e \u043d\u0435\u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f VueController, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u0430 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 vue. \u042d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u043e \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0443\u0436\u0435 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438. \u041c\u0435\u0442\u043e\u0434 run \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u0444\u0430\u0439\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 renderTemplate(), \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.\u00a0\u00a0 \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0440\u043e\u0443\u0442\u0430\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e setDefaultNamespace.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\controllers;  class VueController extends AbstractController {     public function run()     {         return $this->renderTemplate('..\/views\/vue\/vue_page.php');     } } <\/code><\/pre>\n<p>\u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 vue_page.php \u0442\u043e\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0441\u0431\u043e\u0440\u043a\u0438 vue.<\/p>\n<pre><code class=\"php\">&lt;?php \/\/ vue_page.php include (__DIR__ . '\/..\/..\/web\/index.html'); <\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 vue \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443 \u043d\u0430 php, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432 \u043a \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044e \u043d\u0430 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 php. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0447\u0442\u043e \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 AbstractController.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\controllers;  use Pecee\\Http\\Request; use Pecee\\Http\\Response; use Pecee\\SimpleRouter\\SimpleRouter as Router;  abstract class AbstractController {     \/**      * @var Response      *\/     protected $response;     \/**      * @var Request      *\/     protected $request;      public function __construct()     {         $this->request = Router::router()->getRequest();         $this->response =  new Response($this->request);     }      public function renderTemplate($template) {         ob_start();         include $template;         return ob_get_clean();     }      public function setCors()     {         $this->response->header('Access-Control-Allow-Origin: *');         $this->response->header('Access-Control-Request-Method: OPTIONS');         $this->response->header('Access-Control-Allow-Credentials: true');         $this->response->header('Access-Control-Max-Age: 3600');     } } <\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 AbstractController \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u044f $request \u0438 $response. \u0412 $request \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u043e\u043c Pecee\\Http\\Router \u0437\u0430\u043f\u0440\u043e\u0441. \u0410 $response \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0430\u043f\u0438. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u0437\u0434\u0435\u0441\u044c \u043c\u0435\u0442\u043e\u0434 renderTemplate \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 (html \u0441\u0442\u0440\u0430\u043d\u0438\u0446). \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043c\u0435\u0442\u043e\u0434 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439 CORS. \u0415\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0430\u043f\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043d\u0435 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u0430\u0434\u0440\u0435\u0441\u0430, \u0442.\u0435. \u0435\u0441\u043b\u0438 \u0441\u0431\u043e\u0440\u043a\u0430 vue \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0430\u043f\u0438.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 REST API \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432<\/h3>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0430\u043f\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0441\u044b\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0441\u043b\u043e\u0439 ProccessRawBody \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u043a\u0430\u043a middleware \u0432 \u0440\u043e\u0443\u0442\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0430\u043f\u0438.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\middlewares;  use Pecee\\Http\\Middleware\\IMiddleware; use Pecee\\Http\\Request;  class ProccessRawBody implements IMiddleware {      \/**      * @inheritDoc      *\/     public function handle(Request $request): void     {         $rawBody = file_get_contents('php:\/\/input');          if ($rawBody) {             try {              $body = json_decode($rawBody, true);              foreach ($body as $key => $value) {                  $request->$key = $value;              }             } catch (\\Throwable $e) {              }         }     } } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0438\u0437 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 $request \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438\u0437 \u043a\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445. ProccessRawBody \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IMIddleware \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 middleware.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u0440\u043e\u0443\u0442\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0430\u043f\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0441\u043b\u043e\u0439.<\/p>\n<pre><code class=\"php\">&lt;?php \/\/ routes.php Router::group([     'prefix' => 'api\/v1',     'middleware' => [         ProccessRawBody::class     ] ], function () {     Router::post('\/auth\/sign-in', 'AuthController@signin');     Router::get('\/project', 'ProjectController@index'); });<\/code><\/pre>\n<p>\u0423 \u044d\u0442\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u00abapi\/v1\u00bb (\u0442.\u0435. \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &#8216;\/api\/v1\/auth\/sign-in&#8217;), \u0438 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043d\u0430\u043c\u0438 middleware ProccessRawBody::<strong>class<\/strong>, \u0442\u0430\u043a \u0447\u0442\u043e \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 AbstractController \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 $request. AuthController \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u0436\u0435 \u043c\u044b \u0443\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u043c\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 ProjectController::index.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\controllers;  class ProjectController extends AbstractController {     public function index():string     { \/\/ \u041a\u0430\u043a\u0430\u044f-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0443\u0442          return $this->response->json([             [                 'name' => 'project 1'             ],             [                 'name' => 'project 2'             ]         ]);     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043d\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u043e\u0443\u0442\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<h3>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e JWT \u0442\u043e\u043a\u0435\u043d\u0443<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0440\u043e\u0443\u0442\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u041d\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u0445\u043e\u0434 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 jwt-\u0442\u043e\u043a\u0435\u043d\u0430. \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430 \u0438 \u0435\u0433\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u201c lcobucci\/jwt\u201d \u0412\u0441\u0451 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443 \u043d\u0430\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u043f\u043e \u0440\u043e\u0443\u0442\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u0440\u0430\u043d\u0435\u0435 &#8216;\/auth\/sign-in&#8217;. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 AuthController::singin \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u044b\u0434\u0430\u0447\u0438 jwt-\u0442\u043e\u043a\u0435\u043d\u0430 \u043f\u043e\u0441\u043b\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\controllers;  use app\\models\\Request; use ArgumentCountError; use DateTimeImmutable; use Lcobucci\\JWT\\Configuration; use Lcobucci\\JWT\\Signer\\Hmac\\Sha256; use Lcobucci\\JWT\\Signer\\Key\\InMemory;  class AuthController extends AbstractController {     public function signin()     {       \/\/ \u0422\u0443\u0442 \u043a\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f          $config = Configuration::forSymmetricSigner(             new Sha256(),             InMemory::plainText('\u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439_\u043a\u043b\u044e\u0447')         );         $now   = new DateTimeImmutable();         $token = $config->builder()             \/\/ Configures the issuer (iss claim)             ->issuedBy('http:\/\/example.com')             \/\/ Configures the audience (aud claim)             ->permittedFor('http:\/\/example.org')             \/\/ Configures the id (jti claim)             ->identifiedBy('4f1g23a12aa')             \/\/ Configures the time that the token was issue (iat claim)             ->issuedAt($now)             \/\/ Configures the expiration time of the token (exp claim)             ->expiresAt($now->modify('+2 minutes'))             \/\/ Configures a new claim, called \"uid\"             ->withClaim('uid', $user->id)             \/\/ Configures a new header, called \"foo\"             ->withHeader('foo', 'bar')             \/\/ Builds a new token             ->getToken($config->signer(), $config->signingKey());                  return $this->response->json([             'accessToken' => $token->toString()         ]);     } }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0430\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u0434\u043b\u044f jwt \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 &#8216;\u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439_\u043a\u043b\u044e\u0447&#8217;. \u041f\u043e \u043d\u0435\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u0441\u044f \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043a \u0430\u043f\u0438. \u0415\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0443\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0430\u0440\u044b \u043a\u043b\u044e\u0447\u0435\u0439. <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u043a\u043b\u0430\u0439\u043c\u043e\u0432 ->withClaim(&#8216;uid&#8217;, $user->id) \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0442\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0442\u043e\u043c \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0438\u0437 \u043a\u043b\u044e\u0447\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0422\u043e\u043a\u0435\u043d \u0432\u044b\u0434\u0430\u043d \u043d\u0430 2 \u043c\u0438\u043d\u0443\u0442\u044b (->expiresAt($now->modify(&#8216;+2 minutes&#8217;))) \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043e\u043d \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c. ->issuedBy \u0438 ->permittedFor \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f oath2.<\/p>\n<p>\u00a0<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u0440\u043e\u0443\u0442\u043e\u0432 \u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u0443\u044e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u044b \u0440\u043e\u0443\u0442\u043e\u0432 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0441\u043b\u043e\u0439 Authenticate::<strong>class<\/strong>.<\/p>\n<pre><code class=\"php\">&lt;?php \/\/routes.php Router::group([     'prefix' => 'api\/v1',     'middleware' => [         ProccessRawBody::class     ] ], function () {      Router::post('\/auth\/sign-in', 'AuthController@signin');     Router::get('\/project', 'ProjectController@index');      Router::group([         'middleware' => [             Authenticate::class         ]     ], function () {         \/\/ authenticated routes         Router::post('\/project\/create', 'ProjectController@create');         Router::post('\/project\/update\/{id}', 'ProjectController@update')             ->where(['id' => '[\\d]+']);     }); }); <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0433\u0440\u0443\u043f\u043f\u0430 \u0441 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0433\u0440\u0443\u043f\u043f\u044b \u0441 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043e\u043c \u201capi\/v1 \u201d. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u043e\u0443\u0442 &#8216;\/project\/update\/{id}&#8217;. \u0417\u0434\u0435\u0441\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 id \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u043e. \u0412 \u043c\u0435\u0442\u043e\u0434 update, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 Projectcontroller \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f $id \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\controllers;  class ProjectController extends AbstractController {     \/**      * post \/api\/v1\/project\/update\/3      * body:         {             \"project\": {                 \"prop\": \"value\"             }         }      *\/     public function update(int $id): string     { \/\/ \u043a\u043e\u0434 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442         return $this->response->json([             [                 'response' => 'OK',                 'request' => $this->request->project,                 'id' => $id             ]         ]);     } } <\/code><\/pre>\n<p>\u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u0442\u0435\u043f\u0435\u0440\u044c \u043a \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u043c\u0443 \u0441\u043b\u043e\u044e Authenticate::class \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0430\u043f\u0438.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\middlewares;  use app\\exceptions\\NotAuthorizedHttpException; use DateTimeImmutable; use Lcobucci\\Clock\\FrozenClock; use Lcobucci\\JWT\\Configuration; use Lcobucci\\JWT\\Signer\\Hmac\\Sha256; use Lcobucci\\JWT\\Signer\\Key\\InMemory; use Lcobucci\\JWT\\Validation\\Constraint\\SignedWith; use Lcobucci\\JWT\\Validation\\Constraint\\ValidAt; use Pecee\\Http\\Middleware\\IMiddleware; use Pecee\\Http\\Request;  class Authenticate implements IMiddleware {     public function handle(Request $request): void     {         $headers = getallheaders();         $tokenString = substr($headers['Authorization'] ?? '', 7);          $config = Configuration::forSymmetricSigner(             new Sha256(),             InMemory::plainText('\u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439_\u043a\u043b\u044e\u0447')         );          $token = $config->parser()->parse($tokenString);          if (             !$config->validator()->validate(                 $token,                 new SignedWith(                     new Sha256(),                     InMemory::plainText('\u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439_\u043a\u043b\u044e\u0447')                 ),                 new ValidAt(new FrozenClock(new DateTimeImmutable()))             )         ) {             throw new NotAuthorizedHttpException('\u0422\u043e\u043a\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043d\u0435 \u0432\u0430\u043b\u0438\u0434\u0435\u043d \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0440\u043e\u0447\u0435\u043d');         }         $userId = $token->claims()->get('uid');         $request['uid'] = $userId;     } } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c, \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u2018Authorization: Bearer [token]\u2019 (\u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f bearer \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f) \u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0442\u0443\u0434\u0430 \u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u043f\u043e\u0441\u043b\u0435 \u043b\u043e\u0433\u0438\u043d\u0430 \u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u043c\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e. \u0414\u0430\u043b\u0435\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u0440\u0441\u0435\u0440\u0430 jwt-\u0442\u043e\u043a\u0435\u043d-\u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u043f\u0430\u0440\u0441\u0438\u0442\u0441\u044f. \u0418 \u0434\u0430\u043b\u044c\u0448\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430 \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0435\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u041c\u0435\u0442\u043e\u0434 validate() \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true or false. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 NotAuthorizedException. \u0415\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0439, \u0442\u043e \u043c\u044b \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0438\u0437 \u043d\u0435\u0433\u043e id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f $token->claims()->get(&#8216;uid&#8217;) \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 $request, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435. NotAuthorizedException \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\exceptions;  class NotAuthorizedHttpException extends \\Exception {  }<\/code><\/pre>\n<p>\u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0451 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a. \u0412 \u0444\u0430\u0439\u043b\u0435 routes.php \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438:<\/p>\n<pre><code class=\"php\">&lt;?php \/\/routes.php Router::error(function(Request $request, Exception $exception) {     $response = Router::response();     switch (get_class($exception)) {         case NotAuthorizedHttpException::class: {             $response->httpCode(401);             break;         }         case Exception::class: {             $response->httpCode(500);             break;         }     }     if (PROD) {         return $response->json([]);     } else {         return $response->json([             'status' => 'error',             'message' => $exception->getMessage()         ]);     } });<\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0444\u0430\u0439\u043b routes.php \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<figure class=\"bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ba1\/d91\/3b5\/ba1d913b56946af06e5176249cb439f7.png\" alt=\"\u0420\u0438\u0441. 2. \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\" title=\"\u0420\u0438\u0441. 2. \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\" width=\"354\" height=\"760\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ba1\/d91\/3b5\/ba1d913b56946af06e5176249cb439f7.png\"\/><figcaption>\u0420\u0438\u0441. 2. \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/figcaption><\/figure>\n<pre><code class=\"php\">&lt;?php \/\/routes.php use app\\exceptions\\{     NotAuthorizedHttpException }; use app\\middlewares\\{     Authenticate,     ProccessRawBody }; use Pecee\\{     Http\\Request,     SimpleRouter\\SimpleRouter as Router };  const PROD = false;  Router::setDefaultNamespace('app\\controllers');  Router::get('\/', 'VueController@run');  Router::group([     'prefix' => 'api\/v1',     'middleware' => [         ProccessRawBody::class     ] ], function () {     Router::post('\/auth\/sign-in', 'AuthController@signin');     Router::get('\/project', 'ProjectController@index');     Router::group([         'middleware' => [             Authenticate::class         ]     ], function () {         \/\/ authenticated routes         Router::post('\/project\/create', 'ProjectController@create');         Router::post('\/project\/update\/{id}', 'ProjectController@update')             ->where(['id' => '[\\d]+']);     }); });  Router::get('\/controller', 'VueController@run')     ->setMatch('\/\\\/([\\w]+)\/');  Router::error(function(Request $request, Exception $exception) {     $response = Router::response();     switch (get_class($exception)) {         case NotAuthorizedHttpException::class: {             $response->httpCode(401);             break;         }         case Exception::class: {             $response->httpCode(500);             break;         }     }     if (PROD) {         return $response->json([]);     } else {         return $response->json([             'status' => 'error',             'message' => $exception->getMessage()         ]);     } }); <\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435, \u043f\u0440\u043e\u0441\u0442\u043e\u0435 REST api \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u043e\u043c php \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0442\u0440\u0443\u0434\u043e\u0437\u0430\u0442\u0440\u0430\u0442\u0430\u043c\u0438 \u043d\u0430 \u0435\u0433\u043e (\u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0430) \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443. \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/i-luka\/api-php\/tree\/revision1\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0440\u043e\u0443\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/packagist.org\/packages\/pecee\/simple-router#user-content-routes\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.  \u0412\u043c\u0435\u0441\u0442\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 &#171;pecee\/simple-router&#187; \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u0434\u0440\u0443\u0433\u0443\u044e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043c\u0438\u043a\u0440\u043e\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Slim.<\/p>\n<p>\u041f\u0441. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0438\u043b\u0438 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0435\u0441\u044c \u0431\u0435\u0441\u0442\u043f\u0440\u0430\u043a\u0442\u0438\u0441, \u0442\u043e \u043d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0432 \u043a\u043e\u0434\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u044b \u0438\u043b\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u041a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 jwt \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 \u043f\u0430\u043f\u043a\u0435 services.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/681784\/\"> https:\/\/habr.com\/ru\/post\/681784\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0440\u0435\u0441\u0442 \u0430\u043f\u0438 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0421\u041f\u0410 (Vue, React \u0438\u043b\u0438 \u0434\u0440.) \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, CMS \u0438\u043b\u0438 \u0447\u0435\u0433\u043e-\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c php \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u043e\u043c \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0443\u0441\u0438\u043b\u0438\u044f\u043c\u0438 \u043d\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443. \u00a0\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0430\u043c \u0436\u0435 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0438 \u0441\u0430\u043c \u0441\u0430\u0439\u0442 \u0421\u041f\u0410 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430 vue).<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 php \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u0430\u043f\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 php \u0444\u0430\u0439\u043b\u044b, \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u043f\u0430\u043f\u043a\u0430\u0445 \u043d\u0430 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u043d\u0438\u043c. \u0418 \u0445\u043e\u0442\u044f, \u0432\u0438\u0434\u0438\u043c\u043e \u0432 \u0441\u0432\u043e\u0451 \u0432\u0440\u0435\u043c\u044f, \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b \u0448\u0438\u0440\u043e\u043a\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044e php \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043b\u0435\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0441\u043a\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0430\u043f\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Node.js Express \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u0435\u043d, \u0438 \u043f\u0440\u043e\u0441\u0442 \u0434\u043b\u044f \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 &#171;pecee\/simple-router&#187;.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u0434\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e (LAMP, XAMP, docker) \u0438\u043b\u0438 \u043a\u0430\u043a-\u0442\u043e \u0438\u043d\u0430\u0447\u0435 \u0438 \u0443 \u0432\u0430\u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u044b\u0439 \u0444\u0430\u0439\u043b (index.php). \u041a\u0440\u043e\u043c\u0435, \u0442\u043e\u0433\u043e \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 composer.<\/p>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<figure class=\"float bordered\"><figcaption>\u041d\u0430 \u0420\u0438\u0441.1. \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043e\u0431\u0449\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0422\u043e\u0447\u043a\u043e\u0439 \u0432\u0445\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b <\/figcaption><\/figure>\n<p>      index.php\u0432 \u043f\u0430\u043f\u043a\u0435 web. \u0421\u0430\u043c\u0430 \u043f\u0430\u043f\u043a\u0430 web\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0439 \u043f\u0430\u043f\u043a\u043e\u0439, \u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043a\u0430\u043a \u043a\u043e\u0440\u043d\u0435\u0432\u0430\u044f. \u0412 \u043f\u0430\u043f\u043a\u0435 config\u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0440\u043e\u0443\u0442\u043e\u0432 \u043d\u0430\u0448\u0438\u0445 \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432. \u0412 \u043f\u0430\u043f\u043a\u0435 controller\u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432. \u0412 \u043f\u0430\u043f\u043a\u0435 middlewares\u043c\u044b \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0440\u043e\u0443\u0442\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430. \u0412 \u043f\u0430\u043f\u043a\u0430\u0445 exceptions, views \u0438 models \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, html \u0448\u0430\u0431\u043b\u043e\u043d \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438.  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/i-luka\/api-php\/tree\/revision1\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<h3>\u0418\u043d\u0441\u0442\u0430\u043b\u043b\u044f\u0446\u0438\u044f \u0438 \u0437\u0430\u043f\u0443\u0441\u043a<\/h3>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 composer.json (composer install \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430).<\/p>\n<pre><code class=\"json\">\/\/ composer.json {     \"require\": {         \"pecee\/simple-router\": \"*\",         \"lcobucci\/jwt\": \"^3.4\",         \"ext-json\": \"*\"     },     \"autoload\": {         \"psr-4\": {             \"app\\\\\": \"\"         }     } } <\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u2018app\\\u2019 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e \u043a\u0430\u043a \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f namespace. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u0435\u0439\u043c\u0441\u043f\u0435\u0439\u0441\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a \u0432\u0441\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 Router::route() \u0432 \u0444\u0430\u0439\u043b\u0435 index.php<\/p>\n<pre><code class=\"php\">&lt;?php \/\/index.php  use Pecee\\SimpleRouter\\SimpleRouter as Router;  require_once __DIR__ . '\/..\/vendor\/autoload.php'; require_once (__DIR__ . '\/..\/config\/routes.php');      Router::start();<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0442\u0443\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u0440\u043e\u0443\u0442\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0439\u043b\u0435 config\/routes.php.<\/p>\n<h3>\u00a0\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 SPA \u043d\u0430 Vue.js 2 \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443 \u043d\u0430 php<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0437\u0432\u0451\u0440\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u0441\u0431\u043e\u0440\u043a\u0443 vue \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u0430\u043f\u0438, \u0442\u043e \u044d\u0442\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u043e, \u043a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 vue \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043f\u0430\u043f\u043a\u0443 web. \u00a0\u0412 \u0444\u0430\u0439\u043b\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 (\u2018\/config\/routes.php\u2019) \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0434\u0432\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php  use Pecee\\{     SimpleRouter\\SimpleRouter as Router };  Router::setDefaultNamespace('app\\controllers'); Router::get('\/', 'VueController@run'); \/\/ \u043f\u0440\u0430\u0432\u0438\u043b\u043e 1 Router::get('\/controller', 'VueController@run')     ->setMatch('\/\\\/([\\w]+)\/'); \/\/ \u043f\u0440\u0430\u0432\u0438\u043b\u043e 2 <\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0443\u0441\u0442\u043e\u0433\u043e (\u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e) \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 &#8216;\/&#8217; \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 run \u043a\u043b\u0430\u0441\u0441\u0430 VueController. \u0412\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0447\u0442\u043e \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u044f\u0432\u043d\u043e \u043d\u0435\u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f VueController, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u0430 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 vue. \u042d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u043e \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0443\u0436\u0435 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438. \u041c\u0435\u0442\u043e\u0434 run \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u0444\u0430\u0439\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 renderTemplate(), \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.\u00a0\u00a0 \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0440\u043e\u0443\u0442\u0430\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e setDefaultNamespace.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\controllers;  class VueController extends AbstractController {     public function run()     {         return $this->renderTemplate('..\/views\/vue\/vue_page.php');     } } <\/code><\/pre>\n<p>\u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 vue_page.php \u0442\u043e\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0441\u0431\u043e\u0440\u043a\u0438 vue.<\/p>\n<pre><code class=\"php\">&lt;?php \/\/ vue_page.php include (__DIR__ . '\/..\/..\/web\/index.html'); <\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 vue \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443 \u043d\u0430 php, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432 \u043a \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044e \u043d\u0430 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 php. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0447\u0442\u043e \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 AbstractController.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\controllers;  use Pecee\\Http\\Request; use Pecee\\Http\\Response; use Pecee\\SimpleRouter\\SimpleRouter as Router;  abstract class AbstractController {     \/**      * @var Response      *\/     protected $response;     \/**      * @var Request      *\/     protected $request;      public function __construct()     {         $this->request = Router::router()->getRequest();         $this->response =  new Response($this->request);     }      public function renderTemplate($template) {         ob_start();         include $template;         return ob_get_clean();     }      public function setCors()     {         $this->response->header('Access-Control-Allow-Origin: *');         $this->response->header('Access-Control-Request-Method: OPTIONS');         $this->response->header('Access-Control-Allow-Credentials: true');         $this->response->header('Access-Control-Max-Age: 3600');     } } <\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 AbstractController \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u044f $request \u0438 $response. \u0412 $request \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u043e\u043c Pecee\\Http\\Router \u0437\u0430\u043f\u0440\u043e\u0441. \u0410 $response \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0430\u043f\u0438. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u0437\u0434\u0435\u0441\u044c \u043c\u0435\u0442\u043e\u0434 renderTemplate \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 (html \u0441\u0442\u0440\u0430\u043d\u0438\u0446). \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043c\u0435\u0442\u043e\u0434 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439 CORS. \u0415\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0430\u043f\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043d\u0435 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u0430\u0434\u0440\u0435\u0441\u0430, \u0442.\u0435. \u0435\u0441\u043b\u0438 \u0441\u0431\u043e\u0440\u043a\u0430 vue \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0430\u043f\u0438.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 REST API \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432<\/h3>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0430\u043f\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0441\u044b\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0441\u043b\u043e\u0439 ProccessRawBody \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u043a\u0430\u043a middleware \u0432 \u0440\u043e\u0443\u0442\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0430\u043f\u0438.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\middlewares;  use Pecee\\Http\\Middleware\\IMiddleware; use Pecee\\Http\\Request;  class ProccessRawBody implements IMiddleware {      \/**      * @inheritDoc      *\/     public function handle(Request $request): void     {         $rawBody = file_get_contents('php:\/\/input');          if ($rawBody) {             try {              $body = json_decode($rawBody, true);              foreach ($body as $key => $value) {                  $request->$key = $value;              }             } catch (\\Throwable $e) {              }         }     } } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0438\u0437 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 $request \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438\u0437 \u043a\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445. ProccessRawBody \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IMIddleware \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 middleware.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u0440\u043e\u0443\u0442\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0430\u043f\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0441\u043b\u043e\u0439.<\/p>\n<pre><code class=\"php\">&lt;?php \/\/ routes.php Router::group([     'prefix' => 'api\/v1',     'middleware' => [         ProccessRawBody::class     ] ], function () {     Router::post('\/auth\/sign-in', 'AuthController@signin');     Router::get('\/project', 'ProjectController@index'); });<\/code><\/pre>\n<p>\u0423 \u044d\u0442\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u00abapi\/v1\u00bb (\u0442.\u0435. \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &#8216;\/api\/v1\/auth\/sign-in&#8217;), \u0438 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043d\u0430\u043c\u0438 middleware ProccessRawBody::<strong>class<\/strong>, \u0442\u0430\u043a \u0447\u0442\u043e \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 AbstractController \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 $request. AuthController \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u0436\u0435 \u043c\u044b \u0443\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u043c\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 ProjectController::index.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\controllers;  class ProjectController extends AbstractController {     public function index():string     { \/\/ \u041a\u0430\u043a\u0430\u044f-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0443\u0442          return $this->response->json([             [                 'name' => 'project 1'             ],             [                 'name' => 'project 2'             ]         ]);     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043d\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u043e\u0443\u0442\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<h3>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e JWT \u0442\u043e\u043a\u0435\u043d\u0443<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0440\u043e\u0443\u0442\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u041d\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u0445\u043e\u0434 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 jwt-\u0442\u043e\u043a\u0435\u043d\u0430. \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430 \u0438 \u0435\u0433\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u201c lcobucci\/jwt\u201d \u0412\u0441\u0451 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443 \u043d\u0430\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u043f\u043e \u0440\u043e\u0443\u0442\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u0440\u0430\u043d\u0435\u0435 &#8216;\/auth\/sign-in&#8217;. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 AuthController::singin \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u044b\u0434\u0430\u0447\u0438 jwt-\u0442\u043e\u043a\u0435\u043d\u0430 \u043f\u043e\u0441\u043b\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<pre><code class=\"php\">&lt;?php  namespace app\\controllers;  use app\\models\\Request; use ArgumentCountError; use DateTimeImmutable; use Lcobucci\\JWT\\Configuration; use Lcobucci\\JWT\\Signer\\Hmac\\Sha256; use Lcobucci\\JWT\\Signer\\Key\\InMemory;  class AuthController extends AbstractController {     public function signin()     {       \/\/ \u0422\u0443\u0442 \u043a\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f          $config = Configuration::forSymmetricSigner(             new Sha256(),             InMemory::plainText('\u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439_\u043a\u043b\u044e\u0447')         );         $now   = new DateTimeImmutable();         $token = $config->builder()             \/\/ Configures the issuer (iss claim)             ->issuedBy('http:\/\/example.com')             \/\/ Configures the audience (aud claim)             ->permittedFor('http:\/\/example.org')             \/\/ Configures the id (jti claim)             ->identifiedBy('4f1g23a12aa')             \/\/ Configures the time that the token was issue (iat claim)             ->issuedAt($now)             \/\/ Configures the expiration time of the token (exp claim)             ->expiresAt($now->modify('+2 minutes'))             \/\/ Configures a new claim, called \"uid\"             ->withClaim('uid', $user->id)             \/\/ Configures a new header, called \"foo\"             ->withHeader('foo', 'bar')             \/\/ Builds a new<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-336865","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336865"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336865\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}