mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 19:06:40 +00:00
removed usage of realpath in cache key
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user