From 68a6ff4c689f6641a75bf8d135a9f0efc6a515c5 Mon Sep 17 00:00:00 2001 From: Victor Bocharsky Date: Thu, 3 Nov 2016 00:01:42 +0200 Subject: [PATCH 1/2] A few minor improvements --- doctrine/associations.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doctrine/associations.rst b/doctrine/associations.rst index 3d493695ac8..da0b7bc48a7 100644 --- a/doctrine/associations.rst +++ b/doctrine/associations.rst @@ -316,7 +316,7 @@ You can also query in the other direction:: In this case, the same things occur: you first query out for a single ``Category`` object, and then Doctrine makes a second query to retrieve the related ``Product`` -objects, but only once/if you ask for them (i.e. when you call ``->getProducts()``). +objects, but only once/if you ask for them (i.e. when you call ``getProducts()``). The ``$products`` variable is an array of all ``Product`` objects that relate to the given ``Category`` object via their ``category_id`` value. @@ -365,7 +365,7 @@ Of course, if you know up front that you'll need to access both objects, you can avoid the second query by issuing a join in the original query. Add the following method to the ``ProductRepository`` class:: - // src/AppBundle/Entity/ProductRepository.php + // src/AppBundle/Repository/ProductRepository.php public function findOneByIdJoinedToCategory($productId) { $query = $this->getEntityManager() @@ -407,7 +407,7 @@ Doctrine's `Association Mapping Documentation`_. .. note:: If you're using annotations, you'll need to prepend all annotations with - ``ORM\`` (e.g. ``ORM\OneToMany``), which is not reflected in Doctrine's + ``@ORM\`` (e.g. ``@ORM\OneToMany``), which is not reflected in Doctrine's documentation. You'll also need to include the ``use Doctrine\ORM\Mapping as ORM;`` statement, which *imports* the ``ORM`` annotations prefix. From 0226bbc3f2451e44cd91095d410ebfca4baa2cb4 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Sat, 5 Nov 2016 13:23:11 +0200 Subject: [PATCH 2/2] Rename 'Entity' to 'Repository' in namespaces for repository classes --- doctrine/repository.rst | 10 +++++----- security/entity_provider.rst | 6 +++--- service_container/parent_services.rst | 28 +++++++++++++-------------- testing/doctrine.rst | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/doctrine/repository.rst b/doctrine/repository.rst index 573850960ef..bc1af672b1b 100644 --- a/doctrine/repository.rst +++ b/doctrine/repository.rst @@ -21,7 +21,7 @@ To do this, add the repository class name to your entity's mapping definition: use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass="AppBundle\Entity\ProductRepository") + * @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository") */ class Product { @@ -33,7 +33,7 @@ To do this, add the repository class name to your entity's mapping definition: # src/AppBundle/Resources/config/doctrine/Product.orm.yml AppBundle\Entity\Product: type: entity - repositoryClass: AppBundle\Entity\ProductRepository + repositoryClass: AppBundle\Repository\ProductRepository # ... .. code-block:: xml @@ -47,7 +47,7 @@ To do this, add the repository class name to your entity's mapping definition: + repository-class="AppBundle\Repository\ProductRepository"> @@ -72,8 +72,8 @@ entities, ordered alphabetically by name. .. code-block:: php - // src/AppBundle/Entity/ProductRepository.php - namespace AppBundle\Entity; + // src/AppBundle/Repository/ProductRepository.php + namespace AppBundle\Repository; use Doctrine\ORM\EntityRepository; diff --git a/security/entity_provider.rst b/security/entity_provider.rst index bd1803bc3bd..fc761b72d34 100644 --- a/security/entity_provider.rst +++ b/security/entity_provider.rst @@ -50,7 +50,7 @@ For this entry, suppose that you already have a ``User`` entity inside an /** * @ORM\Table(name="app_users") - * @ORM\Entity(repositoryClass="AppBundle\Entity\UserRepository") + * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") */ class User implements UserInterface, \Serializable { @@ -428,8 +428,8 @@ To do this, make your ``UserRepository`` implement a special interface requires three methods: ``loadUserByUsername($username)``, ``refreshUser(UserInterface $user)``, and ``supportsClass($class)``:: - // src/AppBundle/Entity/UserRepository.php - namespace AppBundle\Entity; + // src/AppBundle/Repository/UserRepository.php + namespace AppBundle\Repository; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; diff --git a/service_container/parent_services.rst b/service_container/parent_services.rst index 82abc4cd679..dcbbb582cd2 100644 --- a/service_container/parent_services.rst +++ b/service_container/parent_services.rst @@ -9,8 +9,8 @@ have related classes that share some of the same dependencies. For example, you may have multiple repository classes which need the ``doctrine.entity_manager`` service and an optional ``logger`` service:: - // src/AppBundle/Doctrine/BaseDoctrineRepository.php - namespace AppBundle\Doctrine; + // src/AppBundle/Repository/BaseDoctrineRepository.php + namespace AppBundle\Repository; // ... abstract class BaseDoctrineRepository @@ -48,12 +48,12 @@ duplicated service definitions: - [setLogger, ['@logger']] app.user_repository: - class: AppBundle\Doctrine\DoctrineUserRepository + class: AppBundle\Repository\DoctrineUserRepository # extend the app.base_doctrine_repository service parent: app.base_doctrine_repository app.post_repository: - class: AppBundle\Doctrine\DoctrinePostRepository + class: AppBundle\Repository\DoctrinePostRepository parent: app.base_doctrine_repository # ... @@ -77,12 +77,12 @@ duplicated service definitions: @@ -103,11 +103,11 @@ duplicated service definitions: // extend the app.base_doctrine_repository service $definition = new DefinitionDecorator('app.base_doctrine_repository'); - $definition->setClass('AppBundle\Doctrine\DoctrineUserRepository'); + $definition->setClass('AppBundle\Repository\DoctrineUserRepository'); $container->setDefinition('app.user_repository', $definition); $definition = new DefinitionDecorator('app.base_doctrine_repository'); - $definition->setClass('AppBundle\Doctrine\DoctrinePostRepository'); + $definition->setClass('AppBundle\Repository\DoctrinePostRepository'); $container->setDefinition('app.post_repository', $definition); // ... @@ -144,7 +144,7 @@ in the child class: # ... app.user_repository: - class: AppBundle\Doctrine\DoctrineUserRepository + class: AppBundle\Repository\DoctrineUserRepository parent: app.base_doctrine_repository # overrides the public setting of the parent service @@ -155,7 +155,7 @@ in the child class: arguments: ['@app.username_checker'] app.post_repository: - class: AppBundle\Doctrine\DoctrinePostRepository + class: AppBundle\Repository\DoctrinePostRepository parent: app.base_doctrine_repository # overrides the first argument (using the special index_N key) @@ -174,7 +174,7 @@ in the child class: @@ -184,7 +184,7 @@ in the child class: @@ -202,7 +202,7 @@ in the child class: // ... $definition = new DefinitionDecorator('app.base_doctrine_repository'); - $definition->setClass('AppBundle\Doctrine\DoctrineUserRepository'); + $definition->setClass('AppBundle\Repository\DoctrineUserRepository'); // overrides the public setting of the parent service $definition->setPublic(false); // appends the '@app.username_checker' argument to the parent argument list @@ -210,7 +210,7 @@ in the child class: $container->setDefinition('app.user_repository', $definition); $definition = new DefinitionDecorator('app.base_doctrine_repository'); - $definition->setClass('AppBundle\Doctrine\DoctrinePostRepository'); + $definition->setClass('AppBundle\Repository\DoctrinePostRepository'); // overrides the first argument $definition->replaceArgument(0, new Reference('doctrine.custom_entity_manager')); $container->setDefinition('app.post_repository', $definition); diff --git a/testing/doctrine.rst b/testing/doctrine.rst index 1b4e8ceb00c..b939d4bb02f 100644 --- a/testing/doctrine.rst +++ b/testing/doctrine.rst @@ -18,8 +18,8 @@ If you need to actually execute a query, you will need to boot the kernel to get a valid connection. In this case, you'll extend the ``KernelTestCase``, which makes all of this quite easy:: - // src/AppBundle/Tests/Entity/ProductRepositoryFunctionalTest.php - namespace AppBundle\Tests\Entity; + // src/AppBundle/Tests/Repository/ProductRepositoryFunctionalTest.php + namespace AppBundle\Tests\Repository; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;