{"id":165237,"date":"2013-01-09T18:14:03","date_gmt":"2013-01-09T14:14:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=165237"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=165237","title":{"rendered":"<span class=\"post_title\">\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e Dependency Injection \u0432 Symfony2<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430-\u0431\u043b\u043e\u0433\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 <a href=\"http:\/\/ru.wikipedia.org\/wiki\/\u0412\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435_\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438\">Dependency Injection<\/a>. \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432\u043e \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b Symfony: \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, doctrine-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>  \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043c \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0441\u0430\u0439\u0442\u0430 \u0434\u043e \u0434\u0432\u0443\u0445:  <\/p>\n<ul>\n<li>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 (\/add)<\/li>\n<li>\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u043f\u043e\u0441\u0442\u043e\u0432 (\/list)<\/li>\n<\/ul>\n<p>  \u0424\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \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:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/1ad\/0c0\/254\/1ad0c025444925b70b96ff89b623101e.png\"\/><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0428\u0430\u0433 1. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/h2>\n<p>  <abbr title=\"Dependency Injection\">DI<\/abbr> \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c Symfony \u0443\u0436\u0435 <a href=\"http:\/\/habrahabr.ru\/post\/117572\/\">\u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0441\u044f<\/a> \u043d\u0430 \u0445\u0430\u0431\u0440\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d \u0432 <a href=\"http:\/\/symfony.com\/doc\/current\/book\/service_container.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0440\u0435\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438: \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432 \u043a\u043e\u0434\u0435 \u0431\u0430\u043d\u0434\u043b\u0430, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b (YAML, XML, PHP) \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 (\u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0431\u0430\u043d\u0434\u043b\u0430 <a href=\"http:\/\/jmsyst.com\/bundles\/JMSDiExtraBundle\">JMSDiExtraBundle<\/a>, \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0442\u0430\u0446\u0438\u044e Symfony). \u041a\u0430\u0436\u0434\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0438 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043c\u0430 \u043a\u043e\u0434\u0430. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043a\u043b\u0430\u0441\u0441\u0430, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441\u0441-\u043b\u043e\u0433\u0438\u043a\u0443. \u041f\u0443\u0441\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 PostManager, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Manager\/PostManager.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php namespace AppBundle\\Manager;  use JMS\\DiExtraBundle\\Annotation as DI; use AppBundle\\Entity\\Post; use AppBundle\\Entity\\User;  \/**  * @DI\\Service(&quot;app.manager.post&quot;, public=false)  *\/ class PostManager {     \/**      * @DI\\Inject(&quot;doctrine.orm.entity_manager&quot;)      * @var \\Doctrine\\ORM\\EntityManager      *\/     public $em;      public function addPost(Post $post, User $user)     {         $post-&gt;setAuthor($user);         $this-&gt;em-&gt;persist($post);          $user-&gt;setLastPost($post);         $user-&gt;increasePostsCount();          $this-&gt;em-&gt;flush();     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <b>@DI\\Service<\/b> \u2014 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441. \u0412 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (app.manager.post) \u0438 \u0435\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b.<br \/>  <b>public=false<\/b> \u2014 \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <a href=\"http:\/\/symfony.com\/doc\/current\/components\/dependency_injection\/advanced.html\">\u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442<\/a> \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0437 <abbr title=\"Dependency Injection Container\">DIC<\/abbr> ($container-&gt;get(&#8216;app.manager.post&#8217;) \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435). \u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0441\u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0435 \u043e\u0442 \u043d\u0435\u0433\u043e \u044f\u0432\u043d\u043e (\u0434\u0430\u043b\u0435\u0435, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c, \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435).<br \/>  <b>@DI\\Inject<\/b> \u2014 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430 public. \u0414\u043b\u044f private\/protected \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"http:\/\/jmsyst.com\/bundles\/JMSDiExtraBundle\/master\/usage\">@DI\\InjectParams<\/a> \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0435\u0440\u0432\u0438\u0441 <b>app.manager.post<\/b>, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0439 \u043e\u0442 <b>doctrine.orm.entity_manager<\/b>:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/070\/429\/6ac\/0704296accfa59cb8ae651845dec86d9.png\"\/><br \/>  \u0413\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438 \u0441\u0432\u044f\u0437\u0435\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0432 \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0432\u0435\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 <a href=\"http:\/\/jmsyst.com\/bundles\/JMSDebuggingBundle\">JMSDebuggingBundle<\/a>.<\/p>\n<h2>\u0428\u0430\u0433 2. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/h2>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432 Symfony \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438, \u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0435\u0441\u0442\u044c <a href=\"http:\/\/symfony.com\/doc\/2.0\/cookbook\/controller\/service.html\">\u0437\u0430\u043c\u0435\u0442\u043a\u0430<\/a>, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0438\u0445 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0432\u044b\u043c\u0438. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c PostController, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 PostManager:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Controller\/PostController.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php namespace AppBundle\\Controller;  use JMS\\DiExtraBundle\\Annotation as DI; use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route; use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template; use JMS\\SecurityExtraBundle\\Annotation\\Secure; use Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller; use AppBundle\\Entity\\Post; use AppBundle\\Form\\PostType;  \/**  * @DI\\Service(&quot;app.controller.post&quot;, scope=&quot;request&quot;)  * @Route(service=&quot;app.controller.post&quot;)  *\/ class PostController extends Controller {     \/**      * @DI\\Inject(&quot;service_container&quot;)      *\/     public $container;      \/**      * @DI\\Inject(&quot;app.manager.post&quot;)      * @var \\AppBundle\\Manager\\PostManager      *\/     public $postManager;      \/**      * @Route(&quot;\/add&quot;, name=&quot;post_add&quot;)      * @Template      * @Secure(roles=&quot;ROLE_USER&quot;)      *\/     public function addAction()     {         $post = new Post();         $form = $this-&gt;createForm(new PostType(), $post);          if ($this-&gt;getRequest()-&gt;getMethod() == 'POST') {             $form-&gt;bind($this-&gt;getRequest());              if ($form-&gt;isValid()) {                 $this-&gt;postManager-&gt;addPost($post, $this-&gt;getUser());                 return $this-&gt;redirect($this-&gt;generateUrl('post_list'));             }         }         return array(             'form' =&gt; $form-&gt;createView()         );     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <b>scope=\u00abrequest\u00bb<\/b> \u2014 \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e <a href=\"http:\/\/symfony.com\/doc\/current\/cookbook\/service_container\/scopes.html\">\u043e\u043f\u0438\u0441\u0430\u043d<\/a> \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<br \/>  <b>@R\u043eute(service=\u00abapp.controller.post\u00bb)<\/b> \u2014 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0435\u0440\u0432\u0438\u0441. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b \u043f\u0435\u0440\u0435\u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u0441\u044f \u0441 &#8216;AppBundle:Post:add&#8217; \u043d\u0430 &#8216;app.controller.post:addAction&#8217;.<br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 <b>@DI\\Inject(\u00abservice_container\u00bb)<\/b> \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u043b\u044e\u0431\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435 \u043e\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u2014 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 <abbr title=\"Dependency Injection Container\">DIC<\/abbr> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c.<\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0435\u0440\u0432\u0438\u0441 <b>app.controller.post<\/b>, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0439 \u043e\u0442 <b>service_container<\/b> \u0438 <b>app.manager.post<\/b>:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/68b\/f25\/63e\/68bf2563e1109832b04ebabb328b1474.png\"\/><br \/>  \u0414\u043e\u0441\u0442\u0443\u043f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043a service_container \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u0441\u0440\u0430\u0437\u0443 \u043a\u043e \u0432\u0441\u0435\u043c public-\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0430 (\u0447\u0435\u0440\u0435\u0437 $this-&gt;container-&gt;get(&#8216;&#8230;&#8217;)). \u042d\u0442\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 public=false \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0443:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/26b\/44b\/bd4\/26b44bbd4abc334df2bd5a0f7c9d218f.png\"\/><\/p>\n<h2>\u0428\u0430\u0433 3. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b<\/h2>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u0448\u0430\u0433 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u0441\u043b\u0443\u0436\u0438\u0442 \u0441\u043a\u043e\u0440\u0435\u0435 \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430. \u041d\u043e \u0432 \u043e\u0431\u044a\u0435\u043c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u043e\u0440\u043c, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0441\u0432\u044f\u0437\u0435\u0439.<br \/>  \u0412 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0444\u043e\u0440\u043c\u0443 PostType, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0451 \u043a\u0430\u043a \u0441\u0435\u0440\u0432\u0438\u0441:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Form\/PostType.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php namespace AppBundle\\Form;  use JMS\\DiExtraBundle\\Annotation as DI;  \/**  * @DI\\Service(&quot;app.form.post&quot;, public=false)  *\/ class PostType extends AbstractType {     \/* ... *\/ } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Controller\/PostController.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">\/* ... *\/ class PostController extends Controller {     \/**      * @DI\\Inject(&quot;app.form.post&quot;)      * @var \\AppBundle\\Form\\PostType      *\/     public $postType;      public function addAction()     {         $post = new Post();         $form = $this-&gt;createForm($this-&gt;postType, $post);         \/* ... *\/     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u044c \u0444\u043e\u0440\u043c\u044b \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/149\/fbe\/d1b\/149fbed1b431e882d2a6dae8b049d877.png\"\/><\/p>\n<h2>\u0428\u0430\u0433 4. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/h2>\n<p>  <\/p>\n<h3>\u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431: \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435<\/h3>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Doctrine-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u043a\u0430\u043a \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043e\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e Symfony, \u0430 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432 Doctrine. \u041d\u043e \u0442\u0430\u043a\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0451 \u0436\u0435 \u0435\u0441\u0442\u044c, \u0447\u0435\u0440\u0435\u0437 <a href=\"http:\/\/symfony.com\/doc\/current\/components\/dependency_injection\/factories.html\">\u0444\u0430\u0431\u0440\u0438\u0447\u043d\u043e\u0435<\/a> \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u043d\u0430 <a href=\"https:\/\/github.com\/schmittjoh\/JMSDiExtraBundle\/issues\/65\">\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f<\/a> \u0447\u0435\u0440\u0435\u0437 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0438.<br \/>  \u0412 \u0444\u0430\u0439\u043b\u0435 Doctrine-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0443\u043a\u0430\u0436\u0435\u043c \u043f\u0443\u0442\u044c \u043a \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044e:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Entity\/Post.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php namespace AppBundle\\Entity;  use Doctrine\\ORM\\Mapping as ORM;  \/**  * @ORM\\Table()  * @ORM\\Entity(repositoryClass=&quot;AppBundle\\Repository\\PostRepository&quot;)  *\/ class Post {     \/* ... *\/ } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c PostRepository \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u0441\u0442\u043e\u0432:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Repository\/PostRepository.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php namespace AppBundle\\Repository;  use Doctrine\\ORM\\EntityRepository; use Doctrine\\ORM\\Tools\\Pagination\\Paginator;  class PostRepository extends EntityRepository {     public function getListPaginator($first, $max)     {         $qb = $this-&gt;createQueryBuilder('p')             -&gt;orderBy('p.id', 'DESC')             -&gt;setFirstResult($first)             -&gt;setMaxResults($max);         return new Paginator($qb-&gt;getQuery());     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043a\u0430\u043a \u0441\u0435\u0440\u0432\u0438\u0441 <b>app.repository.post<\/b>:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Resources\/config\/services.yml<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>services:     app.repository.post:         class: AppBundle\\Repository\\PostRepository         factory_service: doctrine.orm.entity_manager         factory_method: getRepository         public: false         arguments: [AppBundle\\Entity\\Post] <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Controller\/PostController.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">\/* ... *\/ class PostController extends Controller {     \/**      * @DI\\Inject(&quot;app.repository.post&quot;)      * @var \\AppBundle\\Repository\\PostRepository      *\/     public $postRepository;      protected $itemsPerPage = 10;      \/**      * @Route(&quot;\/list\/{page}&quot;, requirements={&quot;page&quot;=&quot;\\d+&quot;}, defaults={&quot;page&quot;=1}, name=&quot;post_list&quot;)      * @Template      *\/     public function listAction($page)     {         $posts = $this-&gt;postRepository-&gt;getListPaginator(             $first = ($page-1)*$this-&gt;itemsPerPage,             $max = $this-&gt;itemsPerPage         );          return array(             'posts' =&gt; $posts,             'page' =&gt; $page,             'pagesCount' =&gt; ceil(count($posts)\/$this-&gt;itemsPerPage),         );     }     \/* ... *\/ } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h3>\u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432-\u043e\u0431\u0451\u0440\u0442\u043e\u043a<\/h3>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d <a href=\"http:\/\/ru.wikipedia.org\/wiki\/\u0410\u0434\u0430\u043f\u0442\u0435\u0440_(\u0448\u0430\u0431\u043b\u043e\u043d_\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f)\">Adapter<\/a>. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 Doctrine-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0448 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430, \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u043e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438.<br \/>  \u0412 \u0444\u0430\u0439\u043b\u0435 Doctrine-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">src\/AppBundle\/Entity\/Post.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php namespace AppBundle\\Entity;  use Doctrine\\ORM\\Mapping as ORM;  \/**  * @ORM\\Table()  * @ORM\\Entity()  *\/ class Post {     \/* ... *\/ } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 Repository, \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439 \u043e\u0442 doctrine.orm.entity_manager \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f <a href=\"http:\/\/symfony.com\/doc\/current\/components\/dependency_injection\/parentservices.html\">\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432<\/a>:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Repository\/Repository.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php namespace AppBundle\\Repository;  use JMS\\DiExtraBundle\\Annotation as DI;  \/**  * @DI\\Service(&quot;app.repository&quot;, abstract=true)  *\/ class Repository {     \/**      * @DI\\Inject(&quot;doctrine.orm.entity_manager&quot;)      * @var \\Doctrine\\ORM\\EntityManager      *\/     public $em;      protected $repositoryName;      \/** @return \\Doctrine\\ORM\\EntityRepository *\/     protected function getDoctrineRepository()     {         return $this-&gt;em-&gt;getRepository($this-&gt;repositoryName);     }      public function find($id)     {         return $this-&gt;getDoctrineRepository()-&gt;find($id);     }     public function findOneBy(array $criteria)     {         return $this-&gt;getDoctrineRepository()-&gt;findOneBy($criteria);     }     public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)     {         return $this-&gt;getDoctrineRepository()-&gt;findBy($criteria, $orderBy, $limit, $offset);     }     public function findAll()     {         return $this-&gt;getDoctrineRepository()-&gt;findAll();     }     \/** @return \\Doctrine\\ORM\\QueryBuilder *\/     public function createQueryBuilder($alias)     {         return $this-&gt;getDoctrineRepository()-&gt;createQueryBuilder($alias);     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u0442 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f-\u043e\u0431\u0451\u0440\u0442\u043a\u0438:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Repository\/PostRepository.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php namespace AppBundle\\Repository;  use JMS\\DiExtraBundle\\Annotation as DI; use Doctrine\\ORM\\Tools\\Pagination\\Paginator;  \/**  * @DI\\Service(&quot;app.repository.post&quot;, parent=&quot;app.repository&quot;, public=false)  *\/ class PostRepository extends Repository {     protected $repositoryName = 'AppBundle:Post';      public function getListPaginator($first, $max)     {         $qb = $this-&gt;createQueryBuilder('p')             -&gt;orderBy('p.id', 'DESC')             -&gt;setFirstResult($first)             -&gt;setMaxResults($max);          return new Paginator($qb-&gt;getQuery());     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439, \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 parent=\u00abapp.repository\u00bb \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c. JMSDiExtraBundle \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  \u041e\u0431\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\/src\/AppBundle\/Controller\/PostController.php<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">\/* ... *\/ class PostController extends Controller {     \/**      * @DI\\Inject(&quot;app.repository.post&quot;)      * @var \\AppBundle\\Repository\\PostRepository      *\/     public $postRepository;      protected $itemsPerPage = 10;      \/**      * @Route(&quot;\/list\/{page}&quot;, requirements={&quot;page&quot;=&quot;\\d+&quot;}, defaults={&quot;page&quot;=1}, name=&quot;post_list&quot;)      * @Template      *\/     public function listAction($page)     {         $posts = $this-&gt;postRepository-&gt;getListPaginator(             $first = ($page-1)*$this-&gt;itemsPerPage,             $max = $this-&gt;itemsPerPage         );          return array(             'posts' =&gt; $posts,             'page' =&gt; $page,             'pagesCount' =&gt; ceil(count($posts)\/$this-&gt;itemsPerPage),         );     }     \/* ... *\/ } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0433\u0440\u0430\u0444 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/b2b\/1d4\/fdb\/b2b1d4fdbf1b08955f0b435475f2994c.png\"\/><br \/>  \u0414\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0441\u0432\u044f\u0437\u0435\u0439 \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0443:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/03d\/c54\/9ce\/03dc549ce3342285d6a5179e273e2c56.png\"\/><\/p>\n<h2>\u0428\u0430\u0433 5. \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>  \u041a\u0430\u043a \u0412\u044b \u0443\u0436\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0435\u0432\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435. \u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 app.controller.post \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f addAction \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 app.manager.post \u0438 app.form.post, \u0430 listAction \u2013 app.repository.post. \u041d\u043e \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u043a\u0430\u043a\u0443\u044e \u0431\u044b \u043c\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u043b\u0438, \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c\u0438: \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 addAction \u044d\u0442\u043e app.repository.post, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 listAction \u2014 app.manager.post \u0438 app.form.post. \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043a\u0430\u043a \u0431\u044b \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439, \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0433\u043e\u0432\u043e\u0440\u044f\u0442, \u0447\u0442\u043e \u043e\u043d \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043d\u0438\u0437\u043a\u043e\u0439 <a href=\"http:\/\/ru.wikipedia.org\/wiki\/\u0421\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c_(\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435)\">\u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c\u044e<\/a>. \u0427\u0435\u043c \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434, \u0442\u0435\u043c \u0432\u044b\u0448\u0435 \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u043e \u0441\u0432\u043e\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c. \u041a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u0430\u0436\u0434\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c, \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c\u044e. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c, \u043d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e\u0433\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f, \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0432 app.controller.post \u043d\u0430 \u0434\u0432\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/e21\/986\/214\/e2198621460b801414815c1102ae7bff.png\"\/><\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0412\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432\u043e \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0435\u0451 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043e\u043f\u0440\u0430\u0432\u0434\u044b\u0432\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u0430\u0439\u0442\u0443, \u043e\u0442 \u043d\u0435\u0433\u043e \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u043a\u0430\u043a \u0438 \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Symfony (\u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432).<\/p>\n<p>  \u0420\u0430\u0431\u043e\u0447\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c\/\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0434\u0435\u0441\u044c:<br \/>  <a href=\"https:\/\/github.com\/cerritus\/demoblog\">github.com\/cerritus\/demoblog<\/a>    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/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=\"http:\/\/habrahabr.ru\/post\/165237\/\"> http:\/\/habrahabr.ru\/post\/165237\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430-\u0431\u043b\u043e\u0433\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 <a href=\"http:\/\/ru.wikipedia.org\/wiki\/\u0412\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435_\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438\">Dependency Injection<\/a>. \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432\u043e \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b Symfony: \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, doctrine-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>  \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043c \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0441\u0430\u0439\u0442\u0430 \u0434\u043e \u0434\u0432\u0443\u0445:  <\/p>\n<ul>\n<li>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 (\/add)<\/li>\n<li>\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u043f\u043e\u0441\u0442\u043e\u0432 (\/list)<\/li>\n<\/ul>\n<p>  \u0424\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \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:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/1ad\/0c0\/254\/1ad0c025444925b70b96ff89b623101e.png\"\/>  <\/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-165237","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/165237","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=165237"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/165237\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}