Skip to content

Commit 6980627

Browse files
authored
Merge pull request #2640 from meyerbaptiste/fix_bc_break
Remove a BC break introduced by #2243
2 parents 345612c + 8e1ee34 commit 6980627

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/Bridge/Doctrine/Orm/Filter/ExistsFilter.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\ExistsFilterTrait;
1818
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryBuilderHelper;
1919
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
20+
use ApiPlatform\Core\Exception\InvalidArgumentException;
2021
use Doctrine\Common\Persistence\ManagerRegistry;
2122
use Doctrine\ORM\Mapping\ClassMetadataInfo;
2223
use Doctrine\ORM\Query\Expr\Join;
@@ -44,8 +45,31 @@ class ExistsFilter extends AbstractContextAwareFilter implements ExistsFilterInt
4445
/**
4546
* @param RequestStack|null $requestStack No prefix to prevent autowiring of this deprecated property
4647
*/
47-
public function __construct(ManagerRegistry $managerRegistry, $requestStack = null, LoggerInterface $logger = null, string $existsParameterName = self::QUERY_PARAMETER_KEY, array $properties = null)
48+
public function __construct(ManagerRegistry $managerRegistry, $requestStack = null, LoggerInterface $logger = null, /* string $existsParameterName = self::QUERY_PARAMETER_KEY, array*/ $properties = null)
4849
{
50+
$existsParameterName = self::QUERY_PARAMETER_KEY;
51+
52+
if (($funcNumArgs = \func_num_args()) > 3) {
53+
$fourthArgument = func_get_arg(3);
54+
if (4 <= $funcNumArgs && (null === $fourthArgument || \is_array($fourthArgument))) {
55+
@trigger_error(sprintf('Passing the "$properties" argument as 4th argument of "%s" is deprecated since API Platform 2.5 and will not be possible anymore in API Platform 3. Pass the new "$existsParameterName" argument as 4th argument and the old "$properties" argument as 5th argument instead.', __CLASS__), E_USER_DEPRECATED);
56+
$properties = $fourthArgument;
57+
} elseif (\is_string($fourthArgument)) {
58+
$existsParameterName = $fourthArgument;
59+
} else {
60+
throw new InvalidArgumentException(sprintf('The "$existsParameterName" argument of "%s" is expected to be a string.', __CLASS__));
61+
}
62+
}
63+
64+
if ($funcNumArgs > 4) {
65+
$fifthArgument = func_get_arg(4);
66+
if (null === $fifthArgument || \is_array($fifthArgument)) {
67+
$properties = $fifthArgument;
68+
} else {
69+
throw new InvalidArgumentException(sprintf('The "$properties" argument of "%s" is expected to be an array or null.', __CLASS__));
70+
}
71+
}
72+
4973
parent::__construct($managerRegistry, $requestStack, $logger, $properties);
5074

5175
$this->existsParameterName = $existsParameterName;
@@ -71,8 +95,20 @@ public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $q
7195
/**
7296
* {@inheritdoc}
7397
*/
74-
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null, array $context = []): void
98+
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null/*, array $context = []*/)
7599
{
100+
if (\func_num_args() > 6) {
101+
$context = func_get_arg(6);
102+
} else {
103+
if (__CLASS__ !== \get_class($this)) {
104+
$r = new \ReflectionMethod($this, __FUNCTION__);
105+
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
106+
@trigger_error(sprintf('Method %s() will have a seventh `$context` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.5.', __FUNCTION__), E_USER_DEPRECATED);
107+
}
108+
}
109+
$context = [];
110+
}
111+
76112
if (
77113
(($context['exists_deprecated_syntax'] ?? false) && !isset($value[self::QUERY_PARAMETER_KEY])) ||
78114
!$this->isPropertyEnabled($property, $resourceClass) ||

0 commit comments

Comments
 (0)