GitHub PullRequestReviewCommentEvent at 2014-05-03 08:59:07
Repository: symfony-docs
Actor: WouterJ
Payload: {"comment":{"url":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/12255594","id":12255594,"diff_hunk":"@@ -0,0 +1,105 @@\n+.. index::\n+   single: Doctrine; Service\n+\n+How to turn your Doctrine repository into a service\n+===================================================\n+\n+Working with repositories can be a pretty messy task. Sometimes it is more\n+logic to perform certain things right in the repository instead of pulling\n+the data and handle it in other places.\n+Since this often requires to have other services at hand it is a good\n+idea to turn your standard Doctrine repository into a service.\n+\n+Let's start with the repository itself. The process is pretty straight forward:\n+if you might need to log something, here is the how-to too::\n+\n+    // src/Acme/BlogBundle/Entity/Repository.php;\n+    \n+    namespace Acme\\BlogBundle\\Entity\\Repository;\n+\t\n+    use Psr\\Log\\NullLogger;\n+    use Psr\\Log\\LoggerInterface;\n+    use Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata;\n+    use Doctrine\\ORM\\EntityRepository;\n+    use Doctrine\\ORM\\EntityManager;\n+\t\n+    class PostRepository extends EntityRepository\n+    {\n+\tprivate $logger; /** @var LoggerInterface */\n+\t\n+        public function __construct(EntityManager $em, ClassMetadata $class)\n+        {\n+            parent::__construct($em, $class);\n+\t\n+            $this->logger = new NullLogger();\n+        }\n+\t\n+        public function setLogger(LoggerInterface $logger)\n+        {\n+            $this->logger = $logger;\n+        }\n+        \n+        // ...\n+    }\n+\t \n+Proceed with creating the service definition:\n+\n+.. configuration-block::\n+\n+    .. code-block:: yaml\n+    \n+   \t# src/Acme/BlogBundle/Resources/config/config.yml\n+    \t# todo\n+\n+    .. code-block:: xml\n+    \n+    \t<!-- src/Acme/BlogBundle/Resources/config/config.xml -->\n+\t<container xmlns=\"http://symfony.com/schema/dic/services\"\n+\t           xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n+\t           xsi:schemaLocation=\"http://symfony.com/schema/dic/services/services-1.0.xsd\">\n+\t\t<services>\n+\t        <service id=\"acme.blog.repository.event\"\n+\t            class=\"Acme\\BlogBundle\\Entity\\Repository\\PostRepository\"\n+\t            factory-service=\"doctrine.orm.entity_manager\"\n+\t            factory-method=\"getRepository\">\n+\t            <argument>Acme\\BlogBundle\\Entity\\Blog</argument>\n+\t            \n+\t            <call method=\"setLogger\">\n+\t\t\t<argument type=\"service\" id=\"logger\" />\n+\t\t    </call>\n+\t        </service>\n+\t    </services>\n+\t</container>\n+\t\n+    .. code-block:: php\n+    \n+    \t// src/Acme/BlogBundle/Resources/config/config.php\n+    \t// @todo\n+    \t\n+    \n+Finally, use your repository in your standard controller::\n+\n+    // src/Acme/BlogBundle/Controller/PostController.php\n+    ","path":"cookbook/doctrine/repository_service.rst","position":83,"original_position":83,"commit_id":"6133d90593c16b821a7880285df81f5350fc98c9","original_commit_id":"6133d90593c16b821a7880285df81f5350fc98c9","user":{"login":"WouterJ","id":749025,"avatar_url":"https://avatars.githubusercontent.com/u/749025?","gravatar_id":"331582449435f5efa35be870ab76f1a9","url":"https://api.github.com/users/WouterJ","html_url":"https://github.com/WouterJ","followers_url":"https://api.github.com/users/WouterJ/followers","following_url":"https://api.github.com/users/WouterJ/following{/other_user}","gists_url":"https://api.github.com/users/WouterJ/gists{/gist_id}","starred_url":"https://api.github.com/users/WouterJ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WouterJ/subscriptions","organizations_url":"https://api.github.com/users/WouterJ/orgs","repos_url":"https://api.github.com/users/WouterJ/repos","events_url":"https://api.github.com/users/WouterJ/events{/privacy}","received_events_url":"https://api.github.com/users/WouterJ/received_events","type":"User","site_admin":false},"body":"remove this line","created_at":"2014-05-03T08:59:07Z","updated_at":"2014-05-03T08:59:07Z","html_url":"https://github.com/symfony/symfony-docs/pull/3825#discussion_r12255594","pull_request_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/3825","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/12255594"},"html":{"href":"https://github.com/symfony/symfony-docs/pull/3825#discussion_r12255594"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/3825"}}}}