Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ env:

matrix:
include:
- php: '7.0'
- php: '7.1'
- php: '7.2'
- php: '7.2'
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.1",

"doctrine/inflector": "^1.0",
"psr/cache": "^1.0",
Expand All @@ -22,7 +22,7 @@
"symfony/http-kernel": "^2.7 || ^3.0 || ^4.0",
"symfony/property-access": "^2.7 || ^3.0 || ^4.0",
"symfony/property-info": "^3.3.11 || ^4.0",
"symfony/serializer": "^3.1 || ^4.0",
"symfony/serializer": "^4.1",
"willdurand/negotiation": "^2.0.3"
},
"require-dev": {
Expand Down
11 changes: 10 additions & 1 deletion src/Hal/Serializer/EntrypointNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
use ApiPlatform\Core\Api\UrlGeneratorInterface;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Normalizes the API entrypoint.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class EntrypointNormalizer implements NormalizerInterface
final class EntrypointNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
{
const FORMAT = 'jsonhal';

Expand Down Expand Up @@ -70,4 +71,12 @@ public function supportsNormalization($data, $format = null)
{
return self::FORMAT === $format && $data instanceof Entrypoint;
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}
11 changes: 10 additions & 1 deletion src/Hydra/Serializer/CollectionFiltersNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

Expand All @@ -28,7 +29,7 @@
*
* @author Samuel ROZE <samuel.roze@gmail.com>
*/
final class CollectionFiltersNormalizer implements NormalizerInterface, NormalizerAwareInterface
final class CollectionFiltersNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
{
use JsonLdContextTrait;
use FilterLocatorTrait;
Expand Down Expand Up @@ -57,6 +58,14 @@ public function supportsNormalization($data, $format = null)
return $this->collectionNormalizer->supportsNormalization($data, $format);
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod();
}

/**
* {@inheritdoc}
*/
Expand Down
11 changes: 10 additions & 1 deletion src/Hydra/Serializer/CollectionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use ApiPlatform\Core\JsonLd\ContextBuilderInterface;
use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait;
use ApiPlatform\Core\Serializer\ContextTrait;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
Expand All @@ -31,7 +32,7 @@
* @author Kevin Dunglas <dunglas@gmail.com>
* @author Samuel ROZE <samuel.roze@gmail.com>
*/
final class CollectionNormalizer implements NormalizerInterface, NormalizerAwareInterface
final class CollectionNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
{
use ContextTrait;
use JsonLdContextTrait;
Expand Down Expand Up @@ -100,4 +101,12 @@ public function normalize($object, $format = null, array $context = [])

return $data;
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}
11 changes: 10 additions & 1 deletion src/Hydra/Serializer/DocumentationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Creates a machine readable Hydra API documentation.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class DocumentationNormalizer implements NormalizerInterface
final class DocumentationNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
{
const FORMAT = 'jsonld';

Expand Down Expand Up @@ -581,4 +582,12 @@ public function supportsNormalization($data, $format = null, array $context = []
{
return self::FORMAT === $format && $data instanceof Documentation;
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}
11 changes: 10 additions & 1 deletion src/Hydra/Serializer/EntrypointNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
use ApiPlatform\Core\Api\UrlGeneratorInterface;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Normalizes the API entrypoint.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class EntrypointNormalizer implements NormalizerInterface
final class EntrypointNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
{
const FORMAT = 'jsonld';

Expand Down Expand Up @@ -74,4 +75,12 @@ public function supportsNormalization($data, $format = null, array $context = []
{
return self::FORMAT === $format && $data instanceof Entrypoint;
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}
11 changes: 10 additions & 1 deletion src/Hydra/Serializer/ErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ApiPlatform\Core\Api\UrlGeneratorInterface;
use ApiPlatform\Core\Problem\Serializer\ErrorNormalizerTrait;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
Expand All @@ -24,7 +25,7 @@
* @author Kévin Dunglas <dunglas@gmail.com>
* @author Samuel ROZE <samuel.roze@gmail.com>
*/
final class ErrorNormalizer implements NormalizerInterface
final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
{
const FORMAT = 'jsonld';

Expand Down Expand Up @@ -65,4 +66,12 @@ public function supportsNormalization($data, $format = null)
{
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}
11 changes: 10 additions & 1 deletion src/Hydra/Serializer/PartialCollectionViewNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ApiPlatform\Core\DataProvider\PartialPaginatorInterface;
use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait;
use ApiPlatform\Core\Util\IriHelper;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

Expand All @@ -26,7 +27,7 @@
* @author Kévin Dunglas <dunglas@gmail.com>
* @author Samuel ROZE <samuel.roze@gmail.com>
*/
final class PartialCollectionViewNormalizer implements NormalizerInterface, NormalizerAwareInterface
final class PartialCollectionViewNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
{
use JsonLdContextTrait;

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

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod();
}

/**
* {@inheritdoc}
*/
Expand Down
15 changes: 11 additions & 4 deletions src/Identifier/Normalizer/DateTimeIdentifierDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@
namespace ApiPlatform\Core\Identifier\Normalizer;

use ApiPlatform\Core\Exception\InvalidIdentifierException;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

final class DateTimeIdentifierDenormalizer extends DateTimeNormalizer implements DenormalizerInterface
final class DateTimeIdentifierDenormalizer extends DateTimeNormalizer
{
public function denormalize($data, $class, $format = null, array $context = [])
{
try {
return parent::denormalize($data, $class, $format, $context);
} catch (InvalidArgumentException $e) {
} catch (NotNormalizableValueException $e) {

@dunglas dunglas May 31, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soyuka, I've found this bug while adding an unit test. Can you check that it's correct please?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes I used the normalize signature to find the exception. This is indeed correct.

throw new InvalidIdentifierException($e->getMessage(), $e->getCode(), $e);
}
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}
11 changes: 10 additions & 1 deletion src/Identifier/Normalizer/IntegerDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
namespace ApiPlatform\Core\Identifier\Normalizer;

use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

final class IntegerDenormalizer implements DenormalizerInterface
final class IntegerDenormalizer implements DenormalizerInterface, CacheableSupportsMethodInterface
{
public function denormalize($data, $class, $format = null, array $context = []): int
{
Expand All @@ -30,4 +31,12 @@ public function supportsDenormalization($data, $type, $format = null): bool
{
return Type::BUILTIN_TYPE_INT === $type && \is_string($data);
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}
11 changes: 10 additions & 1 deletion src/JsonApi/Serializer/ConstraintViolationListNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\ConstraintViolationListInterface;
Expand All @@ -24,7 +25,7 @@
*
* @author Héctor Hurtarte <hectorh30@gmail.com>
*/
final class ConstraintViolationListNormalizer implements NormalizerInterface
final class ConstraintViolationListNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
{
const FORMAT = 'jsonapi';

Expand Down Expand Up @@ -60,6 +61,14 @@ public function supportsNormalization($data, $format = null)
return self::FORMAT === $format && $data instanceof ConstraintViolationListInterface;
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return true;
}

private function getSourcePointerFromViolation(ConstraintViolationInterface $violation)
{
$fieldName = $violation->getPropertyPath();
Expand Down
11 changes: 10 additions & 1 deletion src/JsonApi/Serializer/EntrypointNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use ApiPlatform\Core\Api\UrlGeneratorInterface;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
Expand All @@ -26,7 +27,7 @@
* @author Amrouche Hamza <hamza.simperfit@gmail.com>
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class EntrypointNormalizer implements NormalizerInterface
final class EntrypointNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
{
const FORMAT = 'jsonapi';

Expand Down Expand Up @@ -72,4 +73,12 @@ public function supportsNormalization($data, $format = null)
{
return self::FORMAT === $format && $data instanceof Entrypoint;
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}
11 changes: 10 additions & 1 deletion src/JsonApi/Serializer/ErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

use ApiPlatform\Core\Problem\Serializer\ErrorNormalizerTrait;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Converts {@see \Exception} or {@see \Symfony\Component\Debug\Exception\FlattenException} to a JSON API error representation.
*
* @author Héctor Hurtarte <hectorh30@gmail.com>
*/
final class ErrorNormalizer implements NormalizerInterface
final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
{
use ErrorNormalizerTrait;

Expand Down Expand Up @@ -56,4 +57,12 @@ public function supportsNormalization($data, $format = null)
{
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}
Loading