|
@@ -0,0 +1,62 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+/*
|
|
|
+ * This file is part of the Symfony package.
|
|
|
+ *
|
|
|
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
+ *
|
|
|
+ * For the full copyright and license information, please view the LICENSE
|
|
|
+ * file that was distributed with this source code.
|
|
|
+ */
|
|
|
+
|
|
|
+namespace Symfony\Bundle\TwigBundle\CacheWarmer;
|
|
|
+
|
|
|
+use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
|
|
|
+use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Generates the Twig cache for all templates.
|
|
|
+ *
|
|
|
+ * This warmer must be registered after TemplatePathsCacheWarmer,
|
|
|
+ * as the Twig loader will need the cache generated by it.
|
|
|
+ *
|
|
|
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
+ */
|
|
|
+class TemplateCacheCacheWarmer extends CacheWarmer
|
|
|
+{
|
|
|
+ protected $container;
|
|
|
+
|
|
|
+ public function __construct(ContainerInterface $container)
|
|
|
+ {
|
|
|
+ // we don't inject the Twig environment directly as it needs
|
|
|
+ // the loader, which is a cached one, and the cache is not
|
|
|
+ // yet available when this instance is created (the
|
|
|
+ // TemplateCacheCacheWarmer has not been run yet).
|
|
|
+ $this->container = $container;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Warms up the cache.
|
|
|
+ *
|
|
|
+ * @param string $cacheDir The cache directory
|
|
|
+ */
|
|
|
+ public function warmUp($cacheDir)
|
|
|
+ {
|
|
|
+ $templates = include $cacheDir.'/templates.php';
|
|
|
+
|
|
|
+ $twig = $this->container->get('twig');
|
|
|
+ foreach (array_keys($templates) as $template) {
|
|
|
+ $twig->loadTemplate($template);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Checks whether this warmer is optional or not.
|
|
|
+ *
|
|
|
+ * @return Boolean always true
|
|
|
+ */
|
|
|
+ public function isOptional()
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|