3 namespace Drupal\webprofiler\Compiler;
5 use Drupal\Core\StreamWrapper\PublicStream;
6 use Symfony\Component\DependencyInjection\Reference;
7 use Symfony\Component\DependencyInjection\ContainerBuilder;
8 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13 class ProfilerPass implements CompilerPassInterface {
16 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
18 * @throws \InvalidArgumentException
20 public function process(ContainerBuilder $container) {
21 // configure the profiler service
22 if (FALSE === $container->hasDefinition('profiler')) {
26 $definition = $container->getDefinition('profiler');
28 $collectors = new \SplPriorityQueue();
30 foreach ($container->findTaggedServiceIds('data_collector') as $id => $attributes) {
31 $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
34 if (isset($attributes[0]['template'])) {
35 if (!isset($attributes[0]['id'])) {
36 throw new \InvalidArgumentException(sprintf('Data collector service "%s" must have an id attribute in order to specify a template', $id));
38 if (!isset($attributes[0]['title'])) {
39 throw new \InvalidArgumentException(sprintf('Data collector service "%s" must have a title attribute', $id));
44 $attributes[0]['template'],
45 $attributes[0]['title']
49 $collectors->insert([$id, $template], [-$priority, --$order]);
53 foreach ($collectors as $collector) {
54 $definition->addMethodCall('add', [new Reference($collector[0])]);
55 $templates[$collector[0]] = $collector[1];
58 $container->setParameter('data_collector.templates', $templates);
60 // set parameter to store the public folder path
61 $path = 'file:' . DRUPAL_ROOT . '/' . PublicStream::basePath() . '/profiler';
62 $container->setParameter('data_collector.storage', $path);