WebProfilerExtension.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\WebProfilerBundle\DependencyInjection;
  11. use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
  12. use Symfony\Component\Config\FileLocator;
  13. use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Extension\Extension;
  16. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  17. use Symfony\Component\DependencyInjection\Reference;
  18. /**
  19. * WebProfilerExtension.
  20. *
  21. * Usage:
  22. *
  23. * <webprofiler:config
  24. * toolbar="true"
  25. * intercept-redirects="true"
  26. * />
  27. *
  28. * @author Fabien Potencier <fabien@symfony.com>
  29. */
  30. class WebProfilerExtension extends Extension
  31. {
  32. /**
  33. * Loads the web profiler configuration.
  34. *
  35. * @param array $configs An array of configuration settings
  36. */
  37. public function load(array $configs, ContainerBuilder $container)
  38. {
  39. $configuration = $this->getConfiguration($configs, $container);
  40. $config = $this->processConfiguration($configuration, $configs);
  41. $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  42. $loader->load('profiler.php');
  43. if ($config['toolbar'] || $config['intercept_redirects']) {
  44. $loader->load('toolbar.php');
  45. $container->getDefinition('web_profiler.debug_toolbar')->replaceArgument(4, $config['excluded_ajax_paths']);
  46. $container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
  47. $container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED);
  48. }
  49. $container->getDefinition('debug.file_link_formatter')
  50. ->replaceArgument(3, new ServiceClosureArgument(new Reference('debug.file_link_formatter.url_format')));
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function getXsdValidationBasePath()
  56. {
  57. return __DIR__.'/../Resources/config/schema';
  58. }
  59. public function getNamespace()
  60. {
  61. return 'http://symfony.com/schema/dic/webprofiler';
  62. }
  63. }