Skip to content

Commit

Permalink
Add a compat trait to address B/C issues with EntityRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Feb 8, 2024
1 parent 66e6a60 commit 7fa503c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
50 changes: 50 additions & 0 deletions src/Tool/ORM/Repository/EntityRepositoryCompat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Doctrine Behavioral Extensions package.
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gedmo\Tool\ORM\Repository;

use Doctrine\ORM\EntityRepository;

if ((new \ReflectionClass(EntityRepository::class))->getMethod('__call')->hasReturnType()) {
// ORM 3.x
/**
* Helper trait to address compatibility issues between ORM 2.x and 3.x.
*
* @mixin EntityRepository
*
* @internal
*/
trait EntityRepositoryCompat
{
public function __call(string $method, array $args): mixed
{
return $this->doCallWithCompat($method, $args);
}

abstract protected function doCallWithCompat($method, $args);
}
} else {
// ORM 2.x
/**
* Helper trait to address compatibility issues between ORM 2.x and 3.x.
*
* @mixin EntityRepository
*
* @internal
*/
trait EntityRepositoryCompat
{
public function __call($method, $args)
{
return $this->doCallWithCompat($method, $args);
}

abstract protected function doCallWithCompat($method, $args);
}
}
5 changes: 4 additions & 1 deletion src/Tree/Entity/Repository/NestedTreeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Gedmo\Exception\InvalidArgumentException;
use Gedmo\Exception\RuntimeException;
use Gedmo\Exception\UnexpectedValueException;
use Gedmo\Tool\ORM\Repository\EntityRepositoryCompat;
use Gedmo\Tool\Wrapper\EntityWrapper;
use Gedmo\Tree\Node;
use Gedmo\Tree\Strategy;
Expand Down Expand Up @@ -43,6 +44,8 @@
*/
class NestedTreeRepository extends AbstractTreeRepository
{
use EntityRepositoryCompat;

/**
* Allows the following 'virtual' methods:
* - persistAsFirstChild($node)
Expand All @@ -64,7 +67,7 @@ class NestedTreeRepository extends AbstractTreeRepository
*
* @return mixed TreeNestedRepository if persistAs* is called
*/
public function __call($method, $args)
protected function doCallWithCompat($method, $args)

Check failure on line 70 in src/Tree/Entity/Repository/NestedTreeRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Gedmo\Tree\Entity\Repository\NestedTreeRepository::doCallWithCompat() has parameter $args with no type specified.

Check failure on line 70 in src/Tree/Entity/Repository/NestedTreeRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Gedmo\Tree\Entity\Repository\NestedTreeRepository::doCallWithCompat() has parameter $method with no type specified.
{
if ('persistAs' === substr($method, 0, 9)) {
if (!isset($args[0])) {
Expand Down

0 comments on commit 7fa503c

Please sign in to comment.