-
Notifications
You must be signed in to change notification settings - Fork 381
/
ChainLoaderFactory.php
66 lines (58 loc) · 1.77 KB
/
ChainLoaderFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Liip\ImagineBundle\DependencyInjection\Factory\Loader;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
class ChainLoaderFactory extends AbstractLoaderFactory
{
/**
* {@inheritdoc}
*/
public function create(ContainerBuilder $container, $loaderName, array $config): string
{
$definition = $this->getChildLoaderDefinition();
$definition->replaceArgument(0, $this->createLoaderReferences($config['loaders']));
return $this->setTaggedLoaderDefinition($loaderName, $definition, $container);
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'chain';
}
/**
* {@inheritdoc}
*/
public function addConfiguration(ArrayNodeDefinition $builder): void
{
$builder
->children()
->arrayNode('loaders')
->isRequired()
->prototype('scalar')
->cannotBeEmpty()
->end()
->end()
->end();
}
/**
* @param string[] $loaders
*
* @return string[]
*/
private function createLoaderReferences(array $loaders): array
{
return array_combine($loaders, array_map(function ($name) {
return new Reference(sprintf('liip_imagine.binary.loader.%s', $name));
}, $loaders));
}
}