removed usage of realpath in cache key

This commit is contained in:
Fabien Potencier
2016-09-19 18:19:44 -07:00
parent 26deac3c9b
commit 6f0e3edbc5
3 changed files with 29 additions and 8 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.25.0 (2016-XX-XX)
* removed usage of realpath in cache keys
* removed embed parent workaround for simple use cases
* deprecated the ability to store non Node instances in Node::$nodes
* deprecated Twig_Environment::getLexer(), Twig_Environment::getParser(), Twig_Environment::getCompiler()
+16 -5
View File
@@ -198,11 +198,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
foreach ($this->paths[$namespace] as $path) {
if (is_file($path.'/'.$shortname)) {
if (false !== $realpath = realpath($path.'/'.$shortname)) {
return $this->cache[$name] = $realpath;
}
return $this->cache[$name] = $path.'/'.$shortname;
return $this->cache[$name] = $this->normalizePath($path.'/'.$shortname);
}
}
@@ -257,4 +253,19 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
}
}
}
private function normalizePath($path)
{
$parts = explode('/', str_replace('\\', '/', $path));
$new = array();
foreach ($parts as $i => $part) {
if ('..' === $part) {
array_pop($new);
} elseif ('.' !== $part && ('' !== $part || 0 === $i)) {
$new[] = $part;
}
}
return implode('/', $new);
}
}
+12 -3
View File
@@ -51,10 +51,11 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
);
}
public function testPaths()
/**
* @dataProvider getBasePaths
*/
public function testPaths($basePath)
{
$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');
@@ -84,6 +85,14 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
$this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html'));
}
public function getBasePaths()
{
return array(
array(dirname(__FILE__).'/Fixtures'),
array('test/Twig/Tests/Loader/Fixtures'),
);
}
public function testEmptyConstructor()
{
$loader = new Twig_Loader_Filesystem();