WebProfilerExtension.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Config\Resource\FileResource;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\Config\FileLocator;
  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. public function load(array $configs, ContainerBuilder $container)
  31. {
  32. foreach ($configs as $config) {
  33. $this->doConfigLoad($config, $container);
  34. }
  35. }
  36. /**
  37. * Loads the web profiler configuration.
  38. *
  39. * @param array $config An array of configuration settings
  40. * @param ContainerBuilder $container A ContainerBuilder instance
  41. */
  42. protected function doConfigLoad(array $config, ContainerBuilder $container)
  43. {
  44. if (isset($config['toolbar'])) {
  45. if ($config['toolbar']) {
  46. if (!$container->hasDefinition('debug.toolbar')) {
  47. $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  48. $loader->load('toolbar.xml');
  49. }
  50. } elseif ($container->hasDefinition('debug.toolbar')) {
  51. $container->getDefinition('debug.toolbar')->clearTags();
  52. }
  53. }
  54. foreach (array('intercept-redirects', 'intercept_redirects') as $key) {
  55. if (isset($config[$key])) {
  56. $container->setParameter('debug.toolbar.intercept_redirects', (Boolean) $config[$key]);
  57. }
  58. }
  59. }
  60. /**
  61. * Returns the base path for the XSD files.
  62. *
  63. * @return string The XSD base path
  64. */
  65. public function getXsdValidationBasePath()
  66. {
  67. return __DIR__.'/../Resources/config/schema';
  68. }
  69. public function getNamespace()
  70. {
  71. return 'http://symfony.com/schema/dic/webprofiler';
  72. }
  73. }