mirror of
https://github.com/AzuraCast/AzuraCast.git
synced 2024-06-14 21:26:37 +00:00
Update Symfony Validator/Serializer component definitions.
This commit is contained in:
parent
6769b0ce57
commit
4fb7f91604
|
@ -55,7 +55,6 @@ return [
|
|||
// Doctrine Entity Manager
|
||||
App\Doctrine\DecoratedEntityManager::class => function (
|
||||
Doctrine\Common\Cache\Cache $doctrineCache,
|
||||
Doctrine\Common\Annotations\Reader $reader,
|
||||
Environment $environment,
|
||||
App\Doctrine\Event\StationRequiresRestart $eventRequiresRestart,
|
||||
App\Doctrine\Event\AuditLog $eventAuditLog,
|
||||
|
@ -170,13 +169,13 @@ return [
|
|||
// Doctrine cache
|
||||
Doctrine\Common\Cache\Cache::class => function (
|
||||
Environment $environment,
|
||||
Psr\Cache\CacheItemPoolInterface $cachePool
|
||||
Psr\Cache\CacheItemPoolInterface $psr6Cache
|
||||
) {
|
||||
if ($environment->isCli()) {
|
||||
$cachePool = new Symfony\Component\Cache\Adapter\ArrayAdapter();
|
||||
$psr6Cache = new Symfony\Component\Cache\Adapter\ArrayAdapter();
|
||||
}
|
||||
|
||||
$doctrineCache = new Symfony\Component\Cache\DoctrineProvider($cachePool);
|
||||
$doctrineCache = Doctrine\Common\Cache\Psr6\DoctrineProvider::wrap($psr6Cache);
|
||||
$doctrineCache->setNamespace('doctrine.');
|
||||
return $doctrineCache;
|
||||
},
|
||||
|
@ -263,29 +262,29 @@ return [
|
|||
|
||||
// Doctrine annotations reader
|
||||
Doctrine\Common\Annotations\Reader::class => function (
|
||||
Doctrine\Common\Cache\Cache $doctrine_cache,
|
||||
Psr\Cache\CacheItemPoolInterface $psr6Cache,
|
||||
Environment $settings
|
||||
) {
|
||||
return new Doctrine\Common\Annotations\CachedReader(
|
||||
return new Doctrine\Common\Annotations\PsrCachedReader(
|
||||
new Doctrine\Common\Annotations\AnnotationReader,
|
||||
$doctrine_cache,
|
||||
$psr6Cache,
|
||||
!$settings->isProduction()
|
||||
);
|
||||
},
|
||||
|
||||
// Symfony Serializer
|
||||
Symfony\Component\Serializer\Serializer::class => function (
|
||||
Doctrine\Common\Annotations\Reader $annotation_reader,
|
||||
Doctrine\Common\Annotations\Reader $reader,
|
||||
Doctrine\ORM\EntityManagerInterface $em
|
||||
) {
|
||||
$meta_factory = new Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory(
|
||||
new Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader($annotation_reader)
|
||||
$classMetaFactory = new Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory(
|
||||
new Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader($reader)
|
||||
);
|
||||
|
||||
$normalizers = [
|
||||
new Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer(),
|
||||
new App\Normalizer\DoctrineEntityNormalizer($em, $annotation_reader, $meta_factory),
|
||||
new Symfony\Component\Serializer\Normalizer\ObjectNormalizer($meta_factory),
|
||||
new App\Normalizer\DoctrineEntityNormalizer($em, $classMetaFactory),
|
||||
new Symfony\Component\Serializer\Normalizer\ObjectNormalizer($classMetaFactory),
|
||||
];
|
||||
$encoders = [
|
||||
new Symfony\Component\Serializer\Encoder\JsonEncoder,
|
||||
|
@ -295,17 +294,13 @@ return [
|
|||
},
|
||||
|
||||
// Symfony Validator
|
||||
Symfony\Component\Validator\ConstraintValidatorFactoryInterface::class => DI\autowire(
|
||||
App\Validator\ConstraintValidatorFactory::class
|
||||
),
|
||||
|
||||
Symfony\Component\Validator\Validator\ValidatorInterface::class => function (
|
||||
Doctrine\Common\Annotations\Reader $annotation_reader,
|
||||
Symfony\Component\Validator\ConstraintValidatorFactoryInterface $cvf
|
||||
Doctrine\Common\Annotations\Reader $reader,
|
||||
Symfony\Component\Validator\ContainerConstraintValidatorFactory $constraintValidatorFactory
|
||||
) {
|
||||
$builder = new Symfony\Component\Validator\ValidatorBuilder();
|
||||
$builder->setConstraintValidatorFactory($cvf);
|
||||
$builder->enableAnnotationMapping($annotation_reader);
|
||||
$builder->setConstraintValidatorFactory($constraintValidatorFactory);
|
||||
$builder->enableAnnotationMapping($reader);
|
||||
return $builder->getValidator();
|
||||
},
|
||||
|
||||
|
|
|
@ -5,12 +5,10 @@ namespace App\Normalizer;
|
|||
use App\Exception\NoGetterAvailableException;
|
||||
use App\Normalizer\Attributes\DeepNormalize;
|
||||
use DateTime;
|
||||
use Doctrine\Common\Annotations\Reader;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Inflector\Inflector;
|
||||
use Doctrine\Inflector\InflectorFactory;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
|
||||
use Doctrine\ORM\Proxy\Proxy;
|
||||
use InvalidArgumentException;
|
||||
use ProxyManager\Proxy\GhostObjectInterface;
|
||||
|
@ -20,9 +18,7 @@ use ReflectionNamedType;
|
|||
use ReflectionProperty;
|
||||
use ReflectionUnionType;
|
||||
use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
|
||||
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
|
@ -44,30 +40,17 @@ class DoctrineEntityNormalizer extends AbstractNormalizer
|
|||
/** @var SerializerInterface|NormalizerInterface|DenormalizerInterface */
|
||||
protected $serializer;
|
||||
|
||||
protected Reader $annotationReader;
|
||||
|
||||
protected Inflector $inflector;
|
||||
|
||||
public function __construct(
|
||||
protected EntityManagerInterface $em,
|
||||
Reader $annotationReader = null,
|
||||
ClassMetadataFactoryInterface $classMetadataFactory = null,
|
||||
NameConverterInterface $nameConverter = null,
|
||||
array $defaultContext = []
|
||||
) {
|
||||
/** @var AnnotationDriver $metadata_driver */
|
||||
$metadata_driver = $em->getConfiguration()->getMetadataDriverImpl();
|
||||
|
||||
$annotationReader = $annotationReader ?? $metadata_driver->getReader();
|
||||
$classMetadataFactory = $classMetadataFactory ?? new ClassMetadataFactory(
|
||||
new AnnotationLoader($annotationReader)
|
||||
);
|
||||
|
||||
$defaultContext[self::ALLOW_EXTRA_ATTRIBUTES] = false;
|
||||
|
||||
parent::__construct($classMetadataFactory, $nameConverter, $defaultContext);
|
||||
|
||||
$this->annotationReader = $annotationReader;
|
||||
$this->inflector = InflectorFactory::create()->build();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Validator;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints\ExpressionValidator;
|
||||
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
|
||||
|
||||
class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
|
||||
{
|
||||
protected array $validators = [];
|
||||
|
||||
public function __construct(
|
||||
protected ContainerInterface $container
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInstance(Constraint $constraint)
|
||||
{
|
||||
$className = $constraint->validatedBy();
|
||||
|
||||
if (!isset($this->validators[$className])) {
|
||||
if ('validator.expression' === $className) {
|
||||
$this->validators[$className] = new ExpressionValidator();
|
||||
} elseif ($this->container->has($className)) {
|
||||
$this->validators[$className] = $this->container->get($className);
|
||||
} else {
|
||||
$this->validators[$className] = new $className();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->validators[$className];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user