Skip to content

Commit

Permalink
Merge 90b8670 into aad8a84
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Apr 15, 2020
2 parents aad8a84 + 90b8670 commit 9998a34
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 53 deletions.
12 changes: 11 additions & 1 deletion .php_cs.dist
Expand Up @@ -108,6 +108,16 @@ return PhpCsFixer\Config::create()
'property',
],
],
'void_return' => false, // BC breaks; to be done in API Platform 3.0
'void_return' => false, // BC breaks; to be done in API Platform 3.0,
// removed get_class_this see https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/4742/files
'function_to_constant' => [
'functions' => [
'get_called_class',
'get_class',
'php_sapi_name',
'phpversion',
'pi'
]
]
])
->setFinder($finder);
4 changes: 0 additions & 4 deletions src/Annotation/ApiResource.php
Expand Up @@ -208,8 +208,6 @@ final class ApiResource
/**
* @see https://api-platform.com/docs/core/mercure
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
*
* @var mixed
*/
private $mercure;

Expand Down Expand Up @@ -384,8 +382,6 @@ final class ApiResource
/**
* @see https://api-platform.com/docs/core/validation/#using-validation-groups
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
*
* @var mixed
*/
private $validationGroups;

Expand Down
8 changes: 0 additions & 8 deletions src/Annotation/AttributesHydratorTrait.php
Expand Up @@ -10,14 +10,6 @@
*/

declare(strict_types=1);
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ApiPlatform\Core\Annotation;

Expand Down
29 changes: 13 additions & 16 deletions src/Bridge/Doctrine/Orm/Filter/SearchFilter.php
Expand Up @@ -92,12 +92,11 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
$caseSensitive = true;
$metadata = $this->getNestedMetadata($resourceClass, $associations);

if ($metadata->hasField($field)) {
if ('id' === $field) {
$values = array_map([$this, 'getIdFromValue'], $values);
}
$doctrineTypeField = $this->getDoctrineFieldType($property, $resourceClass);
$values = array_map([$this, 'getIdFromValue'], $values);

if (!$this->hasValidValues($values, $this->getDoctrineFieldType($property, $resourceClass))) {
if ($metadata->hasField($field)) {
if (!$this->hasValidValues($values, $doctrineTypeField)) {
$this->logger->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Values for field "%s" are not valid according to the doctrine type.', $field)),
]);
Expand All @@ -114,7 +113,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
}

if (1 === \count($values)) {
$this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $alias, $field, $values[0], $caseSensitive);
$this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $alias, $field, $doctrineTypeField, $values[0], $caseSensitive);

return;
}
Expand All @@ -140,9 +139,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
return;
}

$values = array_map([$this, 'getIdFromValue'], $values);
$associationFieldIdentifier = 'id';
$doctrineTypeField = $this->getDoctrineFieldType($property, $resourceClass);

if (null !== $this->identifiersExtractor) {
$associationResourceClass = $metadata->getAssociationTargetClass($field);
Expand Down Expand Up @@ -171,11 +168,11 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
if (1 === \count($values)) {
$queryBuilder
->andWhere(sprintf('%s.%s = :%s', $associationAlias, $associationField, $valueParameter))
->setParameter($valueParameter, $values[0]);
->setParameter($valueParameter, $values[0], $doctrineTypeField);
} else {
$queryBuilder
->andWhere(sprintf('%s.%s IN (:%s)', $associationAlias, $associationField, $valueParameter))
->setParameter($valueParameter, $values);
->setParameter($valueParameter, $values, $doctrineTypeField);
}
}

Expand All @@ -184,7 +181,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
*
* @throws InvalidArgumentException If strategy does not exist
*/
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $value, bool $caseSensitive)
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $fieldType, $value, bool $caseSensitive)
{
$wrapCase = $this->createWrapCase($caseSensitive);
$valueParameter = $queryNameGenerator->generateParameterName($field);
Expand All @@ -194,27 +191,27 @@ protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuild
case self::STRATEGY_EXACT:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' = '.$wrapCase(':%s'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
->setParameter($valueParameter, $value, $fieldType);
break;
case self::STRATEGY_PARTIAL:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s, \'%%\')'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
->setParameter($valueParameter, $value, $fieldType);
break;
case self::STRATEGY_START:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(:%s, \'%%\')'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
->setParameter($valueParameter, $value, $fieldType);
break;
case self::STRATEGY_END:
$queryBuilder
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s)'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
->setParameter($valueParameter, $value, $fieldType);
break;
case self::STRATEGY_WORD_START:
$queryBuilder
->andWhere(sprintf($wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(:%3$s, \'%%\')').' OR '.$wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(\'%% \', :%3$s, \'%%\')'), $alias, $field, $valueParameter))
->setParameter($valueParameter, $value);
->setParameter($valueParameter, $value, $fieldType);
break;
default:
throw new InvalidArgumentException(sprintf('strategy %s does not exist.', $strategy));
Expand Down
Expand Up @@ -70,8 +70,8 @@
<br>
Other API docs:
{% set active_ui = app.request.get('ui', 'swagger_ui') %}
{% if swaggerUiEnabled and active_ui != 'swagger_ui' %}<a href="{{ path('api_entrypoint') }}">Swagger UI</a>{% endif %}
{% if reDocEnabled and active_ui != 're_doc' %}<a href="{{ path('api_entrypoint', {'ui': 're_doc'}) }}">ReDoc</a>{% endif %}
{% if swaggerUiEnabled and active_ui != 'swagger_ui' %}<a href="{{ path('api_doc') }}">Swagger UI</a>{% endif %}
{% if reDocEnabled and active_ui != 're_doc' %}<a href="{{ path('api_doc', {'ui': 're_doc'}) }}">ReDoc</a>{% endif %}
{% if not graphqlEnabled %}<a href="javascript:alert('GraphQL support is not enabled, see https://api-platform.com/docs/core/graphql/')">GraphiQL</a>{% endif %}
{% if graphiQlEnabled %}<a href="{{ path('api_graphql_graphiql') }}">GraphiQL</a>{% endif %}
{% if graphQlPlaygroundEnabled %}<a href="{{ path('api_graphql_graphql_playground') }}">GraphQL Playground</a>{% endif %}
Expand Down
9 changes: 0 additions & 9 deletions src/Bridge/Symfony/Bundle/Test/BrowserKitAssertionsTrait.php
Expand Up @@ -11,15 +11,6 @@

declare(strict_types=1);

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Test;

use PHPUnit\Framework\Constraint\LogicalAnd;
Expand Down
2 changes: 1 addition & 1 deletion src/Hydra/Serializer/PartialCollectionViewNormalizer.php
Expand Up @@ -113,7 +113,7 @@ public function normalize($object, $format = null, array $context = [])
$data['hydra:view']['hydra:previous'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $currentPage - 1.);
}

if (null !== $lastPage && $currentPage !== $lastPage || null === $lastPage && $pageTotalItems >= $itemsPerPage) {
if (null !== $lastPage && $currentPage < $lastPage || null === $lastPage && $pageTotalItems >= $itemsPerPage) {
$data['hydra:view']['hydra:next'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $currentPage + 1.);
}
}
Expand Down
Expand Up @@ -10,14 +10,6 @@
*/

declare(strict_types=1);
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ApiPlatform\Core\Tests\Bridge\Symfony\Validator\Exception;

Expand Down
2 changes: 0 additions & 2 deletions tests/Fixtures/TestBundle/Document/ContainNonResource.php
Expand Up @@ -34,8 +34,6 @@
class ContainNonResource
{
/**
* @var mixed
*
* @ODM\Id(strategy="INCREMENT", type="integer")
*
* @Groups("contain_non_resource")
Expand Down
2 changes: 0 additions & 2 deletions tests/Fixtures/TestBundle/Entity/ContainNonResource.php
Expand Up @@ -34,8 +34,6 @@
class ContainNonResource
{
/**
* @var mixed
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
Expand Down

0 comments on commit 9998a34

Please sign in to comment.