73ee17b68aa9255b8652a0fb2e7ff7e595d941bb
[yaffs-website] / web / core / lib / Drupal / Core / DependencyInjection / Compiler / TwigExtensionPass.php
1 <?php
2
3 namespace Drupal\Core\DependencyInjection\Compiler;
4
5 use Drupal\Component\Utility\Crypt;
6 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7 use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9 /**
10  * Adds the twig_extension_hash parameter to the container.
11  *
12  * twig_extension_hash is a hash of all extension mtimes for Twig template
13  * invalidation.
14  */
15 class TwigExtensionPass implements CompilerPassInterface {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function process(ContainerBuilder $container) {
21     $twig_extension_hash = '';
22     foreach (array_keys($container->findTaggedServiceIds('twig.extension')) as $service_id) {
23       $class_name = $container->getDefinition($service_id)->getClass();
24       $reflection = new \ReflectionClass($class_name);
25       // We use the class names as hash in order to invalidate on new extensions
26       // and mtime for every time we change an existing file.
27       $twig_extension_hash .= $class_name . filemtime($reflection->getFileName());
28     }
29
30     $container->setParameter('twig_extension_hash', Crypt::hashBase64($twig_extension_hash));
31   }
32
33 }