WebProfilerExtension.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\Component\HttpKernel\DependencyInjection\Extension;
  12. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\Config\FileLocator;
  15. use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
  16. /**
  17. * WebProfilerExtension.
  18. *
  19. * Usage:
  20. *
  21. * <webprofiler:config
  22. * toolbar="true"
  23. * intercept-redirects="true"
  24. * />
  25. *
  26. * @author Fabien Potencier <fabien@symfony.com>
  27. */
  28. class WebProfilerExtension extends Extension
  29. {
  30. /**
  31. * Loads the web profiler configuration.
  32. *
  33. * @param array $configs An array of configuration settings
  34. * @param ContainerBuilder $container A ContainerBuilder instance
  35. */
  36. public function load(array $configs, ContainerBuilder $container)
  37. {
  38. $configuration = $this->getConfiguration($configs, $container);
  39. $config = $this->processConfiguration($configuration, $configs);
  40. $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  41. $loader->load('profiler.xml');
  42. $loader->load('toolbar.xml');
  43. $container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
  44. if (!$config['toolbar']) {
  45. $mode = WebDebugToolbarListener::DISABLED;
  46. } else {
  47. $mode = WebDebugToolbarListener::ENABLED;
  48. }
  49. $container->setParameter('web_profiler.debug_toolbar.mode', $mode);
  50. $container->setParameter('web_profiler.debug_toolbar.position', $config['position']);
  51. }
  52. /**
  53. * Returns the base path for the XSD files.
  54. *
  55. * @return string The XSD base path
  56. */
  57. public function getXsdValidationBasePath()
  58. {
  59. return __DIR__.'/../Resources/config/schema';
  60. }
  61. public function getNamespace()
  62. {
  63. return 'http://symfony.com/schema/dic/webprofiler';
  64. }
  65. }