Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce EntityRepositoryInterface, ancestor for custom repositories #6871

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/en/reference/advanced-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ implementations.
Default Repository (***OPTIONAL***)
-----------------------------------

Specifies the FQCN of a subclass of the EntityRepository.
Specifies the FQCN of a class implementing EntityRepositoryInterface.
That will be available for all entities without a custom repository class.

.. code-block:: php
Expand All @@ -421,7 +421,7 @@ That will be available for all entities without a custom repository class.
$config->getDefaultRepositoryClassName();

The default value is ``Doctrine\ORM\EntityRepository``.
Any repository class must be a subclass of EntityRepository otherwise you got an ORMException
Any repository class must implement EntityRepositoryInterface otherwise you got an ORMException

Setting up the Console
----------------------
Expand Down
6 changes: 3 additions & 3 deletions docs/en/reference/annotations-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ the persistence of all classes marked as entities.

Optional attributes:

- **repositoryClass**: Specifies the FQCN of a subclass of the
EntityRepository. Use of repositories for entities is encouraged to keep
- **repositoryClass**: Specifies the FQCN of a class implementing the
EntityRepositoryInterface. Use of repositories for entities is encouraged to keep
specialized DQL and SQL operations separated from the Model/Domain
Layer.
- **readOnly**: (>= 2.1) Specifies that this entity is marked as read only and not
Expand Down Expand Up @@ -799,7 +799,7 @@ The @MappedSuperclass annotation cannot be used in conjunction with

Optional attributes:

- **repositoryClass**: (>= 2.2) Specifies the FQCN of a subclass of the EntityRepository.
- **repositoryClass**: (>= 2.2) Specifies the FQCN of a class implementing the EntityRepositoryInterface.
That will be inherited for all subclasses of that Mapped Superclass.

Example:
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/working-with-associations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ the details inside the classes can be challenging.
This will however always initialize the collection, with all the
performance penalties given the size. In some scenarios of large
collections it might even be a good idea to completely hide the
read access behind methods on the EntityRepository.
read access behind methods on the EntityRepositoryInterface.

There is no single, best way for association management. It greatly
depends on the requirements of your concrete domain model as well
Expand Down
8 changes: 4 additions & 4 deletions docs/en/reference/working-with-objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ following:
``EntityManager#getRepository($entityName)`` returns a repository
object which provides many ways to retrieve entities of the
specified type. By default, the repository instance is of type
``Doctrine\ORM\EntityRepository``. You can also use custom
``Doctrine\ORM\EntityRepositoryInterface``. You can also use custom
repository classes as shown later.

By Simple Conditions
Expand Down Expand Up @@ -594,7 +594,7 @@ You can also load by owning side associations through the repository:
$number = $em->find('MyProject\Domain\Phonenumber', 1234);
$user = $em->getRepository('MyProject\Domain\User')->findOneBy(array('phone' => $number->getId()));

The ``EntityRepository#findBy()`` method additionally accepts orderings, limit and offset as second to fourth parameters:
The ``EntityRepositoryInterface#findBy()`` method additionally accepts orderings, limit and offset as second to fourth parameters:

.. code-block:: php

Expand All @@ -609,7 +609,7 @@ If you pass an array of values Doctrine will convert the query into a WHERE fiel
$users = $em->getRepository('MyProject\Domain\User')->findBy(array('age' => array(20, 30, 40)));
// translates roughly to: SELECT * FROM users WHERE age IN (20, 30, 40)

An EntityRepository also provides a mechanism for more concise
An EntityRepositoryInterface also provides a mechanism for more concise
calls through its use of ``__call``. Thus, the following two
examples are equivalent:

Expand Down Expand Up @@ -707,7 +707,7 @@ Custom Repositories
~~~~~~~~~~~~~~~~~~~

By default the EntityManager returns a default implementation of
``Doctrine\ORM\EntityRepository`` when you call
``Doctrine\ORM\EntityRepositoryInterface`` when you call
``EntityManager#getRepository($entityClass)``. You can overwrite
this behaviour by specifying the class name of your own Entity
Repository in the Annotation, XML or YAML metadata. In large
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/xml-mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Optional attributes:
- **table** - The Table-Name to be used for this entity. Otherwise the
Unqualified Class-Name is used by default.
- **repository-class** - The fully qualified class-name of an
alternative ``Doctrine\ORM\EntityRepository`` implementation to be
alternative ``Doctrine\ORM\EntityRepositoryInterface`` implementation to be
used with this entity.
- **inheritance-type** - The type of inheritance, defaults to none. A
more detailed description follows in the
Expand Down
6 changes: 3 additions & 3 deletions docs/en/tutorials/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1425,8 +1425,8 @@ example querying for all closed bugs:
// do stuff
}

Compared to DQL these query methods are falling short of functionality very fast.
Doctrine offers you a convenient way to extend the functionalities of the default ``EntityRepository``
Compared to DQL these query methods are falling short of functionality very fast. Doctrine offers
you a convenient way to extend the functionalities of the default ``EntityRepositoryInterface``
and put all the specialized DQL query logic on it. For this you have to create a subclass
of ``Doctrine\ORM\EntityRepository``, in our case a ``BugRepository`` and group all
the previously discussed query functionality in it:
Expand Down Expand Up @@ -1515,7 +1515,7 @@ we have to adjust the metadata slightly.
type: entity
repositoryClass: BugRepository

Now we can remove our query logic in all the places and instead use them through the EntityRepository.
Now we can remove our query logic in all the places and instead use them through the repository.
As an example here is the code of the first use case "List of Bugs":

.. code-block:: php
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,13 @@ public function getFilterClassName(string $filterName) : ?string
*
* @since 2.2
*
* @throws ORMException If not is a \Doctrine\Common\Persistence\ObjectRepository implementation
* @throws ORMException If not is a \Doctrine\ORM\EntityRepositoryInterface implementation
*/
public function setDefaultRepositoryClassName(string $repositoryClassName) : void
{
$reflectionClass = new \ReflectionClass($repositoryClassName);

if ( ! $reflectionClass->implementsInterface(ObjectRepository::class)) {
if ( ! $reflectionClass->implementsInterface(EntityRepositoryInterface::class)) {
throw ORMException::invalidEntityRepository($repositoryClassName);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public function lock($entity, $lockMode, $lockVersion = null)
*
* @param string $entityName The name of the entity.
*
* @return \Doctrine\Common\Persistence\ObjectRepository|\Doctrine\ORM\EntityRepository The repository class.
* @return EntityRepositoryInterface The repository class.
*/
public function getRepository($entityName)
{
Expand Down
Loading