-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
added Twig runtimes for "critical" Twig extensions #20094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d0792e4
3d4ad0b
79efb4c
812fbb4
c541804
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Twig\Extension; | ||
|
||
use Symfony\Component\HttpKernel\Fragment\FragmentHandler; | ||
use Symfony\Component\HttpKernel\Controller\ControllerReference; | ||
|
||
/** | ||
* Provides integration with the HttpKernel component. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class HttpKernelRuntime | ||
{ | ||
private $handler; | ||
|
||
public function __construct(FragmentHandler $handler) | ||
{ | ||
$this->handler = $handler; | ||
} | ||
|
||
/** | ||
* Renders a fragment. | ||
* | ||
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance | ||
* @param array $options An array of options | ||
* | ||
* @return string The fragment content | ||
* | ||
* @see FragmentHandler::render() | ||
*/ | ||
public function renderFragment($uri, $options = array()) | ||
{ | ||
$strategy = isset($options['strategy']) ? $options['strategy'] : 'inline'; | ||
unset($options['strategy']); | ||
|
||
return $this->handler->render($uri, $strategy, $options); | ||
} | ||
|
||
/** | ||
* Renders a fragment. | ||
* | ||
* @param string $strategy A strategy name | ||
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance | ||
* @param array $options An array of options | ||
* | ||
* @return string The fragment content | ||
* | ||
* @see FragmentHandler::render() | ||
*/ | ||
public function renderFragmentStrategy($strategy, $uri, $options = array()) | ||
{ | ||
return $this->handler->render($uri, $strategy, $options); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,5 +71,17 @@ public function process(ContainerBuilder $container) | |
if ($container->has('assets.packages')) { | ||
$container->getDefinition('twig.extension.assets')->addTag('twig.extension'); | ||
} | ||
|
||
if (class_exists('Symfony\Component\Yaml\Parser')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the definition of the container now depends on the existence of a class, we should define a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's for another PR as this is not the only place where we are doing this in a compiler pass. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #20121 |
||
$container->getDefinition('twig.extension.yaml')->addTag('twig.extension'); | ||
} | ||
|
||
if (class_exists('Symfony\Component\Stopwatch\Stopwatch')) { | ||
$container->getDefinition('twig.extension.debug.stopwatch')->addTag('twig.extension'); | ||
} | ||
|
||
if (class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) { | ||
$container->getDefinition('twig.extension.expression')->addTag('twig.extension'); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As usual: any reason to allow inheritance?