Skip to content

Commit

Permalink
Merge pull request #13 from Troopers/feature/twig2.0
Browse files Browse the repository at this point in the history
Compatibility with twig >2.0
  • Loading branch information
paulandrieux authored May 21, 2017
2 parents 3c7fa9f + d405ef4 commit 1b8dc11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 4 additions & 7 deletions Twig/AsseticInjectorTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Bundle\AsseticBundle\Twig\AsseticNode;
use Symfony\Bundle\AsseticBundle\Twig\AsseticTokenParser as BaseAsseticTokenParser;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;

/**
* Assetic token parser.
Expand Down Expand Up @@ -60,19 +61,15 @@ public function parse(\Twig_Token $token)
// check the bundle
$templateRef = null;
try {
$templateRef = $this->templateNameParser->parse($this->parser->getStream()->getFilename());
$templateRef = $this->templateNameParser->parse($this->parser->getStream()->getSourceContext()->getName());
} catch (\RuntimeException $e) {
// this happens when the filename isn't a Bundle:* url
// and it contains ".."
} catch (\InvalidArgumentException $e) {
// this happens when the filename isn't a Bundle:* url
// but an absolute path instead
}
try {
$bundle = $templateRef ? $templateRef->get('bundle') : null;
} catch (\InvalidArgumentException $e) {
$bundle = null;
}
$bundle = $templateRef instanceof TemplateReference ? $templateRef->get('bundle') : null;
if ($bundle && !in_array($bundle, $this->enabledBundles)) {
throw new InvalidBundleException($bundle, "the {% {$this->getTag()} %} tag", $templateRef->getLogicalName(), $this->enabledBundles);
}
Expand All @@ -81,7 +78,7 @@ public function parse(\Twig_Token $token)
return $this->parseAndInject($token);
}

protected function createNode(AssetInterface $asset, \Twig_NodeInterface $body, array $inputs, array $filters, $name, array $attributes = [], $lineno = 0, $tag = null)
protected function createNode(AssetInterface $asset, \Twig_Node $body, array $inputs, array $filters, $name, array $attributes = [], $lineno = 0, $tag = null)
{
return new AsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
}
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
}
],
"require": {
"php": ">=5.3.2"
"php": ">=5.3.2",
"symfony/assetic-bundle": "~2.7",
"twig/twig": "~2.0"
},
"autoload": {
"psr-0": { "Troopers\\AsseticInjectorBundle": "" }
Expand Down

0 comments on commit 1b8dc11

Please sign in to comment.