Augmentation vers version 3.3.0
This commit is contained in:
@@ -15,6 +15,8 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
|
||||
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Markup;
|
||||
use Twig\Profiler\Dumper\HtmlDumper;
|
||||
use Twig\Profiler\Profile;
|
||||
@@ -27,11 +29,13 @@ use Twig\Profiler\Profile;
|
||||
class TwigDataCollector extends DataCollector implements LateDataCollectorInterface
|
||||
{
|
||||
private $profile;
|
||||
private $twig;
|
||||
private $computed;
|
||||
|
||||
public function __construct(Profile $profile)
|
||||
public function __construct(Profile $profile, Environment $twig = null)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
$this->twig = $twig;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,12 +45,46 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->profile->reset();
|
||||
$this->computed = null;
|
||||
$this->data = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function lateCollect()
|
||||
{
|
||||
$this->data['profile'] = serialize($this->profile);
|
||||
$this->data['template_paths'] = [];
|
||||
|
||||
if (null === $this->twig) {
|
||||
return;
|
||||
}
|
||||
|
||||
$templateFinder = function (Profile $profile) use (&$templateFinder) {
|
||||
if ($profile->isTemplate()) {
|
||||
try {
|
||||
$template = $this->twig->load($name = $profile->getName());
|
||||
} catch (LoaderError $e) {
|
||||
$template = null;
|
||||
}
|
||||
|
||||
if (null !== $template && '' !== $path = $template->getSourceContext()->getPath()) {
|
||||
$this->data['template_paths'][$name] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($profile as $p) {
|
||||
$templateFinder($p);
|
||||
}
|
||||
};
|
||||
$templateFinder($this->profile);
|
||||
}
|
||||
|
||||
public function getTime()
|
||||
@@ -59,6 +97,11 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
|
||||
return $this->getComputedData('template_count');
|
||||
}
|
||||
|
||||
public function getTemplatePaths()
|
||||
{
|
||||
return $this->data['template_paths'];
|
||||
}
|
||||
|
||||
public function getTemplates()
|
||||
{
|
||||
return $this->getComputedData('templates');
|
||||
@@ -80,15 +123,15 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
|
||||
$dump = $dumper->dump($this->getProfile());
|
||||
|
||||
// needed to remove the hardcoded CSS styles
|
||||
$dump = str_replace(array(
|
||||
$dump = str_replace([
|
||||
'<span style="background-color: #ffd">',
|
||||
'<span style="color: #d44">',
|
||||
'<span style="background-color: #dfd">',
|
||||
), array(
|
||||
], [
|
||||
'<span class="status-warning">',
|
||||
'<span class="status-error">',
|
||||
'<span class="status-success">',
|
||||
), $dump);
|
||||
], $dump);
|
||||
|
||||
return new Markup($dump, 'UTF-8');
|
||||
}
|
||||
@@ -96,7 +139,11 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
|
||||
public function getProfile()
|
||||
{
|
||||
if (null === $this->profile) {
|
||||
$this->profile = unserialize($this->data['profile']);
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
$this->profile = unserialize($this->data['profile'], ['allowed_classes' => ['Twig_Profiler_Profile', 'Twig\Profiler\Profile']]);
|
||||
} else {
|
||||
$this->profile = unserialize($this->data['profile']);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->profile;
|
||||
@@ -113,13 +160,13 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
|
||||
|
||||
private function computeData(Profile $profile)
|
||||
{
|
||||
$data = array(
|
||||
$data = [
|
||||
'template_count' => 0,
|
||||
'block_count' => 0,
|
||||
'macro_count' => 0,
|
||||
);
|
||||
];
|
||||
|
||||
$templates = array();
|
||||
$templates = [];
|
||||
foreach ($profile as $p) {
|
||||
$d = $this->computeData($p);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user