Skip to content

Commit

Permalink
allow doctrine/persistence 3
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jan 9, 2024
1 parent 2ab2932 commit 3987e19
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"doctrine/annotations": "^1.14.3 || ^2.0",
"doctrine/data-fixtures": "^1.0",
"doctrine/event-manager": "^1.0 || ^2.0",
"doctrine/persistence": "^2.4",
"doctrine/persistence": "^2.4 || ^3.0",
"phpcr/phpcr": "^2.1.1",
"phpcr/phpcr-implementation": "^2.1",
"phpcr/phpcr-utils": "^1.3.0 || ^2.0",
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/PHPCR/ChildrenCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ChildrenCollection extends PersistentCollection
*/
public function __construct(DocumentManagerInterface $dm, object $document, $filter = null, int $fetchDepth = -1, string $locale = null)
{
$this->dm = $dm;
parent::__construct($dm);
$this->document = $document;
$this->filter = $filter;
$this->fetchDepth = $fetchDepth;
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/PHPCR/ImmutableReferrersCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(DocumentManagerInterface $dm, $document, $type = nul
parent::__construct($dm, $document, $type, null, $locale);
}

public function add($element): bool
public function add($element)
{
throw new BadMethodCallException('Can not call '.__METHOD__.' on immutable collection');
}
Expand Down
24 changes: 22 additions & 2 deletions lib/Doctrine/ODM/PHPCR/PersistentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public function unwrap(): Collection
return new ArrayCollection();
}

public function add($element): bool
public function add($element)
{
$this->initialize();
$this->isDirty = true;

return $this->collection->add($element);
$this->collection->add($element);
}

public function clear(): void
Expand Down Expand Up @@ -123,6 +123,26 @@ public function first()
return $this->collection->first();
}

public function findFirst(\Closure $p): Collection
{
if (!method_exists($this->collection, 'findFirst')) {
throw new \RuntimeException('Upgrade doctrine/collections to version 2 or newer to use this method');
}
$this->initialize();

return $this->collection->findFirst($p);
}

public function reduce(\Closure $p, $initial = null)
{
if (!method_exists($this->collection, 'findFirst')) {
throw new \RuntimeException('Upgrade doctrine/collections to version 2 or newer to use this method');
}
$this->initialize();

return $this->collection->reduce($p);
}

public function forAll(\Closure $p): bool
{
$this->initialize();
Expand Down

0 comments on commit 3987e19

Please sign in to comment.