-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split find into find with required class name and findDocument for fi…
…nding any document
- Loading branch information
Showing
33 changed files
with
248 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,7 +180,9 @@ public function getClassMetadata($className): ClassMetadata | |
* | ||
* Will return null if the document was not found. A document is considered | ||
* not found if the data at $id is not instance of of the specified | ||
* $className. To get the document regardless of its class, pass null. | ||
* $className. | ||
* | ||
* To get a document regardless of its class, use the ``findDocument`` method. | ||
* | ||
* If the document is translatable, then the language chooser strategy is | ||
* used to load the best suited language for the translatable fields. | ||
|
@@ -190,16 +192,30 @@ public function getClassMetadata($className): ClassMetadata | |
* | ||
* @return object|null the document if found, otherwise null | ||
*/ | ||
public function find($className, $id): ?object | ||
public function find(string $className, mixed $id): ?object | ||
Check failure on line 195 in lib/Doctrine/ODM/PHPCR/DocumentManager.php GitHub Actions / PHPStan
|
||
{ | ||
if (!is_string($id)) { | ||
throw new \InvalidArgumentException('PHPCR-ODM ids must be of type string (either uuid or path), you passed '.gettype($id)); | ||
} | ||
|
||
return $this->doFind($className, $id); | ||
} | ||
|
||
public function findDocument(string $id): ?object | ||
{ | ||
return $this->doFind(null, $id); | ||
} | ||
|
||
private function doFind(?string $className, mixed $id): ?object | ||
{ | ||
try { | ||
if (UUIDHelper::isUUID($id)) { | ||
try { | ||
$id = $this->session->getNodeByIdentifier($id)->getPath(); | ||
} catch (ItemNotFoundException $e) { | ||
} catch (ItemNotFoundException) { | ||
return null; | ||
} | ||
} elseif (0 !== strpos($id, '/')) { | ||
} elseif (!str_starts_with($id, '/')) { | ||
$id = '/'.$id; | ||
} | ||
|
||
|
@@ -209,7 +225,7 @@ public function find($className, $id): ?object | |
$this->unitOfWork->validateClassName($document, $className); | ||
|
||
return $document; | ||
} catch (ClassMismatchException $e) { | ||
} catch (ClassMismatchException) { | ||
return null; | ||
} | ||
} | ||
|
@@ -222,7 +238,7 @@ public function find($className, $id): ?object | |
|
||
try { | ||
return $this->unitOfWork->getOrCreateDocument($className, $node, $hints); | ||
} catch (ClassMismatchException $e) { | ||
} catch (ClassMismatchException) { | ||
return null; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.