Skip to content

Commit 87ef1fe

Browse files
vincentchalamonalanpoulain
authored andcommitted
Metadata (#36)
* test: fix Metadata tests * test: remove legacy environments from Behat tests * chore: remove deprecations from DeprecationMetadataTrait and rename it to SanitizeMetadataTrait * chore: remove annotation support on Metadata * fix: PHP CS * fix: typo * chore: remove SanitizeMetadataTrait * chore: set PHP dependency to 8.1 in composer.json * fix: PHP typo
1 parent b160e42 commit 87ef1fe

File tree

48 files changed

+85
-1594
lines changed

Some content is hidden

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

48 files changed

+85
-1594
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=7.1",
16+
"php": ">=8.1",
1717
"doctrine/inflector": "^1.0 || ^2.0",
1818
"fig/link-util": "^1.0",
1919
"psr/cache": "^1.0 || ^2.0 || ^3.0",

src/Metadata/Property/DeprecationMetadataTrait.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,7 @@ private function createMetadata(ApiProperty $attribute, ApiProperty $propertyMet
100100
}
101101

102102
foreach (get_class_methods(ApiProperty::class) as $method) {
103-
if (
104-
// TODO: remove these checks for deprecated methods in 3.0
105-
'getAttribute' !== $method &&
106-
'isChildInherited' !== $method &&
107-
'getSubresource' !== $method &&
108-
'getAttributes' !== $method &&
109-
// end of deprecated methods
110-
111-
preg_match('/^(?:get|is)(.*)/', $method, $matches) &&
112-
null !== $val = $attribute->{$method}()
113-
) {
103+
if (preg_match('/^(?:get|is)(.*)/', $method, $matches) && null !== $val = $attribute->{$method}()) {
114104
$propertyMetadata = $propertyMetadata->{"with{$matches[1]}"}($val);
115105
}
116106
}

src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use ApiPlatform\Exception\PropertyNotFoundException;
1717
use ApiPlatform\Metadata\ApiProperty;
1818
use ApiPlatform\Metadata\Extractor\PropertyExtractorInterface;
19-
use ApiPlatform\Metadata\Property\DeprecationMetadataTrait;
2019
use Symfony\Component\PropertyInfo\Type;
2120

2221
/**
@@ -27,7 +26,6 @@
2726
*/
2827
final class ExtractorPropertyMetadataFactory implements PropertyMetadataFactoryInterface
2928
{
30-
use DeprecationMetadataTrait;
3129
private $extractor;
3230
private $decorated;
3331

@@ -65,11 +63,6 @@ public function create(string $resourceClass, string $property, array $options =
6563
$apiProperty = new ApiProperty();
6664

6765
foreach ($propertyMetadata as $key => $value) {
68-
if ('subresource' === $key) {
69-
trigger_deprecation('api-platform', '2.7', 'Using "subresource" is deprecated, declare another resource instead.');
70-
continue;
71-
}
72-
7366
if ('builtinTypes' === $key && null !== $value) {
7467
$value = array_map(function (string $builtinType): Type {
7568
return new Type($builtinType);
@@ -83,10 +76,6 @@ public function create(string $resourceClass, string $property, array $options =
8376
}
8477
}
8578

86-
if (isset($propertyMetadata['attributes'])) {
87-
$apiProperty = $this->withDeprecatedAttributes($apiProperty, $propertyMetadata['attributes']);
88-
}
89-
9079
return $apiProperty;
9180
}
9281

@@ -127,10 +116,6 @@ private function update(ApiProperty $propertyMetadata, array $metadata): ApiProp
127116
$propertyMetadata = $propertyMetadata->{'with'.ucfirst($metadataKey)}($metadata[$metadataKey]);
128117
}
129118

130-
if (isset($metadata['attributes'])) {
131-
$propertyMetadata = $this->withDeprecatedAttributes($propertyMetadata, $metadata['attributes']);
132-
}
133-
134119
return $propertyMetadata;
135120
}
136121
}

src/Metadata/Property/Factory/LegacyPropertyMetadataFactory.php

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/Metadata/Resource/DeprecationMetadataTrait.php

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactory.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
use ApiPlatform\Metadata\Patch;
3333
use ApiPlatform\Metadata\Post;
3434
use ApiPlatform\Metadata\Put;
35-
use ApiPlatform\Metadata\Resource\DeprecationMetadataTrait;
3635
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
3736
use Psr\Log\LoggerInterface;
3837
use Psr\Log\NullLogger;
38+
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
3939

4040
/**
4141
* Creates a resource metadata from {@see ApiResource} annotations.
@@ -45,19 +45,19 @@
4545
*/
4646
final class AttributesResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
4747
{
48-
use DeprecationMetadataTrait;
49-
5048
private $defaults;
5149
private $decorated;
5250
private $logger;
5351
private $graphQlEnabled;
52+
private $camelCaseToSnakeCaseNameConverter;
5453

5554
public function __construct(ResourceMetadataCollectionFactoryInterface $decorated = null, LoggerInterface $logger = null, array $defaults = [], bool $graphQlEnabled = false)
5655
{
5756
$this->defaults = $defaults;
5857
$this->decorated = $decorated;
5958
$this->logger = $logger ?? new NullLogger();
6059
$this->graphQlEnabled = $graphQlEnabled;
60+
$this->camelCaseToSnakeCaseNameConverter = new CamelCaseToSnakeCaseNameConverter();
6161
}
6262

6363
/**
@@ -236,10 +236,8 @@ private function getOperationWithDefaults(ApiResource $resource, Operation $oper
236236
*/
237237
private function addGlobalDefaults($operation)
238238
{
239-
$extraProperties = $operation->getExtraProperties();
240239
foreach ($this->defaults as $key => $value) {
241-
[$newKey, $value] = $this->getKeyValue($key, $value);
242-
$upperKey = ucfirst($newKey);
240+
$upperKey = ucfirst($this->camelCaseToSnakeCaseNameConverter->denormalize($key));
243241
$getter = 'get'.$upperKey;
244242

245243
if (!method_exists($operation, $getter)) {

0 commit comments

Comments
 (0)