{"id":274516,"date":"2016-02-18T12:21:02","date_gmt":"2016-02-18T09:21:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=274516"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=274516","title":{"rendered":"\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0432 Symfony \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438"},"content":{"rendered":"<p>       \u0414\u0430\u0432\u043d\u044b\u043c \u0434\u0430\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439 \u0432\u0441\u0442\u0430\u043b\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0432 Symfony, \u0442.\u0435. \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u0438\u0445 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u044d\u043a\u0448\u043d\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0448\u043b\u043e \u043d\u0430 \u0443\u043c, \u2014 \u044d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <i>EventListener<\/i> \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f <i>kernel.controller<\/i>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 <i>initialize<\/i>, \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0441\u0442\u044c. \u0414\u0430\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u044f \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u0443\u0436\u0435 \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043b\u0435\u0442.<\/p>\n<p>  \u0411\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0434\u043d\u044f\u0445 \u044f \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f: \u0430 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u043a\u0448\u043d\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u043e\u0434\u0440\u044f\u0434, \u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0434\u0430\u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0438 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438? \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u044f \u0440\u0435\u0448\u0438\u043b \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439. \u0414\u0443\u043c\u0430\u044e, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0442\u0435\u043c, \u043a\u0442\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432.<\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0442\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"php\">&lt;?php namespace MyBundle\\Controller;  interface InitializableControllerInterface { } <\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c EventListener \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f <i>kernel.controller<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"php\">&lt;?php namespace MyBundle\\EventListener;  use MyBundle\\Controller\\InitializableControllerInterface; use Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent;  class KernelControllerListener {     \/\/ \u041c\u0435\u0442\u043e\u0434, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043f\u0440\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0438 kernel.controller     public function onKernelController(FilterControllerEvent $event)     {         $controller = $event-&gt;getController();          \/\/ \u0415\u0441\u043b\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 InitializableControllerInterface         if (is_array($controller) && $controller[0] instanseof InitializableControllerInterface) {             \/\/ \u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430         }     } } <\/code><\/pre>\n<p>  \u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (services.xml):<\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt; &lt;container xmlns=&quot;http:\/\/symfony.com\/schema\/dic\/services&quot;     xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;     xsi:schemaLocation=&quot;http:\/\/symfony.com\/schema\/dic\/services http:\/\/symfony.com\/schema\/dic\/services\/services-1.0.xsd&quot;&gt;     &lt;services&gt;         &lt;service id=&quot;my_bundle.kernel_controller_listener&quot; class=&quot;MyBundle\\EventListener\\KernelControllerListener&quot;&gt;             &lt;tag name=&quot;kernel.event_listener&quot; event=&quot;kernel.controller&quot; method=&quot;onKernelController&quot; \/&gt;         &lt;\/service&gt;     &lt;\/services&gt; &lt;\/container&gt; <\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u044d\u0442\u043e\u0433\u043e \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u043d\u043e \u043c\u044b \u0436\u0435 \u0445\u043e\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c.<\/p>\n<p>  \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0448\u044c \u0440\u0438\u0434\u0435\u0440 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u043e\u0442 Doctrine. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441-\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php namespace MyBundle\\Annotation;  \/**  * @Annotation  * @Target({&quot;METHOD&quot;})  *  * \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e @Annotation \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f,  * \u0430 @Target({&quot;METHOD&quot;}) - \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0443\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0430.  *\/ class Init {     \/\/ \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438:      \/**      * @var array      *      * \u041c\u0430\u0441\u0441\u0438\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432      *\/     public $args = [];      \/**      * @var int      *      * \u041f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 (\u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435, \u0442\u0435\u043c \u0440\u0430\u043d\u044c\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u043e\u0432)      *\/     public $priority = 0; } <\/code><\/pre>\n<p>  \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f Doctrine \u043d\u0430\u0434 \u0442\u0438\u043f\u0430\u043c\u0438 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435:<\/p>\n<pre><code class=\"php\">&lt;?php namespace MyBundle\\Controller;  use MyBundle\\Annotation\\Init; use MyBundle\\Controller\\InitializableControllerInterface; use Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller;  class MyController extends Controller implements InitializableControllerInterface {     \/**      * @Init(args = {&quot;test&quot;}, priority = 200)      *      * \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d (initialize(&quot;test&quot;);) \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u044d\u043a\u0448\u043d\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430      *\/     public function initialize($value)     {         \/\/ ... \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043e\u0434 ...     } } <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0432 \u043d\u0430\u0448 KernelControllerListener:<\/p>\n<pre><code class=\"php\">&lt;?php namespace MyBundle\\EventListener;  use Doctrine\\Common\\Annotations\\Reader; use MyBundle\\Annotation\\Init; use MyBundle\\Controller\\InitializableControllerInterface; use Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent;  class KernelControllerListener {     protected $annotationReader;      \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0440\u0438\u0434\u0435\u0440 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439     public function __construct(Reader $annotationReader)     {         $this-&gt;annotationReader = $annotationReader;     }      public function onKernelController(FilterControllerEvent $event)     {         $controller = $event-&gt;getController();          if (is_array($controller) && $controller[0] instanceof InitializableControllerInterface) {             \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043b\u0430\u0441\u0441\u0435             $reflector = new \\ReflectionClass($controller[0]);             \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430             $methods = $reflector-&gt;getMethods(\\ReflectionMethod::IS_PUBLIC);             $initMethods = [];              \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f @Init             foreach ($methods as $method) {                 \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430                 $annotations = $this-&gt;annotationReader-&gt;getMethodAnnotations($method);                  foreach ($annotations as $annotation) {                     \/\/ \u0415\u0441\u043b\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f - \u043d\u0430\u0448\u0430, \u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432                     if ($annotation instanceof Init) {                         $initMethods[] = [                             'method' =&gt; $method,                             'args' =&gt; $annotation-&gt;args,                             'priority' =&gt; $annotation-&gt;priority                         ];                     }                 }             }              \/\/ \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430             usort($initMethods, function($a, $b) { return $b['priority'] - $a['priority']; });              foreach ($initMethods as $initMethod) {                 $method = $initMethod['method'];                  \/\/ \u041e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u043c \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u043b\u0438 \u043d\u0435\u0442                 if (count($initMethod['args'])) {                     $method-&gt;invokeArgs($controller[0], $initMethod['args']);                 } else {                     $method-&gt;invoke($controller[0]);                 }             }         }     } } <\/code><\/pre>\n<p>  \u0418 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u0435\u0440\u0432\u0438\u0441\u0430:<\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt; &lt;container xmlns=&quot;http:\/\/symfony.com\/schema\/dic\/services&quot;     xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;     xsi:schemaLocation=&quot;http:\/\/symfony.com\/schema\/dic\/services http:\/\/symfony.com\/schema\/dic\/services\/services-1.0.xsd&quot;&gt;     &lt;services&gt;         &lt;service id=&quot;my_bundle.kernel_controller_listener&quot; class=&quot;MyBundle\\EventListener\\KernelControllerListener&quot;&gt;             &lt;argument type=&quot;service&quot; id=&quot;annotation_reader&quot; \/&gt; &lt;!-- \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0440\u0438\u0434\u0435\u0440\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 --&gt;             &lt;tag name=&quot;kernel.event_listener&quot; event=&quot;kernel.controller&quot; method=&quot;onKernelController&quot; \/&gt;         &lt;\/service&gt;     &lt;\/services&gt; &lt;\/container&gt; <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0438 \u0432\u0441\u0435. \u0412\u0435\u0441\u044c \u043c\u043e\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/symple-dev\/init-controller-bundle\">GitHub<\/a>, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043e\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043a\u0440\u0438\u0442\u0438\u043a\u0435.<\/p>\n<p>  <b>\u0421\u043c. \u0442\u0430\u043a\u0436\u0435:<\/b>  <\/p>\n<ul>\n<li><a href=\"http:\/\/php.net\/manual\/ru\/class.reflectionclass.php\">PHP: Reflection Class<\/a><\/li>\n<li><a href=\"http:\/\/doctrine-common.readthedocs.org\/en\/latest\/reference\/annotations.html#annotation-classes\">Doctrine: Annotation Classes<\/a><\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<p> \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:\/\/habrahabr.ru\/post\/277465\/\"> https:\/\/habrahabr.ru\/post\/277465\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0414\u0430\u0432\u043d\u044b\u043c \u0434\u0430\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439 \u0432\u0441\u0442\u0430\u043b\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0432 Symfony, \u0442.\u0435. \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u0438\u0445 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u044d\u043a\u0448\u043d\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0448\u043b\u043e \u043d\u0430 \u0443\u043c, \u2014 \u044d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <i>EventListener<\/i> \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f <i>kernel.controller<\/i>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 <i>initialize<\/i>, \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0441\u0442\u044c. \u0414\u0430\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u044f \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u0443\u0436\u0435 \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043b\u0435\u0442.<\/p>\n<p>  \u0411\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0434\u043d\u044f\u0445 \u044f \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f: \u0430 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u043a\u0448\u043d\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u043e\u0434\u0440\u044f\u0434, \u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0434\u0430\u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0438 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438? \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u044f \u0440\u0435\u0448\u0438\u043b \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439. \u0414\u0443\u043c\u0430\u044e, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0442\u0435\u043c, \u043a\u0442\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438.  <\/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-274516","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/274516","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=274516"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/274516\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=274516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=274516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=274516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}