integrated the Twig profiler
This commit is contained in:
parent
2570042937
commit
ef0c9679cb
@ -1,4 +1,10 @@
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/fabpot/Twig"
|
||||
}
|
||||
],
|
||||
"name": "symfony/symfony",
|
||||
"type": "library",
|
||||
"description": "The Symfony PHP framework",
|
||||
@ -18,7 +24,7 @@
|
||||
"require": {
|
||||
"php": ">=5.3.9",
|
||||
"doctrine/common": "~2.3",
|
||||
"twig/twig": "~1.17",
|
||||
"twig/twig": "dev-profiler as 1.17.x-dev",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"replace": {
|
||||
|
58
src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php
Normal file
58
src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?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\Stopwatch\Stopwatch;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class ProfilerExtension extends \Twig_Extension_Profiler
|
||||
{
|
||||
private $stopwatch;
|
||||
private $events;
|
||||
|
||||
public function __construct(\Twig_Profiler_Profile $profile, Stopwatch $stopwatch)
|
||||
{
|
||||
parent::__construct($profile);
|
||||
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->events = new \SplObjectStorage();
|
||||
}
|
||||
|
||||
public function enter(\Twig_Profiler_Profile $profile)
|
||||
{
|
||||
if ($profile->isTemplate()) {
|
||||
$this->events[$profile] = $this->stopwatch->start($profile->getName(), 'template');
|
||||
}
|
||||
|
||||
parent::enter($profile);
|
||||
}
|
||||
|
||||
public function leave(\Twig_Profiler_Profile $profile)
|
||||
{
|
||||
parent::leave($profile);
|
||||
|
||||
if ($profile->isTemplate()) {
|
||||
$this->events[$profile]->stop();
|
||||
unset($this->events[$profile]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'native_profiler';
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Bundle\TwigBundle\Debug;
|
||||
|
||||
trigger_error('The '.__NAMESPACE__.'\TimedTwigEngine class is deprecated since version 2.7 and will be removed in 3.0. Use the Twig native profiler instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||
use Symfony\Component\Templating\TemplateNameParserInterface;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
@ -20,6 +22,8 @@ use Symfony\Component\Config\FileLocatorInterface;
|
||||
* Times the time spent to render a template.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 2.7, to be removed in 3.0. Use the Twig native profiler instead.
|
||||
*/
|
||||
class TimedTwigEngine extends TwigEngine
|
||||
{
|
||||
|
@ -63,13 +63,12 @@ class ExtensionPass implements CompilerPassInterface
|
||||
$container->getDefinition('twig.extension.code')->replaceArgument(0, $container->getParameter('templating.helper.code.file_link_format'));
|
||||
}
|
||||
|
||||
if ($container->getParameter('kernel.debug') && $container->has('debug.stopwatch')) {
|
||||
$container->getDefinition('twig.extension.profiler')->addTag('twig.extension');
|
||||
}
|
||||
|
||||
if ($container->has('templating')) {
|
||||
$container->getDefinition('twig.cache_warmer')->addTag('kernel.cache_warmer');
|
||||
|
||||
if ($container->getParameter('kernel.debug')) {
|
||||
$container->setDefinition('templating.engine.twig', $container->findDefinition('debug.templating.engine.twig'));
|
||||
$container->setAlias('debug.templating.engine.twig', 'templating.engine.twig');
|
||||
}
|
||||
} else {
|
||||
$loader = $container->getDefinition('twig.loader.native_filesystem');
|
||||
$loader->addTag('twig.loader');
|
||||
|
@ -9,13 +9,6 @@
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="debug.templating.engine.twig" class="%debug.templating.engine.twig.class%" public="false">
|
||||
<argument type="service" id="twig" />
|
||||
<argument type="service" id="templating.name_parser" />
|
||||
<argument type="service" id="templating.locator" />
|
||||
<argument type="service" id="debug.stopwatch" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.debug" class="Twig_Extension_Debug" public="false">
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
|
@ -70,6 +70,13 @@
|
||||
<argument type="service" id="templating.locator" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.profiler" class="Symfony\Bridge\Twig\Extension\ProfilerExtension" public="false">
|
||||
<argument type="service" id="twig.profile" />
|
||||
<argument type="service" id="debug.stopwatch" on-invalid="ignore" />
|
||||
</service>
|
||||
|
||||
<service id="twig.profile" class="Twig_Profiler_Profile" />
|
||||
|
||||
<service id="twig.extension.trans" class="%twig.extension.trans.class%" public="false">
|
||||
<argument type="service" id="translator" />
|
||||
</service>
|
||||
|
Reference in New Issue
Block a user