Skip to content

Commit 7c4e151

Browse files
authored
Merge pull request #864 from doctrine/relax-find
explicitly relax the find method
2 parents 917fc65 + 92d4a90 commit 7c4e151

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

docs/en/reference/architecture.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Architecture
22
============
33

4-
The architecture of the PHPCR-ODM is similar to that of Doctrine 2 ORM. Please read
4+
The architecture of the PHPCR-ODM is similar to that of Doctrine ORM. Please read
55
the `ORM architecture chapter <https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/architecture.html>`_ to get a basic understanding of the Doctrine
66
architecture. We will focus on some notable differences here.
77

docs/en/reference/installation-configuration.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ Proxy Objects
421421

422422
A proxy object is an object that is put in place or used instead of
423423
the "real" object. A proxy object can add behavior to the object
424-
being proxied without that object being aware of it. In Doctrine 2,
424+
being proxied without that object being aware of it. In Doctrine,
425425
proxy objects are used to realize several features but mainly for
426426
transparent lazy-loading.
427427

@@ -431,7 +431,7 @@ of the objects. This is an essential property as without it there
431431
would always be fragile partial objects at the outer edges of your
432432
object graph.
433433

434-
Doctrine 2 implements a variant of the proxy pattern where it
434+
Doctrine implements a variant of the proxy pattern where it
435435
generates classes that extend your entity classes and adds
436436
lazy-loading capabilities to them. Doctrine can then give you an
437437
instance of such a proxy class whenever you request an object of
@@ -498,7 +498,7 @@ each time you change anything on your class or mapping:
498498
Multiple Metadata Sources
499499
~~~~~~~~~~~~~~~~~~~~~~~~~
500500

501-
When using different components using Doctrine 2 you may end up
501+
When using different components using Doctrine you may end up
502502
with them using two different metadata drivers, for example XML and
503503
YAML. You can use the DriverChain Metadata implementations to
504504
aggregate these drivers based on namespaces::

docs/en/reference/working-with-objects.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ with the headline "Hello World" with the ID ``/cms/article/hello-world``::
4949
has a table per class and thus always needs the document class name,
5050
PHPCR-ODM has one tree for all documents. The above call will find you
5151
whatever document is at that path. Note that you may optionally specify
52-
the class name to have PHPCR-ODM detect if the document is not of the
53-
expected type.
52+
the class name to have PHPCR-ODM check if the document is not of the
53+
expected type. On a class mismatch, PHPCR-ODM treats the lookup as a not
54+
found and returns ``null``.
5455

5556
In this case, the article is retrieved from the document manager twice,
56-
but modified in between. Doctrine 2 realizes that it is the same ID and will
57+
but modified in between. Doctrine realizes that it is the same ID and will
5758
only ever give you access to one instance of the Article with ID
5859
``/cms/article/hello-world``, no matter how often do you retrieve it from
5960
the ``DocumentManager`` and even no matter what kind of Query method you are
@@ -619,16 +620,16 @@ example::
619620
$user = $em->find(User::class, $id);
620621

621622
The return value is either the found document instance or null if no
622-
instance could be found with the given identifier.
623+
instance of the specified class can be found with the given identifier.
623624

624625
If you need several documents and know their paths, you can have a considerable
625626
performance gain by using ``DocumentManager::findMany(null, $ids)`` as then
626627
all those documents are loaded from the repository in one request.
627628

628629
You can also specify the class name instead of null to filter to only find
629-
instances of that class. If you go through the repository for a document class
630-
this is equivalent to calling find on the ``DocumentManager`` with that document
631-
class.
630+
instances of that class. If you call ``find`` on the repository of a document
631+
class, this is equivalent to calling ``find`` on the ``DocumentManager`` with
632+
that document class.
632633

633634

634635
By Simple Conditions

lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public function isOpen(): bool
8888
return $this->wrapped->isOpen();
8989
}
9090

91+
public function find(?string $className, $id): ?object
92+
{
93+
return $this->wrapped->find($className, $id);
94+
}
95+
9196
public function findMany(?string $className, array $ids): Collection
9297
{
9398
return $this->wrapped->findMany($className, $ids);

lib/Doctrine/ODM/PHPCR/DocumentManager.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,24 +173,7 @@ public function getClassMetadata($className): ClassMetadata
173173
return $this->metadataFactory->getMetadataFor($className);
174174
}
175175

176-
/**
177-
* {@inheritdoc}
178-
*
179-
* Find the Document with the given id.
180-
*
181-
* Will return null if the document was not found. A document is considered
182-
* not found if the data at $id is not instance of of the specified
183-
* $className. To get the document regardless of its class, pass null.
184-
*
185-
* If the document is translatable, then the language chooser strategy is
186-
* used to load the best suited language for the translatable fields.
187-
*
188-
* @param string|null $className optional object class name to use
189-
* @param string $id the path or uuid of the document to find
190-
*
191-
* @return object|null the document if found, otherwise null
192-
*/
193-
public function find($className, $id): ?object
176+
public function find(?string $className, $id): ?object
194177
{
195178
try {
196179
if (UUIDHelper::isUUID($id)) {

lib/Doctrine/ODM/PHPCR/DocumentManagerInterface.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,27 @@ public function getConfiguration(): Configuration;
109109
*/
110110
public function isOpen(): bool;
111111

112+
/**
113+
* {@inheritdoc}
114+
*
115+
* Overwritten to make the $className argument nullable.
116+
*
117+
* Find the Document with the given id.
118+
*
119+
* Will return null if the document was not found. A document is also
120+
* considered not found if the data at $id is not instance of the specified
121+
* $className. To get the document regardless of its class, pass null.
122+
*
123+
* If the document is translatable, then the language chooser strategy is
124+
* used to load the best suited language for the translatable fields.
125+
*
126+
* @param string|null $className optional object class name to use
127+
* @param string $id the path or uuid of the document to find
128+
*
129+
* @return object|null the document if found, otherwise null
130+
*/
131+
public function find(?string $className, $id): ?object;
132+
112133
/**
113134
* Finds many documents by id.
114135
*

0 commit comments

Comments
 (0)