[Serializer] Remove last deprecated/obsolete paths
This commit is contained in:
parent
e281087fd7
commit
c703b355b8
@ -423,6 +423,7 @@ Serializer
|
||||
|
||||
were removed, use the default context instead.
|
||||
* The `AbstractNormalizer::handleCircularReference()` method has two new `$format` and `$context` arguments.
|
||||
* Removed support for instantiating a `DataUriNormalizer` with a default MIME type guesser when the `symfony/mime` component isn't installed.
|
||||
|
||||
Translation
|
||||
-----------
|
||||
|
@ -93,9 +93,6 @@ use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||
use Symfony\Component\Serializer\Encoder\DecoderInterface;
|
||||
use Symfony\Component\Serializer\Encoder\EncoderInterface;
|
||||
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
|
||||
use Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
@ -1280,19 +1277,6 @@ class FrameworkExtension extends Extension
|
||||
{
|
||||
$loader->load('serializer.xml');
|
||||
|
||||
if (!class_exists(DateIntervalNormalizer::class)) {
|
||||
$container->removeDefinition('serializer.normalizer.dateinterval');
|
||||
}
|
||||
|
||||
if (!class_exists(ConstraintViolationListNormalizer::class)) {
|
||||
$container->removeDefinition('serializer.normalizer.constraint_violation_list');
|
||||
}
|
||||
|
||||
if (!class_exists(ClassDiscriminatorFromClassMetadata::class)) {
|
||||
$container->removeAlias('Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface');
|
||||
$container->removeDefinition('serializer.mapping.class_discriminator_resolver');
|
||||
}
|
||||
|
||||
$chainLoader = $container->getDefinition('serializer.mapping.chain_loader');
|
||||
|
||||
if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccessor')) {
|
||||
|
@ -15,7 +15,6 @@ use Symfony\Bundle\FrameworkBundle\CacheWarmer\SerializerCacheWarmer;
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
||||
use Symfony\Component\Cache\Adapter\NullAdapter;
|
||||
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
|
||||
|
||||
@ -23,10 +22,6 @@ class SerializerCacheWarmerTest extends TestCase
|
||||
{
|
||||
public function testWarmUp()
|
||||
{
|
||||
if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
|
||||
$this->markTestSkipped('The Serializer default cache warmer has been introduced in the Serializer Component version 3.2.');
|
||||
}
|
||||
|
||||
$loaders = [
|
||||
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
|
||||
new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
|
||||
@ -48,10 +43,6 @@ class SerializerCacheWarmerTest extends TestCase
|
||||
|
||||
public function testWarmUpWithoutLoader()
|
||||
{
|
||||
if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
|
||||
$this->markTestSkipped('The Serializer default cache warmer has been introduced in the Serializer Component version 3.2.');
|
||||
}
|
||||
|
||||
$file = sys_get_temp_dir().'/cache-serializer-without-loader.php';
|
||||
@unlink($file);
|
||||
|
||||
|
@ -1033,10 +1033,6 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
|
||||
public function testDateIntervalNormalizerRegistered()
|
||||
{
|
||||
if (!class_exists(DateIntervalNormalizer::class)) {
|
||||
$this->markTestSkipped('The DateIntervalNormalizer has been introduced in the Serializer Component version 3.4.');
|
||||
}
|
||||
|
||||
$container = $this->createContainerFromFile('full');
|
||||
|
||||
$definition = $container->getDefinition('serializer.normalizer.dateinterval');
|
||||
|
@ -16,6 +16,7 @@ CHANGELOG
|
||||
use the default context instead.
|
||||
* removed `XmlEncoder::setRootNodeName()` & `XmlEncoder::getRootNodeName()`, use the default context instead.
|
||||
* removed individual encoders/normalizers options as constructor arguments.
|
||||
* removed support for instantiating a `DataUriNormalizer` with a default MIME type guesser when the `symfony/mime` component isn't installed.
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
@ -40,22 +40,8 @@ class JsonDecode implements DecoderInterface
|
||||
self::RECURSION_DEPTH => 512,
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructs a new JsonDecode instance.
|
||||
*
|
||||
* @param array $defaultContext
|
||||
*/
|
||||
public function __construct($defaultContext = [], int $depth = 512)
|
||||
public function __construct(array $defaultContext = [])
|
||||
{
|
||||
if (!\is_array($defaultContext)) {
|
||||
@trigger_error(sprintf('Using constructor parameters that are not a default context is deprecated since Symfony 4.2, use the "%s" and "%s" keys of the context instead.', self::ASSOCIATIVE, self::RECURSION_DEPTH), E_USER_DEPRECATED);
|
||||
|
||||
$defaultContext = [
|
||||
self::ASSOCIATIVE => (bool) $defaultContext,
|
||||
self::RECURSION_DEPTH => $depth,
|
||||
];
|
||||
}
|
||||
|
||||
$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
|
||||
}
|
||||
|
||||
|
@ -26,18 +26,9 @@ class JsonEncode implements EncoderInterface
|
||||
self::OPTIONS => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array $defaultContext
|
||||
*/
|
||||
public function __construct($defaultContext = [])
|
||||
public function __construct(array $defaultContext = [])
|
||||
{
|
||||
if (!\is_array($defaultContext)) {
|
||||
@trigger_error(sprintf('Passing an integer as first parameter of the "%s()" method is deprecated since Symfony 4.2, use the "json_encode_options" key of the context instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->defaultContext[self::OPTIONS] = (int) $defaultContext;
|
||||
} else {
|
||||
$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
|
||||
}
|
||||
$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,24 +203,14 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
* If a circular reference handler is set, it will be called. Otherwise, a
|
||||
* {@class CircularReferenceException} will be thrown.
|
||||
*
|
||||
* @final since Symfony 4.2
|
||||
*
|
||||
* @param object $object
|
||||
* @param string|null $format
|
||||
* @param array $context
|
||||
* @final
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws CircularReferenceException
|
||||
*/
|
||||
protected function handleCircularReference($object/*, string $format = null, array $context = []*/)
|
||||
protected function handleCircularReference(object $object, string $format = null, array $context = [])
|
||||
{
|
||||
if (\func_num_args() < 2 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
|
||||
@trigger_error(sprintf('The "%s()" method will have two new "string $format = null" and "array $context = []" arguments in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
$format = \func_num_args() > 1 ? func_get_arg(1) : null;
|
||||
$context = \func_num_args() > 2 ? func_get_arg(2) : [];
|
||||
|
||||
$circularReferenceHandler = $context[self::CIRCULAR_REFERENCE_HANDLER] ?? $this->defaultContext[self::CIRCULAR_REFERENCE_HANDLER];
|
||||
if ($circularReferenceHandler) {
|
||||
return $circularReferenceHandler($object, $format, $context);
|
||||
@ -450,20 +440,10 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parentContext
|
||||
* @param string $attribute Attribute name
|
||||
* @param string|null $format
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
protected function createChildContext(array $parentContext, $attribute/*, ?string $format */)
|
||||
protected function createChildContext(array $parentContext, string $attribute, ?string $format): array
|
||||
{
|
||||
if (\func_num_args() < 3) {
|
||||
@trigger_error(sprintf('Method "%s::%s()" will have a third "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED);
|
||||
$format = null;
|
||||
}
|
||||
if (isset($parentContext[self::ATTRIBUTES][$attribute])) {
|
||||
$parentContext[self::ATTRIBUTES] = $parentContext[self::ATTRIBUTES][$attribute];
|
||||
} else {
|
||||
|
@ -540,18 +540,9 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
||||
* We must not mix up the attribute cache between parent and children.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param string|null $format
|
||||
*/
|
||||
protected function createChildContext(array $parentContext, $attribute/*, ?string $format */)
|
||||
protected function createChildContext(array $parentContext, string $attribute, ?string $format): array
|
||||
{
|
||||
if (\func_num_args() >= 3) {
|
||||
$format = \func_get_arg(2);
|
||||
} else {
|
||||
@trigger_error(sprintf('Method "%s::%s()" will have a third "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED);
|
||||
$format = null;
|
||||
}
|
||||
|
||||
$context = parent::createChildContext($parentContext, $attribute, $format);
|
||||
$context['cache_key'] = $this->getCacheKey($format, $context);
|
||||
|
||||
|
@ -12,8 +12,6 @@
|
||||
namespace Symfony\Component\Serializer\Normalizer;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface as DeprecatedMimeTypeGuesserInterface;
|
||||
use Symfony\Component\Mime\MimeTypeGuesserInterface;
|
||||
use Symfony\Component\Mime\MimeTypes;
|
||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||
@ -38,22 +36,10 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
||||
*/
|
||||
private $mimeTypeGuesser;
|
||||
|
||||
/**
|
||||
* @param MimeTypeGuesserInterface|null $mimeTypeGuesser
|
||||
*/
|
||||
public function __construct($mimeTypeGuesser = null)
|
||||
public function __construct(MimeTypeGuesserInterface $mimeTypeGuesser = null)
|
||||
{
|
||||
if ($mimeTypeGuesser instanceof DeprecatedMimeTypeGuesserInterface) {
|
||||
@trigger_error(sprintf('Passing a %s to "%s()" is deprecated since Symfony 4.3, pass a "%s" instead.', DeprecatedMimeTypeGuesserInterface::class, __METHOD__, MimeTypeGuesserInterface::class), E_USER_DEPRECATED);
|
||||
} elseif (null === $mimeTypeGuesser) {
|
||||
if (class_exists(MimeTypes::class)) {
|
||||
$mimeTypeGuesser = MimeTypes::getDefault();
|
||||
} elseif (class_exists(MimeTypeGuesser::class)) {
|
||||
@trigger_error(sprintf('Passing null to "%s()" to use a default MIME type guesser without Symfony Mime installed is deprecated since Symfony 4.3. Try running "composer require symfony/mime".', __METHOD__), E_USER_DEPRECATED);
|
||||
$mimeTypeGuesser = MimeTypeGuesser::getInstance();
|
||||
}
|
||||
} elseif (!$mimeTypeGuesser instanceof MimeTypes) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be an instance of "%s" or null, %s given.', __METHOD__, MimeTypes::class, \is_object($mimeTypeGuesser) ? \get_class($mimeTypeGuesser) : \gettype($mimeTypeGuesser)));
|
||||
if (!$mimeTypeGuesser && class_exists(MimeTypes::class)) {
|
||||
$mimeTypeGuesser = MimeTypes::getDefault();
|
||||
}
|
||||
|
||||
$this->mimeTypeGuesser = $mimeTypeGuesser;
|
||||
@ -112,6 +98,10 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
||||
try {
|
||||
switch ($class) {
|
||||
case 'Symfony\Component\HttpFoundation\File\File':
|
||||
if (!class_exists(File::class)) {
|
||||
throw new InvalidArgumentException(sprintf('Cannot denormalize to a "%s" without the HttpFoundation component installed. Try running "composer require symfony/http-foundation".', File::class));
|
||||
}
|
||||
|
||||
return new File($data, false);
|
||||
|
||||
case 'SplFileObject':
|
||||
@ -154,10 +144,6 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
||||
return $object->getMimeType();
|
||||
}
|
||||
|
||||
if ($this->mimeTypeGuesser instanceof DeprecatedMimeTypeGuesserInterface && $mimeType = $this->mimeTypeGuesser->guess($object->getPathname())) {
|
||||
return $mimeType;
|
||||
}
|
||||
|
||||
if ($this->mimeTypeGuesser && $mimeType = $this->mimeTypeGuesser->guessMimeType($object->getPathname())) {
|
||||
return $mimeType;
|
||||
}
|
||||
|
@ -56,12 +56,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
||||
*/
|
||||
protected $decoder;
|
||||
|
||||
/**
|
||||
* @internal since Symfony 4.1
|
||||
*/
|
||||
protected $normalizers = [];
|
||||
|
||||
private $cachedNormalizers;
|
||||
private $normalizers = [];
|
||||
private $denormalizerCache = [];
|
||||
private $normalizerCache = [];
|
||||
|
||||
@ -220,10 +215,6 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
||||
*/
|
||||
private function getNormalizer($data, ?string $format, array $context)
|
||||
{
|
||||
if ($this->cachedNormalizers !== $this->normalizers) {
|
||||
$this->cachedNormalizers = $this->normalizers;
|
||||
$this->denormalizerCache = $this->normalizerCache = [];
|
||||
}
|
||||
$type = \is_object($data) ? \get_class($data) : 'native-'.\gettype($data);
|
||||
|
||||
if (!isset($this->normalizerCache[$format][$type])) {
|
||||
@ -263,10 +254,6 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
||||
*/
|
||||
private function getDenormalizer($data, string $class, ?string $format, array $context)
|
||||
{
|
||||
if ($this->cachedNormalizers !== $this->normalizers) {
|
||||
$this->cachedNormalizers = $this->normalizers;
|
||||
$this->denormalizerCache = $this->normalizerCache = [];
|
||||
}
|
||||
if (!isset($this->denormalizerCache[$format][$class])) {
|
||||
$this->denormalizerCache[$format][$class] = [];
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
"symfony/config": "^4.4|^5.0",
|
||||
"symfony/property-access": "^4.4|^5.0",
|
||||
"symfony/http-foundation": "^4.4|^5.0",
|
||||
"symfony/mime": "^4.4|^5.0",
|
||||
"symfony/cache": "^4.4|^5.0",
|
||||
"symfony/property-info": "^4.4|^5.0",
|
||||
"symfony/validator": "^4.4|^5.0",
|
||||
@ -45,7 +46,7 @@
|
||||
"symfony/yaml": "For using the default YAML mapping loader.",
|
||||
"symfony/config": "For using the XML mapping loader.",
|
||||
"symfony/property-access": "For using the ObjectNormalizer.",
|
||||
"symfony/http-foundation": "For using a MIME type guesser within the DataUriNormalizer.",
|
||||
"symfony/mime": "For using a MIME type guesser within the DataUriNormalizer.",
|
||||
"doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.",
|
||||
"doctrine/cache": "For using the default cached annotation reader and metadata cache."
|
||||
},
|
||||
|
Reference in New Issue
Block a user