Skip to content

Remove a BC break introduced by #2243 #2640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/Bridge/Doctrine/Orm/Filter/ExistsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\ExistsFilterTrait;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryBuilderHelper;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Query\Expr\Join;
Expand Down Expand Up @@ -44,8 +45,31 @@ class ExistsFilter extends AbstractContextAwareFilter implements ExistsFilterInt
/**
* @param RequestStack|null $requestStack No prefix to prevent autowiring of this deprecated property
*/
public function __construct(ManagerRegistry $managerRegistry, $requestStack = null, LoggerInterface $logger = null, string $existsParameterName = self::QUERY_PARAMETER_KEY, array $properties = null)
public function __construct(ManagerRegistry $managerRegistry, $requestStack = null, LoggerInterface $logger = null, /* string $existsParameterName = self::QUERY_PARAMETER_KEY, array*/ $properties = null)
{
$existsParameterName = self::QUERY_PARAMETER_KEY;

if (($funcNumArgs = \func_num_args()) > 3) {
$fourthArgument = func_get_arg(3);
if (4 <= $funcNumArgs && (null === $fourthArgument || \is_array($fourthArgument))) {
@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);
$properties = $fourthArgument;
} elseif (\is_string($fourthArgument)) {
$existsParameterName = $fourthArgument;
} else {
throw new InvalidArgumentException(sprintf('The "$existsParameterName" argument of "%s" is expected to be a string.', __CLASS__));
}
}

if ($funcNumArgs > 4) {
$fifthArgument = func_get_arg(4);
if (null === $fifthArgument || \is_array($fifthArgument)) {
$properties = $fifthArgument;
} else {
throw new InvalidArgumentException(sprintf('The "$properties" argument of "%s" is expected to be an array or null.', __CLASS__));
}
}

parent::__construct($managerRegistry, $requestStack, $logger, $properties);

$this->existsParameterName = $existsParameterName;
Expand All @@ -71,8 +95,20 @@ public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $q
/**
* {@inheritdoc}
*/
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null, array $context = []): void
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null/*, array $context = []*/)
{
if (\func_num_args() > 6) {
$context = func_get_arg(6);
} else {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@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);
}
}
$context = [];
}

if (
(($context['exists_deprecated_syntax'] ?? false) && !isset($value[self::QUERY_PARAMETER_KEY])) ||
!$this->isPropertyEnabled($property, $resourceClass) ||
Expand Down