added a proper setter for the templating servicein HInclude

This commit is contained in:
Fabien Potencier 2013-02-10 12:34:10 +01:00
parent 63bfd9ef79
commit a3131882e3
2 changed files with 14 additions and 5 deletions

View File

@ -41,7 +41,7 @@ class ContainerAwareHIncludeFragmentRenderer extends HIncludeFragmentRenderer
public function render($uri, Request $request, array $options = array())
{
if (!$this->templating) {
$this->templating = $this->container->get('templating');
$this->setTemplating($this->container->get('templating'));
}
return parent::render($uri, $request, $options);

View File

@ -24,10 +24,9 @@ use Symfony\Component\HttpKernel\UriSigner;
*/
class HIncludeFragmentRenderer extends RoutableFragmentRenderer
{
protected $templating;
private $globalDefaultTemplate;
private $signer;
private $templating;
/**
* Constructor.
@ -37,14 +36,24 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
* @param string $globalDefaultTemplate The global default content (it can be a template name or the content)
*/
public function __construct($templating = null, UriSigner $signer = null, $globalDefaultTemplate = null)
{
$this->setTemplating($templating);
$this->globalDefaultTemplate = $globalDefaultTemplate;
$this->signer = $signer;
}
/**
* Sets the templating engine to use to render the default content.
*
* @param EngineInterface|\Twig_Environment|null $templating An EngineInterface or a \Twig_Environment instance
*/
public function setTemplating($templating)
{
if (null !== $templating && !$templating instanceof EngineInterface && !$templating instanceof \Twig_Environment) {
throw new \InvalidArgumentException('The hinclude rendering strategy needs an instance of \Twig_Environment or Symfony\Component\Templating\EngineInterface');
}
$this->templating = $templating;
$this->globalDefaultTemplate = $globalDefaultTemplate;
$this->signer = $signer;
}
/**