Skip to content

Commit

Permalink
removed TemplateReferenceInterface::getSignature() (replaced by the e…
Browse files Browse the repository at this point in the history
…xisting getLogicalName() which already acts as a unique identifier)
  • Loading branch information
fabpot committed Jun 7, 2011
1 parent 5af7c7f commit 5be0baf
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 44 deletions.
Expand Up @@ -46,7 +46,7 @@ public function warmUp($cacheDir)
$templates = array();

foreach ($this->finder->findAllTemplates() as $template) {
$templates[$template->getSignature()] = $this->locator->locate($template);
$templates[$template->getLogicalName()] = $this->locator->locate($template);
}

$this->writeCacheFile($cacheDir.'/templates.php', sprintf('<?php return %s;', var_export($templates, true)));
Expand Down
Expand Up @@ -72,7 +72,8 @@ public function locate($template, $currentPath = null, $first = true)
*/
protected function getCachedTemplatePath(TemplateReferenceInterface $template)
{
$key = $template->getSignature();
$key = $template->getLogicalName();

return isset($this->templates[$key]) ? $this->templates[$key] : null;
}
}
Expand Up @@ -54,7 +54,7 @@ public function locate($template, $currentPath = null, $first = true)
throw new \InvalidArgumentException("The template must be an instance of TemplateReferenceInterface.");
}

$key = $template->getSignature();
$key = $template->getLogicalName();

if (isset($this->cache[$key])) {
return $this->cache[$key];
Expand Down
Expand Up @@ -23,11 +23,11 @@ class TemplateReference extends BaseTemplateReference
public function __construct($bundle = null, $controller = null, $name = null, $format = null, $engine = null)
{
$this->parameters = array(
'bundle' => $bundle,
'controller' => $controller,
'name' => $name,
'format' => $format,
'engine' => $engine,
'bundle' => $bundle,
'controller' => $controller,
'name' => $name,
'format' => $format,
'engine' => $engine,
);
}

Expand All @@ -51,10 +51,6 @@ public function getPath()
*/
public function getLogicalName()
{
$parts = sprintf('%s:%s:', $this->get('bundle'), $this->get('controller'));
$elements = sprintf('%s.%s.%s', $this->get('name'), $this->get('format'), $this->get('engine'));

return $parts . $elements;
return sprintf('%s:%s:%s.%s.%s', $this->get('bundle'), $this->get('controller'), $this->get('name'), $this->get('format'), $this->get('engine'));
}

}
Expand Up @@ -48,7 +48,7 @@ public function testParse($name, $ref)
{
$template = $this->parser->parse($name);

$this->assertEquals($template->getSignature(), $ref->getSignature());
$this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
$this->assertEquals($template->getLogicalName(), $ref->getLogicalName());

This comment has been minimized.

Copy link
@stof

stof Jun 7, 2011

Member

this test is now duplicated

$this->assertEquals($template->getLogicalName(), $name);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public function testParseFromFilename($file, $ref)
if ($ref === false) {
$this->assertFalse($template);
} else {
$this->assertEquals($template->getSignature(), $ref->getSignature());
$this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php
Expand Up @@ -88,7 +88,7 @@ protected function findTemplate($name)
{
$tpl = $this->parser->parse($name);

if (isset($this->cache[$key = $tpl->getSignature()])) {
if (isset($this->cache[$key = $tpl->getLogicalName()])) {
return $this->cache[$key];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Templating/Loader/CacheLoader.php
Expand Up @@ -50,7 +50,7 @@ public function __construct(LoaderInterface $loader, $dir)
*/
public function load(TemplateReferenceInterface $template)
{
$key = $template->getSignature();
$key = $template->getLogicalName();

This comment has been minimized.

Copy link
@vicb

vicb Jun 7, 2011

Contributor

':' seems not to be allowed on win:
http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx.
http://msdn.microsoft.com/en-us/library/aa368590(v=vs.85).aspx

However it could be part of the logical name.

This comment has been minimized.

Copy link
@fabpot

fabpot Jun 7, 2011

Author Member

fixed, thanks.

$dir = $this->dir.DIRECTORY_SEPARATOR.substr($key, 0, 2);
$file = substr($key, 2).'.tpl';
$path = $dir.DIRECTORY_SEPARATOR.$file;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Templating/PhpEngine.php
Expand Up @@ -488,7 +488,7 @@ protected function load($name)
{
$template = $this->parser->parse($name);

$key = $template->getSignature();
$key = $template->getLogicalName();
if (isset($this->cache[$key])) {
return $this->cache[$key];
}
Expand Down
20 changes: 6 additions & 14 deletions src/Symfony/Component/Templating/TemplateReference.php
Expand Up @@ -20,11 +20,11 @@ class TemplateReference implements TemplateReferenceInterface
{
protected $parameters;

public function __construct($name = null, $engine = null)
public function __construct($name = null, $engine = null)
{
$this->parameters = array(
'name' => $name,
'engine' => $engine,
'name' => $name,
'engine' => $engine,
);
}

Expand All @@ -33,16 +33,6 @@ public function __toString()
return $this->getLogicalName();
}

/**
* Returns the template signature
*
* @return string A UID for the template
*/
public function getSignature()
{
return md5(serialize($this->parameters));
}

/**
* Sets a template parameter.
*
Expand Down Expand Up @@ -105,7 +95,9 @@ public function getPath()
}

/**
* Returns the template name
* Returns the "logical" template name.
*
* The template name acts as a unique identifier for the template.
*
* @return string The template name
*/
Expand Down
11 changes: 3 additions & 8 deletions src/Symfony/Component/Templating/TemplateReferenceInterface.php
Expand Up @@ -48,13 +48,6 @@ function set($name, $value);
*/
function get($name);

/**
* Returns the template signature
*
* @return string A UID for the template
*/
function getSignature();

/**
* Returns the path to the template.
*
Expand All @@ -65,7 +58,9 @@ function getSignature();
function getPath();

/**
* Returns the template name
* Returns the "logical" template name.
*
* The template name acts as a unique identifier for the template.
*
* @return string The template name
*/
Expand Down
6 changes: 3 additions & 3 deletions tests/Symfony/Tests/Component/Templating/PhpEngineTest.php
Expand Up @@ -153,13 +153,13 @@ class ProjectTemplateLoader extends Loader
public function setTemplate($name, $content)
{
$template = new TemplateReference($name, 'php');
$this->templates[$template->getSignature()] = $content;
$this->templates[$template->getLogicalName()] = $content;
}

public function load(TemplateReferenceInterface $template)
{
if (isset($this->templates[$template->getSignature()])) {
return new StringStorage($this->templates[$template->getSignature()]);
if (isset($this->templates[$template->getLogicalName()])) {
return new StringStorage($this->templates[$template->getLogicalName()]);
}

return false;
Expand Down
Expand Up @@ -35,7 +35,7 @@ public function testParse($name, $ref)
{
$template = $this->parser->parse($name);

$this->assertEquals($template->getSignature(), $ref->getSignature());
$this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
$this->assertEquals($template->getLogicalName(), $name);
}

Expand Down

0 comments on commit 5be0baf

Please sign in to comment.