File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22 file_name_pattern : ' *.twig'
33 form_themes : ['bootstrap_5_layout.html.twig']
44
5- globals :
6- dirigent :
7- slug : ' %dirigent.slug%'
8-
95when@test :
106 twig :
117 strict_variables : true
Original file line number Diff line number Diff line change 33
44# Put parameters here that don't need to change on each machine where the app is deployed
55# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
6- parameters :
7- dirigent.slug : ~
86
97services :
108 # default configuration for services in *this* file
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace CodedMonkey \Dirigent \DependencyInjection \Compiler ;
4+
5+ use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
6+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
7+
8+ class ParametersPass implements CompilerPassInterface
9+ {
10+ public function process (ContainerBuilder $ container ): void
11+ {
12+ $ this ->setTwigGlobal ($ container );
13+ }
14+
15+ private function setTwigGlobal (ContainerBuilder $ container ): void
16+ {
17+ $ parameterBag = $ container ->getParameterBag ();
18+
19+ $ variables = [
20+ 'slug ' => $ parameterBag ->get ('dirigent.slug ' ),
21+ ];
22+
23+ $ container ->getDefinition ('twig ' )->addMethodCall ('addGlobal ' , ['dirigent ' , $ variables ]);
24+ }
25+ }
Original file line number Diff line number Diff line change @@ -11,10 +11,8 @@ class DirigentExtension extends ConfigurableExtension
1111{
1212 protected function loadInternal (array $ mergedConfig , ContainerBuilder $ container ): void
1313 {
14- if (null === $ slug = $ mergedConfig ['slug ' ]) {
15- $ slug = (new AsciiSlugger ())->slug ($ mergedConfig ['title ' ]);
16- $ slug = strtolower ($ slug );
17- }
14+ $ slug = $ mergedConfig ['slug ' ];
15+ $ slug ??= (new AsciiSlugger ())->slug ($ mergedConfig ['title ' ])->lower ()->toString ();
1816
1917 $ container ->setParameter ('dirigent.title ' , $ mergedConfig ['title ' ]);
2018 $ container ->setParameter ('dirigent.slug ' , $ slug );
Original file line number Diff line number Diff line change 33namespace CodedMonkey \Dirigent ;
44
55use CodedMonkey \Dirigent \DependencyInjection \Compiler \EncryptionPass ;
6+ use CodedMonkey \Dirigent \DependencyInjection \Compiler \ParametersPass ;
67use CodedMonkey \Dirigent \DependencyInjection \DirigentExtension ;
78use Symfony \Bundle \FrameworkBundle \Kernel \MicroKernelTrait ;
89use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -32,8 +33,8 @@ protected function build(ContainerBuilder $container): void
3233 {
3334 $ container ->registerExtension (new DirigentExtension ());
3435
35- // The encryption pass has to be the first pass to run as it removes sensitive data from the container
36- $ container ->addCompilerPass (new EncryptionPass (), priority: 2048 );
36+ $ container -> addCompilerPass ( new EncryptionPass (), priority: 2048 ); // The encryption pass has to be the first pass to run as it removes sensitive data from the container
37+ $ container ->addCompilerPass (new ParametersPass () );
3738 }
3839
3940 public function boot (): void
You can’t perform that action at this time.
0 commit comments