WebProfilerExtension.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  45. if (isset($config['toolbar'])) {
  46. if ($config['toolbar']) {
  47. if (!$container->hasDefinition('debug.toolbar')) {
  48. $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  49. $loader->load('toolbar.xml');
  50. }
  51. } elseif ($container->hasDefinition('debug.toolbar')) {
  52. $container->getDefinition('debug.toolbar')->clearTags();
  53. }
  54. }
  55. foreach (array('intercept-redirects', 'intercept_redirects') as $key) {
  56. if (isset($config[$key])) {
  57. $container->setParameter('debug.toolbar.intercept_redirects', (Boolean) $config[$key]);
  58. }
  59. }
  60. }
  61. /**
  62. * Returns the base path for the XSD files.
  63. *
  64. * @return string The XSD base path
  65. */
  66. public function getXsdValidationBasePath()
  67. {
  68. return __DIR__.'/../Resources/config/schema';
  69. }
  70. public function getNamespace()
  71. {
  72. return 'http://symfony.com/schema/dic/webprofiler';
  73. }
  74. }