mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 19:36:43 +00:00
changed the arguments of generateKey
This commit is contained in:
@@ -29,11 +29,11 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function generateKey($className, $prefix)
|
public function generateKey($name, $className)
|
||||||
{
|
{
|
||||||
$class = substr($className, strlen($prefix));
|
$hash = hash('sha256', $className);
|
||||||
|
|
||||||
return $this->directory.'/'.$class[0].'/'.$class[1].'/'.$class.'.php';
|
return $this->directory.'/'.$hash[0].'/'.$hash[1].'/'.$hash.'.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class Twig_Cache_Null implements Twig_CacheInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function generateKey($className, $prefix)
|
public function generateKey($name, $className)
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ interface Twig_CacheInterface
|
|||||||
/**
|
/**
|
||||||
* Generates a cache key for the given template class name.
|
* Generates a cache key for the given template class name.
|
||||||
*
|
*
|
||||||
|
* @param string $name The template name
|
||||||
* @param string $className The template class name
|
* @param string $className The template class name
|
||||||
* @param string $prefix A template class prefix
|
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function generateKey($className, $prefix);
|
public function generateKey($name, $className);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the cache key exists.
|
* Checks if the cache key exists.
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ class Twig_Environment
|
|||||||
{
|
{
|
||||||
@trigger_error(sprintf('The %s method is deprecated and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
|
@trigger_error(sprintf('The %s method is deprecated and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
|
||||||
|
|
||||||
$key = $this->cache->generateKey($this->getTemplateClass($name), $this->templateClassPrefix);
|
$key = $this->cache->generateKey($name, $this->getTemplateClass($name));
|
||||||
|
|
||||||
return !$key ? false : $key;
|
return !$key ? false : $key;
|
||||||
}
|
}
|
||||||
@@ -370,7 +370,7 @@ class Twig_Environment
|
|||||||
if ($this->bcGetCacheFilename) {
|
if ($this->bcGetCacheFilename) {
|
||||||
$key = $this->getCacheFilename($name);
|
$key = $this->getCacheFilename($name);
|
||||||
} else {
|
} else {
|
||||||
$key = $this->cache->generateKey($cls, $this->templateClassPrefix);
|
$key = $this->cache->generateKey($name, $cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->cache->has($key) || ($this->isAutoReload() && !$this->isTemplateFresh($name, $this->cache->getTimestamp($key)))) {
|
if (!$this->cache->has($key) || ($this->isAutoReload() && !$this->isTemplateFresh($name, $this->cache->getTimestamp($key)))) {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
|||||||
// force compilation
|
// force compilation
|
||||||
$twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{ foo }}')), $options);
|
$twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{ foo }}')), $options);
|
||||||
|
|
||||||
$key = $cache->generateKey($twig->getTemplateClass('index'), $twig->getTemplateClassPrefix());
|
$key = $cache->generateKey('index', $twig->getTemplateClass('index'));
|
||||||
$cache->write($key, $twig->compileSource('{{ foo }}', 'index'));
|
$cache->write($key, $twig->compileSource('{{ foo }}', 'index'));
|
||||||
|
|
||||||
// check that extensions won't be initialized when rendering a template that is already in the cache
|
// check that extensions won't be initialized when rendering a template that is already in the cache
|
||||||
|
|||||||
Reference in New Issue
Block a user