2011-02-10 17:20:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-02-10 17:20:44 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\Templating;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal representation of a template.
|
|
|
|
*
|
|
|
|
* @author Victor Berchet <victor@suumit.com>
|
2011-07-20 09:27:25 +01:00
|
|
|
*
|
|
|
|
* @api
|
2011-02-10 17:20:44 +00:00
|
|
|
*/
|
|
|
|
class TemplateReference implements TemplateReferenceInterface
|
|
|
|
{
|
|
|
|
protected $parameters;
|
|
|
|
|
2011-06-07 09:07:43 +01:00
|
|
|
public function __construct($name = null, $engine = null)
|
2011-02-10 17:20:44 +00:00
|
|
|
{
|
|
|
|
$this->parameters = array(
|
2011-06-07 09:07:43 +01:00
|
|
|
'name' => $name,
|
|
|
|
'engine' => $engine,
|
2011-02-10 17:20:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
2011-04-08 10:33:35 +01:00
|
|
|
return $this->getLogicalName();
|
2011-02-10 17:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-08 10:24:28 +01:00
|
|
|
* Sets a template parameter.
|
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param string $name The parameter name
|
|
|
|
* @param string $value The parameter value
|
2011-04-08 10:24:28 +01:00
|
|
|
*
|
|
|
|
* @return TemplateReferenceInterface The TemplateReferenceInterface instance
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException if the parameter is not defined
|
2011-07-20 09:27:25 +01:00
|
|
|
*
|
|
|
|
* @api
|
2011-02-10 17:20:44 +00:00
|
|
|
*/
|
|
|
|
public function set($name, $value)
|
|
|
|
{
|
|
|
|
if (array_key_exists($name, $this->parameters)) {
|
|
|
|
$this->parameters[$name] = $value;
|
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-08 10:24:28 +01:00
|
|
|
* Gets a template parameter.
|
|
|
|
*
|
|
|
|
* @param string $name The parameter name
|
|
|
|
*
|
|
|
|
* @return string The parameter value
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException if the parameter is not defined
|
2011-07-20 09:27:25 +01:00
|
|
|
*
|
|
|
|
* @api
|
2011-02-10 17:20:44 +00:00
|
|
|
*/
|
|
|
|
public function get($name)
|
|
|
|
{
|
|
|
|
if (array_key_exists($name, $this->parameters)) {
|
|
|
|
return $this->parameters[$name];
|
|
|
|
}
|
2011-02-27 17:29:20 +00:00
|
|
|
|
|
|
|
throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
|
2011-02-10 17:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-08 10:24:28 +01:00
|
|
|
* Gets the template parameters.
|
|
|
|
*
|
|
|
|
* @return array An array of parameters
|
2011-07-20 09:27:25 +01:00
|
|
|
*
|
|
|
|
* @api
|
2011-02-10 17:20:44 +00:00
|
|
|
*/
|
|
|
|
public function all()
|
|
|
|
{
|
|
|
|
return $this->parameters;
|
|
|
|
}
|
|
|
|
|
2011-02-21 18:24:27 +00:00
|
|
|
/**
|
2011-04-08 10:24:28 +01:00
|
|
|
* Returns the path to the template.
|
|
|
|
*
|
|
|
|
* By default, it just returns the template name.
|
|
|
|
*
|
|
|
|
* @return string A path to the template or a resource
|
2011-07-20 09:27:25 +01:00
|
|
|
*
|
|
|
|
* @api
|
2011-02-21 18:24:27 +00:00
|
|
|
*/
|
|
|
|
public function getPath()
|
|
|
|
{
|
|
|
|
return $this->parameters['name'];
|
|
|
|
}
|
2011-04-08 09:31:47 +01:00
|
|
|
|
|
|
|
/**
|
2011-06-07 09:07:43 +01:00
|
|
|
* Returns the "logical" template name.
|
|
|
|
*
|
|
|
|
* The template name acts as a unique identifier for the template.
|
2011-04-08 10:24:28 +01:00
|
|
|
*
|
|
|
|
* @return string The template name
|
2011-07-20 09:27:25 +01:00
|
|
|
*
|
|
|
|
* @api
|
2011-04-08 09:31:47 +01:00
|
|
|
*/
|
|
|
|
public function getLogicalName()
|
|
|
|
{
|
|
|
|
return $this->parameters['name'];
|
|
|
|
}
|
2011-02-10 17:20:44 +00:00
|
|
|
}
|