3 namespace Drupal\Core\DependencyInjection\Compiler;
5 use Drupal\Component\Utility\Crypt;
6 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7 use Symfony\Component\DependencyInjection\ContainerBuilder;
10 * Adds the twig_extension_hash parameter to the container.
12 * Parameter twig_extension_hash is a hash of all extension mtimes for Twig
13 * template invalidation.
15 class TwigExtensionPass implements CompilerPassInterface {
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());
30 $container->setParameter('twig_extension_hash', Crypt::hashBase64($twig_extension_hash));