/** * {@inheritdoc} */ public function getCacheKey($name) { $templates = $this->getTemplates($name); foreach ($templates as $template) { try { return $this->loader->getCacheKey($template); } catch (\Twig_Error $e) { } } throw new \Twig_Error_Loader(sprintf("Template \"%s\" not found. Tried the following:\n%s", $name, implode("\n", $templates))); }
/** * @dataProvider getSecurityTests */ public function testSecurity($template) { $loader = new Twig_Loader_Filesystem(array(dirname(__FILE__) . '/../Fixtures')); try { $loader->getCacheKey($template); $this->fail(); } catch (Twig_Error_Loader $e) { $this->assertNotContains('Unable to find template', $e->getMessage()); } }
public function getCacheKey($name) { if (isset($this->templateStrings[$name])) { return $this->templateStrings[$name]; } $cacheKey = parent::getCacheKey($name); if ($this->useTimeInCacheKey) { $path = $this->findTemplate($name); $lastModified = filemtime($path); $cacheKey .= $lastModified; } return $cacheKey; }
/** * @dataProvider getBasePaths */ public function testPaths($basePath) { $loader = new Twig_Loader_Filesystem(array($basePath . '/normal', $basePath . '/normal_bis')); $loader->setPaths(array($basePath . '/named', $basePath . '/named_bis'), 'named'); $loader->addPath($basePath . '/named_ter', 'named'); $loader->addPath($basePath . '/normal_ter'); $loader->prependPath($basePath . '/normal_final'); $loader->prependPath($basePath . '/named/../named_quater', 'named'); $loader->prependPath($basePath . '/named_final', 'named'); $this->assertEquals(array($basePath . '/normal_final', $basePath . '/normal', $basePath . '/normal_bis', $basePath . '/normal_ter'), $loader->getPaths()); $this->assertEquals(array($basePath . '/named_final', $basePath . '/named/../named_quater', $basePath . '/named', $basePath . '/named_bis', $basePath . '/named_ter'), $loader->getPaths('named')); // do not use realpath here as it would make the test unuseful $this->assertEquals(str_replace('\\', '/', $basePath . '/named_quater/named_absolute.html'), str_replace('\\', '/', $loader->getCacheKey('@named/named_absolute.html'))); $this->assertEquals("path (final)\n", $loader->getSource('index.html')); $this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html')); $this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html')); }
public function testPaths() { $basePath = dirname(__FILE__) . '/Fixtures'; $loader = new Twig_Loader_Filesystem(array($basePath . '/normal', $basePath . '/normal_bis')); $loader->setPaths(array($basePath . '/named', $basePath . '/named_bis'), 'named'); $loader->addPath($basePath . '/named_ter', 'named'); $loader->addPath($basePath . '/normal_ter'); $loader->prependPath($basePath . '/normal_final'); $loader->prependPath($basePath . '/named/../named_quater', 'named'); $loader->prependPath($basePath . '/named_final', 'named'); $this->assertEquals(array($basePath . '/normal_final', $basePath . '/normal', $basePath . '/normal_bis', $basePath . '/normal_ter'), $loader->getPaths()); $this->assertEquals(array($basePath . '/named_final', $basePath . '/named/../named_quater', $basePath . '/named', $basePath . '/named_bis', $basePath . '/named_ter'), $loader->getPaths('named')); $this->assertEquals(realpath($basePath . '/named_quater/named_absolute.html'), realpath($loader->getCacheKey('@named/named_absolute.html'))); $this->assertEquals("path (final)\n", $loader->getSource('index.html')); $this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html')); $this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html')); }
/** * @param string $name * * @return false|string */ public function getCacheKey($name) { $name = $this->getName($name); return parent::getCacheKey($name); }
/** * @dataProvider getSecurityTests * @expectedException Twig_Error_Loader */ public function testSecurity($template) { $loader = new Twig_Loader_Filesystem(array(__DIR__ . '/../Fixtures')); $loader->getCacheKey($template); }