{"id":346328,"date":"2023-03-06T09:04:02","date_gmt":"2023-03-06T09:04:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=346328"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=346328","title":{"rendered":"<span>Samoyed CMG \u2014 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/720036\/\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u0431\u044b\u043b \u043e\u043f\u0438\u0441\u0430\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Samoyed CMG (<strong>C<\/strong>ontent <strong>M<\/strong>anagement <strong>G<\/strong>enerator). \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u0434\u0430 \u0441\u0430\u0439\u0442\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u043c. \u0422.\u0435. \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438, \u0430 \u043d\u0435 \u043f\u0440\u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0438 \u043d\u0430 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435. <\/p>\n<p>  <\/p>\n<p>\u0412 \u043d\u0435\u0439 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0438\u0441\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u0443\u0436\u0430\u0442 \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0441\u0430\u0439\u0442\u0430. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u0432\u0430 \u0438\u0437 \u043d\u0438\u0445:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/samoyed-cmg-demo.shasoft.com\/debug\/scripts\/34.html\" rel=\"nofollow noopener noreferrer\">Shasoft\\SamoyedCMG\\Generator\\Service\\ServiceGeneratorPath<\/a> \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0443\u0442\u044f\u043c\u0438 \u0441\u0430\u0439\u0442\u0430.<\/li>\n<li><a href=\"https:\/\/samoyed-cmg-demo.shasoft.com\/debug\/scripts\/35.html\" rel=\"nofollow noopener noreferrer\">Shasoft\\STwig\\Twig<\/a> \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c <a href=\"https:\/\/twig.symfony.com\/\" rel=\"nofollow noopener noreferrer\">Twig<\/a>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"vvedenie\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441 \u0432 \u043f\u043e\u043d\u044f\u0442\u0438\u0438 Samoyed CMG \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432:<\/p>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/www.php.net\/manual\/ru\/language.oop5.interfaces.php\" rel=\"nofollow noopener noreferrer\">\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441<\/a> \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441\u0430.<\/li>\n<li>\u041a\u043b\u0430\u0441\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u0435\u0440\u0432\u0438\u0441.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0412 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0430\u0439\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">\/\/ \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 public function setService(string $name, string $classname): bool<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><strong>$name<\/strong> \u2014 \u0438\u043c\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u0438\u043c\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430);<\/li>\n<li><strong>$classname<\/strong> \u2014 \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0435 \u043c\u0435\u043d\u044f\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043b\u0430\u0441\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e <del>\u044f \u043d\u0435 \u0438\u0449\u0443 \u043b\u0435\u0433\u043a\u0438\u0439 \u043f\u0443\u0442\u0435\u0439<\/del> \u0435\u0441\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443, \u0442\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440.<\/p>\n<p>  <\/p>\n<h2 id=\"generator\">\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440<\/h2>\n<p>  <\/p>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>CodeGenerator<\/code><\/p>\n<p>  <\/p>\n<pre><code class=\"php\">\/\/ \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043a\u043e\u0434\u0430 abstract class CodeGenerator extends ObjectGenerator {     \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c HTML \u043a\u043e\u0434 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0435     abstract protected function getHtml(ApiHtml $api): string;     \/\/ \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f     abstract protected function onGenerate(ApiGenerate $api): void; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>getHtml<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 html \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441 <a href=\"https:\/\/samoyed-cmg-demo.shasoft.com\/debug\/index.html\" rel=\"nofollow noopener noreferrer\">\u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0430\u0439\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0445\u043e\u0434 \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u0443\u0437\u043b\u0430\u043c \u0434\u0435\u0440\u0435\u0432\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>onGenerate<\/code>. \u041e\u0431\u044a\u0435\u043a\u0442 $api \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">\/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 public function addScript(string $filepathTemplate, array $args = [], ?\\Closure $cbTwigConfig = null): static;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0438 \u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438 \u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0443\u0437\u0435\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <a href=\"https:\/\/twig.symfony.com\/doc\/3.x\/api.html\" rel=\"nofollow noopener noreferrer\">Twig\\Environment<\/a> \u0438 \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0438 <a href=\"https:\/\/twig.symfony.com\/doc\/3.x\/advanced.html\" rel=\"nofollow noopener noreferrer\">\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u044b<\/a> \u043a \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0443 Twig. <strong>\u0412\u0410\u0416\u041d\u041e(!)<\/strong>: \u0432\u0441\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"generator-servisa-raboty-s-putyami\">\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0443\u0442\u044f\u043c\u0438<\/h2>\n<p>  <\/p>\n<p>\u0418\u0434\u0435\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">\/\/ \u041f\u0443\u0442\u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 interface IPath extends IService {     \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0441\u0430\u0439\u0442\u0430     public function site(?string $pathX = null): string;     \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u043e\u0432     public function vendor(?string $pathX = null): string;     \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430     public function package(string $packageName, ?string $pathX = null): string;     \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f www \u0441\u0435\u0440\u0432\u0435\u0440\u0430     public function wwwServer(?string $pathX = null): string;     \/\/ \u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f     public function temp(?string $pathX = null): string;     \/\/ \u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435     public function storage(?string $pathX = null): string; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 <code>site<\/code>, <code>vendor<\/code> \u0438 <code>package<\/code> \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0449\u0438\u043c\u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 (\u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u043e\u0434\u043e\u0432\u0430\u044f \u0431\u0430\u0437\u0430 \u043e\u0434\u043d\u0430 \u043d\u0430 \u0432\u0441\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b). \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>wwwServer<\/code> \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0434\u043e\u043c\u0435\u043d\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430. \u0424\u0443\u043d\u043a\u0446\u0438\u0438 <code>temp<\/code> \u0438 <code>storage<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430. \u042d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u0430\u0445 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0434\u043d\u0438\u043c \u0438 \u0442\u0435\u043c \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u043c. \u041c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a \u0434\u043e\u043c\u0435\u043d\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438 \u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0443\u0436\u0435 \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043f\u0430\u043f\u043a\u0435. <\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041a\u043e\u0434 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">\/\/ \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0443\u0442\u044f\u043c\u0438  class ServiceGeneratorPath extends CodeGenerator {     \/\/ \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440     public function __construct(protected string $dataKey)     {         parent::__construct();     }     \/\/ \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f     protected function onGenerate(ApiGenerate $api): void     {         \/\/ \u0418\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u043c\u0435\u043d\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u043c\u0435\u043d\u044b         $classname = str_replace('IPath', 'Path', IPath::class);         \/\/ \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432         if ($api->setService(IPath::class, $classname)) {             \/\/ \u0422\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443             $api->addScript(__DIR__ . '\/..\/..\/..\/twig\/Service\/Path.php.twig', [                 'classname' => $classname,                 'dataKey' => $this->dataKey             ]);         }     }     \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c HTML \u043a\u043e\u0434 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0435     protected function getHtml(ApiHtml $api): string     {         return \"&lt;strong>dataKey&lt;\/strong>: \" . $this->dataKey;     } }<\/code><\/pre>\n<\/div><\/div>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0428\u0430\u0431\u043b\u043e\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">&lt;?php  {{ classname | namespace }}  use Shasoft\\Support\\File; use Shasoft\\SamoyedCMG\\Service\\IPath; use Shasoft\\SamoyedCMG\\Service\\IRoute;  \/\/ \u041f\u0443\u0442\u0438 class {{ classname | class }} implements IPath {     \/\/ \u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f     protected string $basepath;     \/\/ \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440     public function __construct(protected IRoute $route)     {         \/\/ \u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0441\u0430\u0439\u0442\u0430         $this->basepath = File::normalize(__DIR__ . \"\/..\", true);     }     \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0441\u0430\u0439\u0442\u0430     public function site(?string $pathX = null): string     {         $ret = $this->basepath;         if (!is_null($pathX)) {             $ret .= '\/' . $pathX;         }         return $ret;     }     \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u043e\u0432     public function vendor(?string $pathX = null): string     {         $ret = $this->site('vendor');         $ret = '';         if (!is_null($pathX)) {             $ret .= '\/' . $pathX;         }         return $ret;     }     \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430     public function package(string $packageName, ?string $pathX = null): string     {         $ret = $this->vendor($packageName);         if (!is_null($pathX)) {             $ret .= '\/' . $pathX;         }         return $ret;     }     \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f www \u0441\u0435\u0440\u0432\u0435\u0440\u0430     public function wwwServer(?string $pathX = null): string     {         $ret = $this->site('www-server\/@\/'.$this->route->host());         if (!is_null($pathX)) {             $ret .= '\/' . $pathX;         }         return $ret;     }     \/\/ \u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f     public function temp(?string $pathX = null): string     {         $ret = $this->site('~.temp\/{{ dataKey }}');         if (!is_null($pathX)) {             $ret .= '\/' . $pathX;         }         return $ret;     }     \/\/ \u0424\u0430\u0439\u043b\u043e\u0432\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435     public function storage(?string $pathX = null): string     {         $ret = $this->site('storage\/{{ dataKey }}');         if (!is_null($pathX)) {             $ret .= '\/' . $pathX;         }         return $ret;     } }<\/code><\/pre>\n<\/div><\/div>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f getHtml \u043d\u0430 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/samoyed-cmg-demo.shasoft.com\/debug\/index.html\" rel=\"nofollow noopener noreferrer\">\u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443<\/a><br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/_q\/5w\/sh\/_q5wsh8fcqpfkdxpsgxbuomibgu.png\" data-src=\"https:\/\/habrastorage.org\/webt\/_q\/5w\/sh\/_q5wsh8fcqpfkdxpsgxbuomibgu.png\"\/><\/p>\n<\/div><\/div>\n<p>  <\/p>\n<p><a href=\"https:\/\/samoyed-cmg-demo.shasoft.com\/debug\/scripts\/34.html\" rel=\"nofollow noopener noreferrer\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430<\/a> \u043d\u0430 \u0441\u0442\u0430\u043d\u0438\u0446\u0435 \u0441 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439. \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 <a href=\"https:\/\/samoyed-cmg-demo.shasoft.com\/debug\/scripts\/6a72e9ed997b5e6386dde32098aa214d.html\" rel=\"nofollow noopener noreferrer\">IRoute<\/a> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0443. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430.<\/p>\n<p>  <\/p>\n<p><strong>\u0412\u0410\u0416\u041d\u041e(!)<\/strong>: \u0432 $api \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>setService<\/code> \u0434\u043b\u044f \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 TRUE \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438. \u0422.\u0435. \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e \u0438\u043b\u0438 \u0431\u044b\u043b\u0430 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443. \u0418 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430. \u0421\u0432\u044f\u0437\u0430\u043d\u043e \u044d\u0442\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a, \u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u0432\u0441\u0435\u0445 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e, \u0437\u043d\u0430\u0447\u0438\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u0443\u0436\u0435 \u0431\u044b\u043b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0440\u0430\u043d\u0435\u0435 \u0438 \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0435\u0433\u043e \u0435\u0449\u0451 \u0440\u0430\u0437 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c.<\/p>\n<p>  <\/p>\n<h2 id=\"generator-servisa-raboty-s-shablonizatorom\">\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c<\/h2>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043e\u0431\u0449\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">\/\/ \u0428\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440 interface ITemplate extends IService {     \/\/ \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c     public function render(string $templateName, array $args = []): string; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Twig \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0432 \u043e\u0431\u0449\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">\/\/ \u0428\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440 Twig interface ITwig extends ITemplate {}<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u044b \u0447\u0442\u043e\u0431\u044b \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u0435\u0440\u0432\u0438\u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u043b\u044f Twig \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u043b\u043e\u043c\u0430\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0431\u0449\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041a\u043e\u0434 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">\/\/ \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c Twig https:\/\/twig.symfony.com\/ class ServiceGeneratorTwig extends CodeGenerator {     \/\/ \u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0430\u0432\u0430 \u0438\u043c\u0451\u043d     protected array $namespaces = [];     \/\/ \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440     public function __construct()     {         parent::__construct();     }     \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c HTML \u043a\u043e\u0434 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0435     protected function getHtml(ApiHtml $api): string     {         $ret = '';         if (!empty($this->namespaces)) {             $ret .= '&lt;ul>';             foreach ($this->namespaces as $namespace => $filepath) {                 $ret .= '&lt;li>&lt;strong>' . $namespace . '&lt;\/strong>: ' . $api->relSite($filepath) . '&lt;\/li>';             }             $ret .= '&lt;\/ul>';         }         return $ret;     }     \/\/ \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f     protected function onGenerate(ApiGenerate $api): void     {         \/\/ \u0418\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430         $classname = str_replace('ITwig', 'Twig', ITwig::class);         \/\/ \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430         if ($api->setService(ITwig::class, $classname)) {             \/\/ \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443             $api->addScript(__DIR__ . '\/..\/twig\/Twig.php.twig', [                 'classname' => $classname,                 'namespaces' => $this->namespaces,                 'dev' => $api->isDev()             ]);         }     }     \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0451\u043d     public function addNamespace(string $name, string $path): static     {         \/\/ \u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0443\u0442\u044c         $path = File::normalize($path, true);         \/\/ \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0451\u043d \u043d\u0435\u0442 \u0418\u041b\u0418 \u043f\u0443\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f         if (!array_key_exists($name, $this->namespaces) || $this->namespaces[$name] != $path) {             \/\/ \u0412\u043d\u0435\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435             $this->namespaces[$name] = $path;             \/\/ \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0444\u043b\u0430\u0433 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f             $this->setModify();         }         \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0435\u0431\u044f         return $this;     }     \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0451\u043d     public function addNamespaces(array $namespaces): static     {         foreach ($namespaces as $name => $path) {             $this->addNamespace($name, $path);         }         \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0435\u0431\u044f         return $this;     } }<\/code><\/pre>\n<\/div><\/div>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0428\u0430\u0431\u043b\u043e\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">&lt;?php  {{ classname | namespace }}  use Shasoft\\SamoyedCMG\\Service\\IPath; use Shasoft\\STwig\\ITwig; use Twig\\Environment; use Twig\\Loader\\FilesystemLoader;  \/\/ \u0428\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440 Twig class {{ classname | class }} implements ITwig {     \/\/ \u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438 Twig     protected ?Environment $_twig = null;     \/\/ \u041f\u0430\u043f\u043a\u0430 \u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438     protected string $path;     \/\/ \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440     public function __construct(IPath $path)     {         \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432         $this->path = $path->temp('twig');     }     \/\/ \u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435     public function render(string $templateName, array $args = []): string     {         \/\/ \u0415\u0441\u043b\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043d         if( is_null($this->_twig) ) {             \/\/ \u0417\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432             $loader = new FilesystemLoader(); {% if namespaces %}             \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0443\u0442\u0438 {% for name, path in namespaces %}             $loader->addPath( __DIR__ . '\/{{ path | relScript }}', '{{ name }}'); {% endfor %} {% endif %}             \/\/ \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430             $this->_twig = new Environment($loader, [                 \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432                 'cache' => $this->path,                 \/\/ \u0420\u0435\u0436\u0438\u043c \u043e\u0442\u043b\u0430\u0434\u043a\u0438                 'debug' => {{ dev | var_export }},             ]);         }         return $this->_twig->render($templateName, $args);     } }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0443 \u043f\u0443\u0442\u0435\u0439, \u043d\u043e \u0435\u0441\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u0438\u0435. \u041e\u043d\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">    \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0451\u043d     public function addNamespace(string $name, string $path): static;     \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0451\u043d     public function addNamespaces(array $namespaces): static;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u0435\u0440\u0435\u0432\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a <code>tune<\/code>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">\/\/-- \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u044b $node->tune(function (ServiceGeneratorTwig $twig) {     \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0451\u043d main \u0418 \u043f\u0430\u043f\u043a\u0443 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438     $twig->addNamespace('main', __DIR__ . '\/..\/@twig'); });<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0412\u0410\u0416\u041d\u041e(!)<\/strong>: \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>setModify<\/code> \u0434\u043b\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445. \u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435: \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0439\u0442\u0435, \u0430 \u0431\u044b\u043b\u043e \u043b\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0438\u043b\u0438 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u0442\u0435\u043c\u0438 \u0436\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/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\/720528\/\"> https:\/\/habr.com\/ru\/post\/720528\/<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/720036\/\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u0431\u044b\u043b \u043e\u043f\u0438\u0441\u0430\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Samoyed CMG (<strong>C<\/strong>ontent <strong>M<\/strong>anagement <strong>G<\/strong>enerator). \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u0434\u0430 \u0441\u0430\u0439\u0442\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u043c. \u0422.\u0435. \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438, \u0430 \u043d\u0435 \u043f\u0440\u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0438 \u043d\u0430 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435. <\/p>\n<p>  <\/p>\n<p>\u0412 \u043d\u0435\u0439 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0438\u0441\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u0443\u0436\u0430\u0442 \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0441\u0430\u0439\u0442\u0430. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u0432\u0430 \u0438\u0437 \u043d\u0438\u0445:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/samoyed-cmg-demo.shasoft.com\/debug\/scripts\/34.html\" rel=\"nofollow noopener noreferrer\">Shasoft\\SamoyedCMG\\Generator\\Service\\ServiceGeneratorPath<\/a> \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0443\u0442\u044f\u043c\u0438 \u0441\u0430\u0439\u0442\u0430.<\/li>\n<li><a href=\"https:\/\/samoyed-cmg-demo.shasoft.com\/debug\/scripts\/35.html\" rel=\"nofollow noopener noreferrer\">Shasoft\\STwig\\Twig<\/a> \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c <a href=\"https:\/\/twig.symfony.com\/\" rel=\"nofollow noopener noreferrer\">Twig<\/a>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\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-346328","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/346328","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=346328"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/346328\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=346328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=346328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=346328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}