merged branch fabpot/hinclude-tweak (PR #7096)

This PR was merged into the 2.2 branch.

Commits
-------

a313188 added a proper setter for the templating servicein HInclude

Discussion
----------

added a proper setter for the templating servicein HInclude

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

---------------------------------------------------------------------------

by stof at 2013-02-17T12:44:40Z

👍
This commit is contained in:
Fabien Potencier 2013-02-17 16:28:01 +01:00
commit ae2f424da7
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;
}
/**