Skip to content

Commit 4c16efe

Browse files
authored
fix(doctrine): remove context aware in the new namespace (#4779)
* fix(doctrine): remove context aware in the new namespace
1 parent f516b0f commit 4c16efe

File tree

247 files changed

+6935
-4614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+6935
-4614
lines changed

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
# Changelog
22

3+
## 2.7.0-beta
4+
5+
Json-Ld: property metadata types and iris (#4769)
6+
Symfony: write listener uri variables converter (#4774)
7+
Metadata: extra properties operation inheritance (#4773)
8+
9+
**BC**
10+
11+
Doctrine: new interfaces for Filters and Extensions ready, switch to the `ApiPlatform\Doctrine` namespace after fixing your deprecations: (#4779)
12+
- `ApiPlatform\Core\Bridge\Doctrine\Orm\Extension` interfaces have an `Operation` instead of the `$operationName`, the new namespace is `ApiPlatform\Doctrine\Orm\Extension`
13+
- `ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Extension` interfaces have an `Operation` instead of the `$operationName`, the new namespace is `ApiPlatform\Doctrine\Odm\Extension`
14+
15+
## 2.7.0-alpha.7
16+
17+
Metadata: defaults deprecation (#4772)
18+
19+
## 2.7.0-alpha.6
20+
21+
GraphQl: output creates its own type in TypeBuilder (#4766)
22+
Metadata: clear missing metadata cache pools (#4770)
23+
Metadata: property override when value is set (#4767)
24+
Metadata: add read and write to extractor (#4760)
25+
JsonSchema: factory backward compatibility layer (#4758)
26+
Metadata: defaults properly overrides metadata (#4759)
27+
Metadata: Add missing processor and provider to extractor (#4754)
28+
29+
## 2.7.0-alpha.5
30+
31+
* Backward compatibility: fix upgrade script for subresources (#4747)
32+
* Backward compatibility: fix dependency injection (#4748)
33+
34+
## 2.7.0-alpha.4
35+
36+
* Backward compatibility: fix dependency injection (#4744)
37+
* Metadata: allow extra keys within defaults (#4743)
38+
339
## 2.7.0-alpha.3
440

541
* Implements Skolem IRIs instead of blank nodes, can be disabled using `iri: false` (#4731)

phpstan.neon.dist

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ parameters:
1616
- src/Symfony/Bundle/Test/Constraint/ArraySubset.php
1717
- tests/Fixtures/app/AppKernel.php
1818
excludePaths:
19+
- src/deprecation.php
1920
- src/Core/Bridge/Symfony/Bundle/Test/Constraint/ArraySubsetLegacy.php
2021
# Class ... extends final class cannot be ignored...
2122
- src/Core/Action/EntrypointAction.php
@@ -282,10 +283,6 @@ parameters:
282283
paths:
283284
- tests/Fixtures/TestBundle/Document/
284285
- tests/Fixtures/TestBundle/Entity/
285-
-
286-
message: '#Strict comparison using !== between .+ and .+ will always evaluate to false\.#'
287-
paths:
288-
- src/Doctrine/Common/PropertyHelperTrait.php
289286
- '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy<(\\?[a-zA-Z0-9_]+)+>::\$[a-zA-Z0-9_]+#'
290287
-
291288
message: '#Call to an undefined method Doctrine\\Persistence\\ObjectManager::getConnection\(\)#'
@@ -296,14 +293,6 @@ parameters:
296293
path: src/Symfony/EventListener/AddFormatListener.php
297294
- '#Parameter \#1 \$vars of class GraphQL\\Language\\AST\\(IntValue|ObjectField|ObjectValue|BooleanValue|ListValue|StringValue)Node constructor expects array<bool\|float\|GraphQL\\Language\\AST\\Location\|GraphQL\\Language\\AST\\NameNode\|GraphQL\\Language\\AST\\NodeList\|GraphQL\\Language\\AST\\SelectionSetNode\|int\|string\|null>, array<string, .+> given\.#'
298295
- '#Parameter \#1 \$defaultContext of class Symfony\\Component\\Serializer\\Encoder\\Json(De|En)code constructor expects array, (int|true) given\.#'
299-
- '#Parameter \#(2|3) \$(resourceMetadataFactory|pagination) of class ApiPlatform\\Doctrine\\Orm\\Extension\\PaginationExtension constructor expects (ApiPlatform\\Core\\Metadata\\Resource\\Factory\\ResourceMetadataFactoryInterface\|Symfony\\Component\\HttpFoundation\\RequestStack|ApiPlatform\\Core\\Metadata\\Resource\\Factory\\ResourceMetadataFactoryInterface\|ApiPlatform\\State\\Pagination\\Pagination), stdClass given\.#'
300-
-
301-
message: '#Parameter \#[0-9] \$filterLocator of class .+ constructor expects ApiPlatform\\Core\\Api\\FilterCollection|Psr\\Container\\ContainerInterface, ArrayObject<mixed, mixed> given\.#'
302-
paths:
303-
- tests/Doctrine/Orm/Extension/FilterExtensionTest.php
304-
- tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php
305-
- tests/Core/Swagger/Serializer/DocumentationNormalizerV2Test.php
306-
- tests/Core/Swagger/Serializer/DocumentationNormalizerV3Test.php
307296
-
308297
message: '#Parameter \#1 \$objectValue of method GraphQL\\Type\\Definition\\InterfaceType::resolveType\(\) expects object, array(<string, string>)? given.#'
309298
path: tests/GraphQl/Type/TypeBuilderTest.php
@@ -324,9 +313,6 @@ parameters:
324313
- '#Constructor of class ApiPlatform\\Core\\Annotation\\ApiProperty has an unused parameter#'
325314

326315
# Expected, due to optional interfaces
327-
- '#Method ApiPlatform\\Doctrine\\Orm\\Extension\\QueryCollectionExtensionInterface::applyToCollection\(\) invoked with 5 parameters, 3-4 required\.#'
328-
- '#Method ApiPlatform\\\Doctrine\\Orm\\Extension\\QueryResult(Item|Collection)ExtensionInterface::getResult\(\) invoked with 4 parameters, 1 required\.#'
329-
- '#Method ApiPlatform\\Doctrine\\Orm\\Extension\\QueryResult(Item|Collection)ExtensionInterface::supportsResult\(\) invoked with 3 parameters, 1-2 required\.#'
330316
- '#Method ApiPlatform\\Core\\Bridge\\Symfony\\Routing\\RouteNameResolverInterface::getRouteName\(\) invoked with 3 parameters, 2 required\.#'
331317
- '#Method ApiPlatform\\Core\\DataPersister\\DataPersisterInterface::persist\(\) invoked with 2 parameters, 1 required\.#'
332318
- '#Method ApiPlatform\\Core\\DataPersister\\DataPersisterInterface::remove\(\) invoked with 2 parameters, 1 required\.#'
@@ -337,8 +323,6 @@ parameters:
337323
- '#Method Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface::supportsNormalization\(\) invoked with 3 parameters, 1-2 required\.#'
338324

339325
# Expected, due to deprecations
340-
- '#Method ApiPlatform\\Doctrine\\Orm\\Filter\\(Abstract|Exists|Order)Filter::filterProperty\(\) invoked with 7 parameters, 5-6 required\.#'
341-
- '#Method ApiPlatform\\Doctrine\\Orm\\Filter\\(AbstractFilter|FilterInterface)::apply\(\) invoked with 5 parameters, 3-4 required\.#'
342326
- '#Method ApiPlatform\\PathResolver\\OperationPathResolverInterface::resolveOperationPath\(\) invoked with 4 parameters, 3 required\.#'
343327
-
344328
message: '#If condition is always false.#'
@@ -369,6 +353,9 @@ parameters:
369353
-
370354
message: "#^Unreachable statement - code above always terminates.$#"
371355
path: tests
356+
-
357+
message: "#^Unreachable statement - code above always terminates.$#"
358+
path: src/Core/Bridge/Doctrine/EventListener/PublishMercureUpdatesListener.php
372359
-
373360
message: "#Access to an undefined static property static\\([^)]+\\)::\\$container.$#"
374361
path: tests

src/Api/FilterLocatorTrait.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace ApiPlatform\Api;
1515

16-
use ApiPlatform\Core\Api\FilterCollection;
17-
use ApiPlatform\Exception\InvalidArgumentException;
1816
use Psr\Container\ContainerInterface;
1917

2018
/**
@@ -26,24 +24,17 @@
2624
*/
2725
trait FilterLocatorTrait
2826
{
27+
/** @var ContainerInterface */
2928
private $filterLocator;
3029

3130
/**
3231
* Sets a filter locator with a backward compatibility.
3332
*
34-
* @param ContainerInterface|FilterCollection|null $filterLocator
33+
* @param ContainerInterface|null $filterLocator
3534
*/
3635
private function setFilterLocator($filterLocator, bool $allowNull = false): void
3736
{
38-
if ($filterLocator instanceof ContainerInterface || $filterLocator instanceof FilterCollection || (null === $filterLocator && $allowNull)) {
39-
if ($filterLocator instanceof FilterCollection) {
40-
@trigger_error(sprintf('The %s class is deprecated since version 2.1 and will be removed in 3.0. Provide an implementation of %s instead.', FilterCollection::class, ContainerInterface::class), \E_USER_DEPRECATED);
41-
}
42-
43-
$this->filterLocator = $filterLocator;
44-
} else {
45-
throw new InvalidArgumentException(sprintf('The "$filterLocator" argument is expected to be an implementation of the "%s" interface%s.', ContainerInterface::class, $allowNull ? ' or null' : ''));
46-
}
37+
$this->filterLocator = $filterLocator;
4738
}
4839

4940
/**
@@ -55,12 +46,6 @@ private function getFilter(string $filterId): ?FilterInterface
5546
return $this->filterLocator->get($filterId);
5647
}
5748

58-
if ($this->filterLocator instanceof FilterCollection && $this->filterLocator->offsetExists($filterId)) {
59-
return $this->filterLocator->offsetGet($filterId);
60-
}
61-
6249
return null;
6350
}
6451
}
65-
66-
class_alias(FilterLocatorTrait::class, \ApiPlatform\Core\Api\FilterLocatorTrait::class);

src/Core/Api/FilterLocatorTrait.php

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,51 @@
1313

1414
namespace ApiPlatform\Core\Api;
1515

16-
class_exists(\ApiPlatform\Api\FilterLocatorTrait::class);
16+
use ApiPlatform\Core\Exception\InvalidArgumentException;
17+
use Psr\Container\ContainerInterface;
1718

18-
if (false) {
19-
trait FilterLocatorTrait
19+
/**
20+
* Manipulates filters with a backward compatibility between the new filter locator and the deprecated filter collection.
21+
*
22+
* @author Baptiste Meyer <[email protected]>
23+
*
24+
* @internal
25+
*/
26+
trait FilterLocatorTrait
27+
{
28+
private $filterLocator;
29+
30+
/**
31+
* Sets a filter locator with a backward compatibility.
32+
*
33+
* @param ContainerInterface|FilterCollection|null $filterLocator
34+
*/
35+
private function setFilterLocator($filterLocator, bool $allowNull = false): void
36+
{
37+
if ($filterLocator instanceof ContainerInterface || $filterLocator instanceof FilterCollection || (null === $filterLocator && $allowNull)) {
38+
if ($filterLocator instanceof FilterCollection) {
39+
@trigger_error(sprintf('The %s class is deprecated since version 2.1 and will be removed in 3.0. Provide an implementation of %s instead.', FilterCollection::class, ContainerInterface::class), \E_USER_DEPRECATED);
40+
}
41+
42+
$this->filterLocator = $filterLocator;
43+
} else {
44+
throw new InvalidArgumentException(sprintf('The "$filterLocator" argument is expected to be an implementation of the "%s" interface%s.', ContainerInterface::class, $allowNull ? ' or null' : ''));
45+
}
46+
}
47+
48+
/**
49+
* Gets a filter with a backward compatibility.
50+
*/
51+
private function getFilter(string $filterId): ?FilterInterface
2052
{
21-
use \ApiPlatform\Api\FilterLocatorTrait;
53+
if ($this->filterLocator instanceof ContainerInterface && $this->filterLocator->has($filterId)) {
54+
return $this->filterLocator->get($filterId);
55+
}
56+
57+
if ($this->filterLocator instanceof FilterCollection && $this->filterLocator->offsetExists($filterId)) {
58+
return $this->filterLocator->offsetGet($filterId);
59+
}
60+
61+
return null;
2262
}
2363
}

src/Core/Bridge/Doctrine/Common/Filter/BooleanFilterTrait.php

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,87 @@
1313

1414
namespace ApiPlatform\Core\Bridge\Doctrine\Common\Filter;
1515

16-
class_exists(\ApiPlatform\Doctrine\Common\Filter\BooleanFilterTrait::class);
16+
use ApiPlatform\Core\Bridge\Doctrine\Common\PropertyHelperTrait;
17+
use ApiPlatform\Core\Exception\InvalidArgumentException;
18+
use Psr\Log\LoggerInterface;
1719

18-
if (false) {
19-
trait BooleanFilterTrait
20+
/**
21+
* Trait for filtering the collection by boolean values.
22+
*
23+
* Filters collection on equality of boolean properties. The value is specified
24+
* as one of ( "true" | "false" | "1" | "0" ) in the query.
25+
*
26+
* For each property passed, if the resource does not have such property or if
27+
* the value is not one of ( "true" | "false" | "1" | "0" ) the property is ignored.
28+
*
29+
* @author Amrouche Hamza <[email protected]>
30+
* @author Teoh Han Hui <[email protected]>
31+
* @author Alan Poulain <[email protected]>
32+
*/
33+
trait BooleanFilterTrait
34+
{
35+
use PropertyHelperTrait;
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function getDescription(string $resourceClass): array
41+
{
42+
$description = [];
43+
44+
$properties = $this->getProperties();
45+
if (null === $properties) {
46+
$properties = array_fill_keys($this->getClassMetadata($resourceClass)->getFieldNames(), null);
47+
}
48+
49+
foreach ($properties as $property => $unused) {
50+
if (!$this->isPropertyMapped($property, $resourceClass) || !$this->isBooleanField($property, $resourceClass)) {
51+
continue;
52+
}
53+
$propertyName = $this->normalizePropertyName($property);
54+
$description[$propertyName] = [
55+
'property' => $propertyName,
56+
'type' => 'bool',
57+
'required' => false,
58+
];
59+
}
60+
61+
return $description;
62+
}
63+
64+
abstract protected function getProperties(): ?array;
65+
66+
abstract protected function getLogger(): LoggerInterface;
67+
68+
abstract protected function normalizePropertyName($property);
69+
70+
/**
71+
* Determines whether the given property refers to a boolean field.
72+
*/
73+
protected function isBooleanField(string $property, string $resourceClass): bool
74+
{
75+
return isset(self::DOCTRINE_BOOLEAN_TYPES[(string) $this->getDoctrineFieldType($property, $resourceClass)]);
76+
}
77+
78+
private function normalizeValue($value, string $property): ?bool
2079
{
21-
use \ApiPlatform\Doctrine\Common\Filter\BooleanFilterTrait;
80+
if (\in_array($value, [true, 'true', '1'], true)) {
81+
return true;
82+
}
83+
84+
if (\in_array($value, [false, 'false', '0'], true)) {
85+
return false;
86+
}
87+
88+
$this->getLogger()->notice('Invalid filter ignored', [
89+
'exception' => new InvalidArgumentException(sprintf('Invalid boolean value for "%s" property, expected one of ( "%s" )', $property, implode('" | "', [
90+
'true',
91+
'false',
92+
'1',
93+
'0',
94+
]))),
95+
]);
96+
97+
return null;
2298
}
2399
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Bridge\Doctrine\Common\Filter;
15+
16+
/**
17+
* Interface for filtering the collection by date intervals.
18+
*
19+
* @author Kévin Dunglas <[email protected]>
20+
* @author Théo FIDRY <[email protected]>
21+
* @author Alan Poulain <[email protected]>
22+
*/
23+
interface DateFilterInterface
24+
{
25+
public const PARAMETER_BEFORE = 'before';
26+
public const PARAMETER_STRICTLY_BEFORE = 'strictly_before';
27+
public const PARAMETER_AFTER = 'after';
28+
public const PARAMETER_STRICTLY_AFTER = 'strictly_after';
29+
public const EXCLUDE_NULL = 'exclude_null';
30+
public const INCLUDE_NULL_BEFORE = 'include_null_before';
31+
public const INCLUDE_NULL_AFTER = 'include_null_after';
32+
public const INCLUDE_NULL_BEFORE_AND_AFTER = 'include_null_before_and_after';
33+
}

0 commit comments

Comments
 (0)