Author: Fabien Potencier (fabien@symfony.com)
Inheritance: extends Twig_Loader_Filesystem
 /**
  * @param CertificationManager $certificationManager
  */
 public function addCertificationTemplateDir(CertificationManager $certificationManager)
 {
     if (!is_dir($this->baseDir)) {
         throw new \RuntimeException('certification-data folder not found: did you install the certifications ?');
     }
     foreach (array_keys($certificationManager->getCertifications()) as $certificationName) {
         $this->loader->addPath($this->baseDir . '/' . $certificationName, $certificationName);
     }
 }
 /**
  * @expectedException \Twig_Error_Loader
  */
 public function testTwigErrorIfLocatorReturnsFalse()
 {
     $parser = $this->getMock('Symfony\\Component\\Templating\\TemplateNameParserInterface');
     $parser->expects($this->once())->method('parse')->with('name.format.engine')->will($this->returnValue(new TemplateReference('', '', 'name', 'format', 'engine')));
     $locator = $this->getMock('Symfony\\Component\\Config\\FileLocatorInterface');
     $locator->expects($this->once())->method('locate')->will($this->returnValue(false));
     $loader = new FilesystemLoader($locator, $parser);
     $loader->getCacheKey('name.format.engine');
 }
Esempio n. 3
0
 public function testTwigSoftErrorIfTemplateDoesNotExist()
 {
     $parser = $this->getMockBuilder('Symfony\\Component\\Templating\\TemplateNameParserInterface')->getMock();
     $locator = $this->getMockBuilder('Symfony\\Component\\Config\\FileLocatorInterface')->getMock();
     $loader = new FilesystemLoader($locator, $parser);
     $loader->addPath(__DIR__ . '/../DependencyInjection/Fixtures/Resources/views');
     $method = new \ReflectionMethod('Symfony\\Bundle\\TwigBundle\\Loader\\FilesystemLoader', 'findTemplate');
     $method->setAccessible(true);
     $this->assertFalse($method->invoke($loader, 'name.format.engine', false));
 }
 private function getUsedTemplates(\Twig_Profiler_Profile $profile)
 {
     $templates = array();
     foreach ($profile as $p) {
         if ($p->isTemplate()) {
             try {
                 $templates[] = array('template' => $p->getTemplate(), 'fullPath' => $this->filesystemLoader->getCacheKey($p->getTemplate()));
             } catch (\Exception $e) {
             }
         }
         $templates = array_merge($templates, $this->getUsedTemplates($p));
     }
     return $templates;
 }
Esempio n. 5
0
 /**
  * @param string $template
  * @param bool $throw
  * @return string
  */
 protected function findTemplate($template, $throw = true)
 {
     $parts = explode(':', $template);
     $parts[1] = 'Content';
     $defaultTemplate = implode(':', $parts);
     return parent::findTemplate($defaultTemplate, $throw);
 }
 protected function findTemplate($name, $throw = true)
 {
     // If it's prefixed with "Theme" we need to change the name before we pass it along...
     if (TwigDatabaseLoader::MAGIC_TEMPLATE === substr($name, 0, strlen(TwigDatabaseLoader::MAGIC_TEMPLATE))) {
         $name = $this->defaultLoadBundle . substr($name, strlen(TwigDatabaseLoader::MAGIC_TEMPLATE));
         return parent::findTemplate($name, $throw);
     }
     throw new Twig_Error_Loader(sprintf('Template for "%s" does not exist and is not prefixed.', $name));
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 protected function findTemplate($template)
 {
     $templateName = (string) $template;
     // Only try and load templates which aren't namespaced
     if (strpos($templateName, '@theme/') === 0) {
         $templatePath = str_replace('@theme', '', $templateName);
         $theme = $this->themeManager->getAdminTheme();
         return parent::findTemplate('@theme_' . $theme->getName() . $templatePath);
     }
     if (strpos($templateName, 'theme_') === 0) {
         if (preg_match('/theme_([^:]+):([^:]*):(.*)/', $templateName, $matches)) {
             list($fullName, $themeName, $path, $file) = $matches;
             $theme = $this->themeManager->getTheme($themeName);
             return parent::findTemplate('@theme_' . $theme->getName() . $path . '/' . $file);
         }
     }
     return parent::findTemplate($template);
 }
 /**
  * @param string|TemplateReferenceInterface $template
  * @return string
  */
 protected function findTemplate($template)
 {
     $logicalName = (string) $template;
     if (isset($this->cache[$logicalName])) {
         return $this->cache[$logicalName];
     }
     if ($this->request === null && $this->container->isScopeActive('request')) {
         $this->request = $this->container->get('request');
     }
     $locale = $this->request ? $this->request->attributes->get('_locale') : 'en';
     if (is_string($template)) {
         if (strpos($template, ':')) {
             try {
                 $template = $this->parser->parse($template);
             } catch (\Exception $e) {
             }
         } else {
             return parent::findTemplate($template);
         }
     }
     if ($locale !== 'en') {
         $params = $template->all();
         $localizedTemplate = new TemplateReference($params['bundle'], $params['controller'], $params['name'], $params['format'], $params['engine']);
         if ($params['controller']) {
             $localizedTemplate->set('controller', $locale . '/' . $params['controller']);
         } else {
             $localizedTemplate->set('name', $locale . '/' . $params['name']);
         }
         try {
             return parent::findTemplate($localizedTemplate);
         } catch (\Twig_Error_Loader $e) {
             return parent::findTemplate($template);
         }
     }
     return parent::findTemplate($template);
 }
 public function testTwigErrorIfLocatorReturnsFalse()
 {
     $this->setExpectedException('Twig_Error_Loader');
     $this->locator->expects($this->once())->method('locate')->will($this->returnValue(false));
     $this->loader->getCacheKey('name.format.engine');
 }
Esempio n. 10
0
 public function __construct(KernelInterface $kernel, FileLocatorInterface $locator, TemplateNameParserInterface $parser)
 {
     $this->kernel = $kernel;
     $this->cache = [];
     parent::__construct($locator, $parser);
 }
Esempio n. 11
0
 protected function findTemplate($template, $throw = true)
 {
     //todo: find formatPath Template first
     return parent::findTemplate($template, $throw);
 }
Esempio n. 12
0
 /**
  * __construct
  *
  * Extension constructor.
  *
  * @access public
  * @param  FilesystemLoader $loader
  */
 public function __construct(FilesystemLoader $loader)
 {
     $loader->addPath($this->getTemplateDirectory(), 'Pomm');
 }
 protected function findTemplate($template)
 {
     $template = $this->frontSynchroniserManager !== null && $this->isFrontSynchroniserTemplate($template) ? $this->frontSynchroniserManager->compile($template) : $template;
     return parent::findTemplate($template);
 }