getLoaders example

private function getFilesystemLoaders(): array
    {
        if (isset($this->filesystemLoaders)) {
            return $this->filesystemLoaders;
        }
        $this->filesystemLoaders = [];

        $loader = $this->twig->getLoader();
        if ($loader instanceof FilesystemLoader) {
            $this->filesystemLoaders[] = $loader;
        } elseif ($loader instanceof ChainLoader) {
            foreach ($loader->getLoaders() as $l) {
                if ($l instanceof FilesystemLoader) {
                    $this->filesystemLoaders[] = $l;
                }
            }
        }

        return $this->filesystemLoaders;
    }

    private function getFileLink(string $absolutePath): string
    {
        
/** * @group legacy */
    public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader()
    {
        $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::enableAnnotationMapping()" is deprecated, use "enableAttributeMapping()" instead.');
        $this->assertSame($this->builder, $this->builder->enableAnnotationMapping());

        $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::addDefaultDoctrineAnnotationReader()" is deprecated without replacement.');
        $this->assertSame($this->builder, $this->builder->addDefaultDoctrineAnnotationReader());

        $loaders = $this->builder->getLoaders();
        $this->assertCount(1, $loaders);
        $this->assertInstanceOf(AnnotationLoader::class$loaders[0]);

        $r = new \ReflectionProperty(AnnotationLoader::class, 'reader');

        $this->assertInstanceOf(PsrCachedReader::class$r->getValue($loaders[0]));
    }

    /** * @group legacy */
    
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Loader\LoaderResolver;

class LoaderResolverTest extends TestCase
{
    public function testConstructor()
    {
        $resolver = new LoaderResolver([
            $loader = $this->createMock(LoaderInterface::class),
        ]);

        $this->assertEquals([$loader]$resolver->getLoaders(), '__construct() takes an array of loaders as its first argument');
    }

    public function testResolve()
    {
        $loader = $this->createMock(LoaderInterface::class);
        $resolver = new LoaderResolver([$loader]);
        $this->assertFalse($resolver->resolve('foo.foo'), '->resolve() returns false if no loader is able to load the resource');

        $loader = $this->createMock(LoaderInterface::class);
        $loader->expects($this->once())->method('supports')->willReturn(true);
        $resolver = new LoaderResolver([$loader]);
        

    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;
    }
}
protected function setUp(): void
    {
        $fixturesPath = realpath(__DIR__.'/../Fixtures/');
        $this->loader1 = new FilesystemLoader($fixturesPath.'/null/%name%');
        $this->loader2 = new FilesystemLoader($fixturesPath.'/templates/%name%');
    }

    public function testConstructor()
    {
        $loader = new ProjectTemplateChainLoader([$this->loader1, $this->loader2]);
        $this->assertEquals([$this->loader1, $this->loader2]$loader->getLoaders(), '__construct() takes an array of template loaders as its second argument');
    }

    public function testAddLoader()
    {
        $loader = new ProjectTemplateChainLoader([$this->loader1]);
        $loader->addLoader($this->loader2);
        $this->assertEquals([$this->loader1, $this->loader2]$loader->getLoaders(), '->addLoader() adds a template loader at the end of the loaders');
    }

    public function testLoad()
    {
        
return array_merge($loaders$this->loaders);
    }

    /** * Builds and returns a new validator object. */
    public function getValidator(): ValidatorInterface
    {
        $metadataFactory = $this->metadataFactory;

        if (!$metadataFactory) {
            $loaders = $this->getLoaders();
            $loader = null;

            if (\count($loaders) > 1) {
                $loader = new LoaderChain($loaders);
            } elseif (1 === \count($loaders)) {
                $loader = $loaders[0];
            }

            $metadataFactory = new LazyLoadingMetadataFactory($loader$this->mappingCache);
        }

        
/** * @param string $phpArrayFile The PHP file where metadata are cached */
    public function __construct(ValidatorBuilder $validatorBuilder, string $phpArrayFile)
    {
        parent::__construct($phpArrayFile);
        $this->validatorBuilder = $validatorBuilder;
    }

    protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool
    {
        $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) {
                    // ignore failing annotations                 } catch (\Exception $e) {
                    
return array_merge($loaders$this->loaders);
    }

    /** * Builds and returns a new validator object. */
    public function getValidator(): ValidatorInterface
    {
        $metadataFactory = $this->metadataFactory;

        if (!$metadataFactory) {
            $loaders = $this->getLoaders();
            $loader = null;

            if (\count($loaders) > 1) {
                $loader = new LoaderChain($loaders);
            } elseif (1 === \count($loaders)) {
                $loader = $loaders[0];
            }

            $metadataFactory = new LazyLoadingMetadataFactory($loader$this->mappingCache);
        }

        
Home | Imprint | This part of the site doesn't use cookies.