1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of ocubom/twig-extra-bundle |
5
|
|
|
* |
6
|
|
|
* © Oscar Cubo Medina <https://ocubom.github.io> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ocubom\TwigExtraBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Ocubom\Twig\Extension\HtmlAttributesRuntime; |
15
|
|
|
use Ocubom\Twig\Extension\HtmlCompressRuntime; |
16
|
|
|
use Ocubom\Twig\Extension\HtmlExtension; |
17
|
|
|
use Ocubom\Twig\Extension\Svg\Finder; |
18
|
|
|
use Ocubom\Twig\Extension\Svg\FinderInterface; |
19
|
|
|
use Ocubom\Twig\Extension\SvgExtension; |
20
|
|
|
use Ocubom\Twig\Extension\SvgRuntime; |
21
|
|
|
use Ocubom\TwigExtraBundle\Extensions; |
22
|
|
|
use Ocubom\TwigExtraBundle\Listener\AddHttpHeadersListener; |
23
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
24
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
|
|
|
25
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
26
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
27
|
|
|
|
28
|
|
|
class OcubomTwigExtraExtension extends Extension |
29
|
|
|
{ |
30
|
2 |
|
public function load(array $configs, ContainerBuilder $container): void |
31
|
|
|
{ |
32
|
2 |
|
$configuration = $this->getConfiguration($configs, $container); |
33
|
|
|
assert($configuration instanceof ConfigurationInterface); |
34
|
2 |
|
$config = $this->processConfiguration($configuration, $configs); |
35
|
|
|
|
36
|
2 |
|
foreach (array_keys(Extensions::getClasses()) as $name) { |
37
|
2 |
|
if ($this->isConfigEnabled($container, $config[$name])) { |
38
|
2 |
|
$this->{'registerTwig'.ucfirst($name).'Extension'}($container, $config[$name]); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
2 |
|
$this->registerHttpHeadersListener($container, $config); |
43
|
|
|
} |
44
|
|
|
|
45
|
2 |
|
private function registerTwigHtmlExtension(ContainerBuilder $container, array $config): void |
46
|
|
|
{ |
47
|
2 |
|
if ($config['enabled']) { |
48
|
2 |
|
$container->register('ocubom_twig_extra.extension.html', HtmlExtension::class) |
49
|
2 |
|
->addTag('twig.extension'); |
50
|
|
|
|
51
|
2 |
|
$container->register('ocubom_twig_extra.runtime.html_attributes', HtmlAttributesRuntime::class) |
52
|
2 |
|
->addTag('twig.runtime'); |
53
|
|
|
|
54
|
2 |
|
$container->register('ocubom_twig_extra.runtime.html_compress', HtmlCompressRuntime::class) |
55
|
2 |
|
->setArguments([ |
56
|
2 |
|
$config['compression']['force'], |
57
|
2 |
|
$config['compression']['level'], |
58
|
2 |
|
]) |
59
|
2 |
|
->addTag('twig.runtime'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
2 |
|
private function registerTwigSvgExtension(ContainerBuilder $container, array $config): void |
64
|
|
|
{ |
65
|
2 |
|
if ($config['enabled']) { |
66
|
2 |
|
$container->register('ocubom_twig_extra.extension.svg', SvgExtension::class) |
67
|
2 |
|
->addTag('twig.extension'); |
68
|
|
|
|
69
|
2 |
|
$container->register('ocubom_twig_extra.runtime.svg', SvgRuntime::class) |
70
|
2 |
|
->setArguments([ |
71
|
2 |
|
new Reference('ocubom_twig_extra.service.svg_finder'), |
72
|
2 |
|
new Reference('logger'), |
73
|
2 |
|
]) |
74
|
2 |
|
->addTag('twig.runtime'); |
75
|
|
|
|
76
|
2 |
|
$container->register('ocubom_twig_extra.service.svg_finder', Finder::class) |
77
|
2 |
|
->setArguments($config['search_path']); |
78
|
|
|
|
79
|
2 |
|
$container->setAlias(FinderInterface::class, 'ocubom_twig_extra.service.svg_finder'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
2 |
|
private function registerHttpHeadersListener(ContainerBuilder $container, array $config): void |
84
|
|
|
{ |
85
|
|
|
// Filter enabled header rules |
86
|
2 |
|
$headers = array_filter($config['http_headers'], function (array $header): bool { |
87
|
1 |
|
return $header['enabled'] ? true : false; |
88
|
2 |
|
}); |
89
|
|
|
|
90
|
|
|
// Only register listener if some rule is defined |
91
|
2 |
|
if (count($headers) > 0) { |
92
|
1 |
|
$container->register('ocubom_twig_extra.listener.http_headers', AddHttpHeadersListener::class) |
93
|
1 |
|
->setArguments(array_values($headers)) |
94
|
1 |
|
->addTag('kernel.event_subscriber'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths