/**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $templates = $this->templateFinder->findAllTemplates();
     /** @var TemplateReferenceInterface $template */
     foreach ($templates as $template) {
         $this->warmUpTemplate($template);
     }
 }
 public function testWarmUpEmpty()
 {
     $this->templateFinder->expects($this->once())->method('findAllTemplates')->will($this->returnValue(array()));
     $this->fileLocator->expects($this->never())->method('locate');
     $warmer = new TemplatePathsCacheWarmer($this->templateFinder, $this->templateLocator);
     $warmer->warmUp($this->tmpDir);
     $this->assertFileExists($this->tmpDir . '/templates.php');
     $this->assertSame(file_get_contents(__DIR__ . '/../Fixtures/TemplatePathsCache/templates-empty.php'), file_get_contents($this->tmpDir . '/templates.php'));
 }
 function it_builds_cache_by_warming_up_every_template_and_every_theme_together(TemplateFinderInterface $templateFinder, TemplateLocatorInterface $templateLocator, ThemeRepositoryInterface $themeRepository, Cache $cache, ThemeInterface $theme, TemplateReferenceInterface $firstTemplate, TemplateReferenceInterface $secondTemplate)
 {
     $templateFinder->findAllTemplates()->willReturn([$firstTemplate, $secondTemplate]);
     $themeRepository->findAll()->willReturn([$theme]);
     $theme->getName()->willReturn('theme/name');
     $firstTemplate->getLogicalName()->willReturn('Logical:Name:First');
     $secondTemplate->getLogicalName()->willReturn('Logical:Name:Second');
     $templateLocator->locateTemplate($firstTemplate, $theme)->willReturn('/First/Theme/index.html.twig');
     $templateLocator->locateTemplate($secondTemplate, $theme)->willThrow(ResourceNotFoundException::class);
     $cache->save('Logical:Name:First|theme/name', '/First/Theme/index.html.twig')->shouldBeCalled();
     $cache->save('Logical:Name:Second|theme/name', null)->shouldBeCalled();
     $this->warmUp(null);
 }
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $templates = [];
     $themes = $this->themeRepository->findAll();
     /** @var TemplateReferenceInterface $template */
     foreach ($this->finder->findAllTemplates() as $template) {
         $this->themeContext->clear();
         foreach ($themes as $theme) {
             $this->themeContext->setTheme($theme);
             $path = $this->locator->locate($template);
             $templates[$template->getLogicalName() . "|" . $theme->getLogicalName()] = $path;
         }
         $templates[$template->getLogicalName()] = $this->locator->locate($template);
     }
     $this->writeCacheFile($cacheDir . '/templates.php', sprintf('<?php return %s;', var_export($templates, true)));
 }
예제 #5
0
 /**
  * Warms up the cache.
  *
  * @param string $cacheDir The cache directory
  */
 public function warmUp($cacheDir)
 {
     $engine = $this->container->get('templating.engine.smarty');
     $logger = $this->container->has('logger') ? $this->container->get('logger') : null;
     foreach ($this->finder->findAllTemplates() as $template) {
         try {
             $engine->compileTemplate($template, false);
         } catch (\Exception $e) {
             // problem during compilation, log it and give up
             $e = SmartyBundleRuntimeException::createFromPrevious($e, $template);
             if ($logger) {
                 $logger->warn(sprintf('Failed to compile Smarty template "%s": "%s"', (string) $template, $e->getMessage()));
             }
         }
     }
 }
예제 #6
0
 private function boot()
 {
     if ($this->booted) {
         return;
     }
     $this->booted = true;
     foreach ($this->finder->findAllTemplates() as $reference) {
         $this->addTemplate($reference);
     }
     foreach (array_keys($this->bundle_paths) as $name) {
         if (false !== ($resolved_path = $this->resolveResourcePath('@' . $name))) {
             $this->aliases['@' . $name] = $resolved_path;
             $this->addPath($resolved_path);
         }
     }
     $this->profiler->set('bundles', $this->aliases);
     $this->profiler->set('templates', $this->templates);
 }