Ajout des vendor
This commit is contained in:
89
vendor/symfony/framework-bundle/CacheWarmer/AbstractPhpFileCacheWarmer.php
vendored
Normal file
89
vendor/symfony/framework-bundle/CacheWarmer/AbstractPhpFileCacheWarmer.php
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
||||
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Cache\Adapter\NullAdapter;
|
||||
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
||||
use Symfony\Component\Config\Resource\ClassExistenceResource;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
||||
|
||||
abstract class AbstractPhpFileCacheWarmer implements CacheWarmerInterface
|
||||
{
|
||||
private $phpArrayFile;
|
||||
|
||||
/**
|
||||
* @param string $phpArrayFile The PHP file where metadata are cached
|
||||
*/
|
||||
public function __construct(string $phpArrayFile)
|
||||
{
|
||||
$this->phpArrayFile = $phpArrayFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isOptional()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return string[] A list of classes to preload on PHP 7.4+
|
||||
*/
|
||||
public function warmUp(string $cacheDir)
|
||||
{
|
||||
$arrayAdapter = new ArrayAdapter();
|
||||
|
||||
spl_autoload_register([ClassExistenceResource::class, 'throwOnRequiredClass']);
|
||||
try {
|
||||
if (!$this->doWarmUp($cacheDir, $arrayAdapter)) {
|
||||
return [];
|
||||
}
|
||||
} finally {
|
||||
spl_autoload_unregister([ClassExistenceResource::class, 'throwOnRequiredClass']);
|
||||
}
|
||||
|
||||
// the ArrayAdapter stores the values serialized
|
||||
// to avoid mutation of the data after it was written to the cache
|
||||
// so here we un-serialize the values first
|
||||
$values = array_map(function ($val) { return null !== $val ? unserialize($val) : null; }, $arrayAdapter->getValues());
|
||||
|
||||
return $this->warmUpPhpArrayAdapter(new PhpArrayAdapter($this->phpArrayFile, new NullAdapter()), $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] A list of classes to preload on PHP 7.4+
|
||||
*/
|
||||
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
|
||||
{
|
||||
return (array) $phpArrayAdapter->warmUp($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final protected function ignoreAutoloadException(string $class, \Exception $exception): void
|
||||
{
|
||||
try {
|
||||
ClassExistenceResource::throwOnRequiredClass($class, $exception);
|
||||
} catch (\ReflectionException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool false if there is nothing to warm-up
|
||||
*/
|
||||
abstract protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter);
|
||||
}
|
113
vendor/symfony/framework-bundle/CacheWarmer/AnnotationsCacheWarmer.php
vendored
Normal file
113
vendor/symfony/framework-bundle/CacheWarmer/AnnotationsCacheWarmer.php
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationException;
|
||||
use Doctrine\Common\Annotations\PsrCachedReader;
|
||||
use Doctrine\Common\Annotations\Reader;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
||||
|
||||
/**
|
||||
* Warms up annotation caches for classes found in composer's autoload class map
|
||||
* and declared in DI bundle extensions using the addAnnotatedClassesToCache method.
|
||||
*
|
||||
* @author Titouan Galopin <galopintitouan@gmail.com>
|
||||
*/
|
||||
class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer
|
||||
{
|
||||
private $annotationReader;
|
||||
private $excludeRegexp;
|
||||
private $debug;
|
||||
|
||||
/**
|
||||
* @param string $phpArrayFile The PHP file where annotations are cached
|
||||
*/
|
||||
public function __construct(Reader $annotationReader, string $phpArrayFile, string $excludeRegexp = null, bool $debug = false)
|
||||
{
|
||||
parent::__construct($phpArrayFile);
|
||||
$this->annotationReader = $annotationReader;
|
||||
$this->excludeRegexp = $excludeRegexp;
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
|
||||
{
|
||||
$annotatedClassPatterns = $cacheDir.'/annotations.map';
|
||||
|
||||
if (!is_file($annotatedClassPatterns)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$annotatedClasses = include $annotatedClassPatterns;
|
||||
$reader = new PsrCachedReader($this->annotationReader, $arrayAdapter, $this->debug);
|
||||
|
||||
foreach ($annotatedClasses as $class) {
|
||||
if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$this->readAllComponents($reader, $class);
|
||||
} catch (\Exception $e) {
|
||||
$this->ignoreAutoloadException($class, $e);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] A list of classes to preload on PHP 7.4+
|
||||
*/
|
||||
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
|
||||
{
|
||||
// make sure we don't cache null values
|
||||
$values = array_filter($values, function ($val) { return null !== $val; });
|
||||
|
||||
return parent::warmUpPhpArrayAdapter($phpArrayAdapter, $values);
|
||||
}
|
||||
|
||||
private function readAllComponents(Reader $reader, string $class)
|
||||
{
|
||||
$reflectionClass = new \ReflectionClass($class);
|
||||
|
||||
try {
|
||||
$reader->getClassAnnotations($reflectionClass);
|
||||
} catch (AnnotationException $e) {
|
||||
/*
|
||||
* Ignore any AnnotationException to not break the cache warming process if an Annotation is badly
|
||||
* configured or could not be found / read / etc.
|
||||
*
|
||||
* In particular cases, an Annotation in your code can be used and defined only for a specific
|
||||
* environment but is always added to the annotations.map file by some Symfony default behaviors,
|
||||
* and you always end up with a not found Annotation.
|
||||
*/
|
||||
}
|
||||
|
||||
foreach ($reflectionClass->getMethods() as $reflectionMethod) {
|
||||
try {
|
||||
$reader->getMethodAnnotations($reflectionMethod);
|
||||
} catch (AnnotationException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($reflectionClass->getProperties() as $reflectionProperty) {
|
||||
try {
|
||||
$reader->getPropertyAnnotations($reflectionProperty);
|
||||
} catch (AnnotationException $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
64
vendor/symfony/framework-bundle/CacheWarmer/CachePoolClearerCacheWarmer.php
vendored
Normal file
64
vendor/symfony/framework-bundle/CacheWarmer/CachePoolClearerCacheWarmer.php
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
||||
|
||||
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
||||
|
||||
/**
|
||||
* Clears the cache pools when warming up the cache.
|
||||
*
|
||||
* Do not use in production!
|
||||
*
|
||||
* @author Teoh Han Hui <teohhanhui@gmail.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class CachePoolClearerCacheWarmer implements CacheWarmerInterface
|
||||
{
|
||||
private $poolClearer;
|
||||
private $pools;
|
||||
|
||||
/**
|
||||
* @param string[] $pools
|
||||
*/
|
||||
public function __construct(Psr6CacheClearer $poolClearer, array $pools = [])
|
||||
{
|
||||
$this->poolClearer = $poolClearer;
|
||||
$this->pools = $pools;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function warmUp(string $cacheDirectory): array
|
||||
{
|
||||
foreach ($this->pools as $pool) {
|
||||
if ($this->poolClearer->hasPool($pool)) {
|
||||
$this->poolClearer->clearPool($pool);
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isOptional(): bool
|
||||
{
|
||||
// optional cache warmers are not run when handling the request
|
||||
return false;
|
||||
}
|
||||
}
|
91
vendor/symfony/framework-bundle/CacheWarmer/ConfigBuilderCacheWarmer.php
vendored
Normal file
91
vendor/symfony/framework-bundle/CacheWarmer/ConfigBuilderCacheWarmer.php
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Config\Builder\ConfigBuilderGenerator;
|
||||
use Symfony\Component\Config\Builder\ConfigBuilderGeneratorInterface;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
/**
|
||||
* Generate all config builders.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class ConfigBuilderCacheWarmer implements CacheWarmerInterface
|
||||
{
|
||||
private $kernel;
|
||||
private $logger;
|
||||
|
||||
public function __construct(KernelInterface $kernel, LoggerInterface $logger = null)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function warmUp(string $cacheDir)
|
||||
{
|
||||
$generator = new ConfigBuilderGenerator($cacheDir);
|
||||
|
||||
foreach ($this->kernel->getBundles() as $bundle) {
|
||||
$extension = $bundle->getContainerExtension();
|
||||
if (null === $extension) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->dumpExtension($extension, $generator);
|
||||
} catch (\Exception $e) {
|
||||
if ($this->logger) {
|
||||
$this->logger->warning('Failed to generate ConfigBuilder for extension {extensionClass}.', ['exception' => $e, 'extensionClass' => \get_class($extension)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No need to preload anything
|
||||
return [];
|
||||
}
|
||||
|
||||
private function dumpExtension(ExtensionInterface $extension, ConfigBuilderGeneratorInterface $generator): void
|
||||
{
|
||||
$configuration = null;
|
||||
if ($extension instanceof ConfigurationInterface) {
|
||||
$configuration = $extension;
|
||||
} elseif ($extension instanceof ConfigurationExtensionInterface) {
|
||||
$configuration = $extension->getConfiguration([], new ContainerBuilder($this->kernel->getContainer()->getParameterBag()));
|
||||
}
|
||||
|
||||
if (!$configuration) {
|
||||
return;
|
||||
}
|
||||
|
||||
$generator->build($configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isOptional()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
68
vendor/symfony/framework-bundle/CacheWarmer/RouterCacheWarmer.php
vendored
Normal file
68
vendor/symfony/framework-bundle/CacheWarmer/RouterCacheWarmer.php
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
|
||||
/**
|
||||
* Generates the router matcher and generator classes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class RouterCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
// As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected.
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function warmUp(string $cacheDir): array
|
||||
{
|
||||
$router = $this->container->get('router');
|
||||
|
||||
if ($router instanceof WarmableInterface) {
|
||||
return (array) $router->warmUp($cacheDir);
|
||||
}
|
||||
|
||||
throw new \LogicException(sprintf('The router "%s" cannot be warmed up because it does not implement "%s".', get_debug_type($router), WarmableInterface::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isOptional(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedServices(): array
|
||||
{
|
||||
return [
|
||||
'router' => RouterInterface::class,
|
||||
];
|
||||
}
|
||||
}
|
87
vendor/symfony/framework-bundle/CacheWarmer/SerializerCacheWarmer.php
vendored
Normal file
87
vendor/symfony/framework-bundle/CacheWarmer/SerializerCacheWarmer.php
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationException;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\LoaderChain;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
|
||||
|
||||
/**
|
||||
* Warms up XML and YAML serializer metadata.
|
||||
*
|
||||
* @author Titouan Galopin <galopintitouan@gmail.com>
|
||||
*/
|
||||
class SerializerCacheWarmer extends AbstractPhpFileCacheWarmer
|
||||
{
|
||||
private $loaders;
|
||||
|
||||
/**
|
||||
* @param LoaderInterface[] $loaders The serializer metadata loaders
|
||||
* @param string $phpArrayFile The PHP file where metadata are cached
|
||||
*/
|
||||
public function __construct(array $loaders, string $phpArrayFile)
|
||||
{
|
||||
parent::__construct($phpArrayFile);
|
||||
$this->loaders = $loaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
|
||||
{
|
||||
if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$metadataFactory = new CacheClassMetadataFactory(new ClassMetadataFactory(new LoaderChain($this->loaders)), $arrayAdapter);
|
||||
|
||||
foreach ($this->extractSupportedLoaders($this->loaders) as $loader) {
|
||||
foreach ($loader->getMappedClasses() as $mappedClass) {
|
||||
try {
|
||||
$metadataFactory->getMetadataFor($mappedClass);
|
||||
} catch (AnnotationException $e) {
|
||||
// ignore failing annotations
|
||||
} catch (\Exception $e) {
|
||||
$this->ignoreAutoloadException($mappedClass, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoaderInterface[] $loaders
|
||||
*
|
||||
* @return XmlFileLoader[]|YamlFileLoader[]
|
||||
*/
|
||||
private function extractSupportedLoaders(array $loaders): array
|
||||
{
|
||||
$supportedLoaders = [];
|
||||
|
||||
foreach ($loaders as $loader) {
|
||||
if ($loader instanceof XmlFileLoader || $loader instanceof YamlFileLoader) {
|
||||
$supportedLoaders[] = $loader;
|
||||
} elseif ($loader instanceof LoaderChain) {
|
||||
$supportedLoaders = array_merge($supportedLoaders, $this->extractSupportedLoaders($loader->getLoaders()));
|
||||
}
|
||||
}
|
||||
|
||||
return $supportedLoaders;
|
||||
}
|
||||
}
|
71
vendor/symfony/framework-bundle/CacheWarmer/TranslationsCacheWarmer.php
vendored
Normal file
71
vendor/symfony/framework-bundle/CacheWarmer/TranslationsCacheWarmer.php
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* Generates the catalogues for translations.
|
||||
*
|
||||
* @author Xavier Leune <xavier.leune@gmail.com>
|
||||
*/
|
||||
class TranslationsCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface
|
||||
{
|
||||
private $container;
|
||||
private $translator;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
// As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected.
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function warmUp(string $cacheDir)
|
||||
{
|
||||
if (null === $this->translator) {
|
||||
$this->translator = $this->container->get('translator');
|
||||
}
|
||||
|
||||
if ($this->translator instanceof WarmableInterface) {
|
||||
return (array) $this->translator->warmUp($cacheDir);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isOptional()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return [
|
||||
'translator' => TranslatorInterface::class,
|
||||
];
|
||||
}
|
||||
}
|
101
vendor/symfony/framework-bundle/CacheWarmer/ValidatorCacheWarmer.php
vendored
Normal file
101
vendor/symfony/framework-bundle/CacheWarmer/ValidatorCacheWarmer.php
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationException;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
||||
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
|
||||
use Symfony\Component\Validator\Mapping\Loader\LoaderChain;
|
||||
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
|
||||
use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Validator\ValidatorBuilder;
|
||||
|
||||
/**
|
||||
* Warms up XML and YAML validator metadata.
|
||||
*
|
||||
* @author Titouan Galopin <galopintitouan@gmail.com>
|
||||
*/
|
||||
class ValidatorCacheWarmer extends AbstractPhpFileCacheWarmer
|
||||
{
|
||||
private $validatorBuilder;
|
||||
|
||||
/**
|
||||
* @param string $phpArrayFile The PHP file where metadata are cached
|
||||
*/
|
||||
public function __construct(ValidatorBuilder $validatorBuilder, string $phpArrayFile)
|
||||
{
|
||||
parent::__construct($phpArrayFile);
|
||||
$this->validatorBuilder = $validatorBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
|
||||
{
|
||||
if (!method_exists($this->validatorBuilder, 'getLoaders')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$loaders = $this->validatorBuilder->getLoaders();
|
||||
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), $arrayAdapter);
|
||||
|
||||
foreach ($this->extractSupportedLoaders($loaders) as $loader) {
|
||||
foreach ($loader->getMappedClasses() as $mappedClass) {
|
||||
try {
|
||||
if ($metadataFactory->hasMetadataFor($mappedClass)) {
|
||||
$metadataFactory->getMetadataFor($mappedClass);
|
||||
}
|
||||
} catch (AnnotationException $e) {
|
||||
// ignore failing annotations
|
||||
} catch (\Exception $e) {
|
||||
$this->ignoreAutoloadException($mappedClass, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] A list of classes to preload on PHP 7.4+
|
||||
*/
|
||||
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
|
||||
{
|
||||
// make sure we don't cache null values
|
||||
$values = array_filter($values, function ($val) { return null !== $val; });
|
||||
|
||||
return parent::warmUpPhpArrayAdapter($phpArrayAdapter, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoaderInterface[] $loaders
|
||||
*
|
||||
* @return XmlFileLoader[]|YamlFileLoader[]
|
||||
*/
|
||||
private function extractSupportedLoaders(array $loaders): array
|
||||
{
|
||||
$supportedLoaders = [];
|
||||
|
||||
foreach ($loaders as $loader) {
|
||||
if ($loader instanceof XmlFileLoader || $loader instanceof YamlFileLoader) {
|
||||
$supportedLoaders[] = $loader;
|
||||
} elseif ($loader instanceof LoaderChain) {
|
||||
$supportedLoaders = array_merge($supportedLoaders, $this->extractSupportedLoaders($loader->getLoaders()));
|
||||
}
|
||||
}
|
||||
|
||||
return $supportedLoaders;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user