Skip to content

Commit 0d31d5c

Browse files
authored
Merge pull request #1988 from dunglas/serializer-41
Implement CacheableSupportsMethodInterface introduced in Symfony 4.1
2 parents 6a8f942 + 414c5bc commit 0d31d5c

File tree

44 files changed

+291
-25
lines changed

Some content is hidden

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

44 files changed

+291
-25
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ env:
1313

1414
matrix:
1515
include:
16-
- php: '7.0'
1716
- php: '7.1'
1817
- php: '7.2'
1918
- php: '7.2'

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=7.0",
16+
"php": ">=7.1",
1717

1818
"doctrine/inflector": "^1.0",
1919
"psr/cache": "^1.0",
@@ -22,7 +22,7 @@
2222
"symfony/http-kernel": "^2.7 || ^3.0 || ^4.0",
2323
"symfony/property-access": "^2.7 || ^3.0 || ^4.0",
2424
"symfony/property-info": "^3.3.11 || ^4.0",
25-
"symfony/serializer": "^3.1 || ^4.0",
25+
"symfony/serializer": "^4.1",
2626
"willdurand/negotiation": "^2.0.3"
2727
},
2828
"require-dev": {

src/Hal/Serializer/EntrypointNormalizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
use ApiPlatform\Core\Api\UrlGeneratorInterface;
1919
use ApiPlatform\Core\Exception\InvalidArgumentException;
2020
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
21+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
2122
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2223

2324
/**
2425
* Normalizes the API entrypoint.
2526
*
2627
* @author Kévin Dunglas <[email protected]>
2728
*/
28-
final class EntrypointNormalizer implements NormalizerInterface
29+
final class EntrypointNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
2930
{
3031
const FORMAT = 'jsonhal';
3132

@@ -70,4 +71,12 @@ public function supportsNormalization($data, $format = null)
7071
{
7172
return self::FORMAT === $format && $data instanceof Entrypoint;
7273
}
74+
75+
/**
76+
* {@inheritdoc}
77+
*/
78+
public function hasCacheableSupportsMethod(): bool
79+
{
80+
return true;
81+
}
7382
}

src/Hydra/Serializer/CollectionFiltersNormalizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait;
2121
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
2222
use Psr\Container\ContainerInterface;
23+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
2324
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
2425
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2526

@@ -28,7 +29,7 @@
2829
*
2930
* @author Samuel ROZE <[email protected]>
3031
*/
31-
final class CollectionFiltersNormalizer implements NormalizerInterface, NormalizerAwareInterface
32+
final class CollectionFiltersNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
3233
{
3334
use JsonLdContextTrait;
3435
use FilterLocatorTrait;
@@ -57,6 +58,14 @@ public function supportsNormalization($data, $format = null)
5758
return $this->collectionNormalizer->supportsNormalization($data, $format);
5859
}
5960

61+
/**
62+
* {@inheritdoc}
63+
*/
64+
public function hasCacheableSupportsMethod(): bool
65+
{
66+
return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod();
67+
}
68+
6069
/**
6170
* {@inheritdoc}
6271
*/

src/Hydra/Serializer/CollectionNormalizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use ApiPlatform\Core\JsonLd\ContextBuilderInterface;
2222
use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait;
2323
use ApiPlatform\Core\Serializer\ContextTrait;
24+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
2425
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
2526
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
2627
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@@ -31,7 +32,7 @@
3132
* @author Kevin Dunglas <[email protected]>
3233
* @author Samuel ROZE <[email protected]>
3334
*/
34-
final class CollectionNormalizer implements NormalizerInterface, NormalizerAwareInterface
35+
final class CollectionNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
3536
{
3637
use ContextTrait;
3738
use JsonLdContextTrait;
@@ -100,4 +101,12 @@ public function normalize($object, $format = null, array $context = [])
100101

101102
return $data;
102103
}
104+
105+
/**
106+
* {@inheritdoc}
107+
*/
108+
public function hasCacheableSupportsMethod(): bool
109+
{
110+
return true;
111+
}
103112
}

src/Hydra/Serializer/DocumentationNormalizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929
use Symfony\Component\PropertyInfo\Type;
3030
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
3131
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
32+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
3233
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
3334

3435
/**
3536
* Creates a machine readable Hydra API documentation.
3637
*
3738
* @author Kévin Dunglas <[email protected]>
3839
*/
39-
final class DocumentationNormalizer implements NormalizerInterface
40+
final class DocumentationNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
4041
{
4142
const FORMAT = 'jsonld';
4243

@@ -581,4 +582,12 @@ public function supportsNormalization($data, $format = null, array $context = []
581582
{
582583
return self::FORMAT === $format && $data instanceof Documentation;
583584
}
585+
586+
/**
587+
* {@inheritdoc}
588+
*/
589+
public function hasCacheableSupportsMethod(): bool
590+
{
591+
return true;
592+
}
584593
}

src/Hydra/Serializer/EntrypointNormalizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
use ApiPlatform\Core\Api\UrlGeneratorInterface;
1919
use ApiPlatform\Core\Exception\InvalidArgumentException;
2020
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
21+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
2122
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2223

2324
/**
2425
* Normalizes the API entrypoint.
2526
*
2627
* @author Kévin Dunglas <[email protected]>
2728
*/
28-
final class EntrypointNormalizer implements NormalizerInterface
29+
final class EntrypointNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
2930
{
3031
const FORMAT = 'jsonld';
3132

@@ -74,4 +75,12 @@ public function supportsNormalization($data, $format = null, array $context = []
7475
{
7576
return self::FORMAT === $format && $data instanceof Entrypoint;
7677
}
78+
79+
/**
80+
* {@inheritdoc}
81+
*/
82+
public function hasCacheableSupportsMethod(): bool
83+
{
84+
return true;
85+
}
7786
}

src/Hydra/Serializer/ErrorNormalizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Core\Api\UrlGeneratorInterface;
1717
use ApiPlatform\Core\Problem\Serializer\ErrorNormalizerTrait;
1818
use Symfony\Component\Debug\Exception\FlattenException;
19+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
1920
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2021

2122
/**
@@ -24,7 +25,7 @@
2425
* @author Kévin Dunglas <[email protected]>
2526
* @author Samuel ROZE <[email protected]>
2627
*/
27-
final class ErrorNormalizer implements NormalizerInterface
28+
final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
2829
{
2930
const FORMAT = 'jsonld';
3031

@@ -65,4 +66,12 @@ public function supportsNormalization($data, $format = null)
6566
{
6667
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
6768
}
69+
70+
/**
71+
* {@inheritdoc}
72+
*/
73+
public function hasCacheableSupportsMethod(): bool
74+
{
75+
return true;
76+
}
6877
}

src/Hydra/Serializer/PartialCollectionViewNormalizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiPlatform\Core\DataProvider\PartialPaginatorInterface;
1818
use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait;
1919
use ApiPlatform\Core\Util\IriHelper;
20+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
2021
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
2122
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2223

@@ -26,7 +27,7 @@
2627
* @author Kévin Dunglas <[email protected]>
2728
* @author Samuel ROZE <[email protected]>
2829
*/
29-
final class PartialCollectionViewNormalizer implements NormalizerInterface, NormalizerAwareInterface
30+
final class PartialCollectionViewNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
3031
{
3132
use JsonLdContextTrait;
3233

@@ -102,6 +103,14 @@ public function supportsNormalization($data, $format = null)
102103
return $this->collectionNormalizer->supportsNormalization($data, $format);
103104
}
104105

106+
/**
107+
* {@inheritdoc}
108+
*/
109+
public function hasCacheableSupportsMethod(): bool
110+
{
111+
return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod();
112+
}
113+
105114
/**
106115
* {@inheritdoc}
107116
*/

src/Identifier/Normalizer/DateTimeIdentifierDenormalizer.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,25 @@
1414
namespace ApiPlatform\Core\Identifier\Normalizer;
1515

1616
use ApiPlatform\Core\Exception\InvalidIdentifierException;
17-
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
17+
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
1818
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
19-
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
2019

21-
final class DateTimeIdentifierDenormalizer extends DateTimeNormalizer implements DenormalizerInterface
20+
final class DateTimeIdentifierDenormalizer extends DateTimeNormalizer
2221
{
2322
public function denormalize($data, $class, $format = null, array $context = [])
2423
{
2524
try {
2625
return parent::denormalize($data, $class, $format, $context);
27-
} catch (InvalidArgumentException $e) {
26+
} catch (NotNormalizableValueException $e) {
2827
throw new InvalidIdentifierException($e->getMessage(), $e->getCode(), $e);
2928
}
3029
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function hasCacheableSupportsMethod(): bool
35+
{
36+
return true;
37+
}
3138
}

0 commit comments

Comments
 (0)