This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ProfilerPass.php

52 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Adds tagged data_collector services to profiler service
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class ProfilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (false === $container->hasDefinition('profiler')) {
return;
}
$definition = $container->getDefinition('profiler');
2011-01-17 10:09:31 +00:00
$collectors = array();
$priorities = array();
$templates = array();
foreach ($container->findTaggedServiceIds('data_collector') as $id => $attributes) {
2011-01-17 10:09:31 +00:00
$priorities[] = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
$collectors[] = $id;
if (isset($attributes[0]['template'])) {
$templates[] = $attributes[0]['template'];
}
}
2011-01-17 10:09:31 +00:00
array_multisort($priorities, SORT_DESC, $collectors, SORT_DESC, $templates);
foreach ($collectors as $collector) {
$definition->addMethodCall('add', array(new Reference($collector)));
}
$container->setParameter('data_collector.templates', array_combine($collectors, $templates));
}
}