ZendExtension.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\ZendBundle\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. /**
  16. * ZendExtension is an extension for the Zend Framework libraries.
  17. *
  18. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  19. */
  20. class ZendExtension extends Extension
  21. {
  22. /**
  23. * Loads the Zend Framework configuration.
  24. *
  25. * Usage example:
  26. *
  27. * <zend:config>
  28. * <zend:logger priority="info" path="/path/to/some.log" />
  29. * </zend:config>
  30. *
  31. * @param array $config An array of configuration settings
  32. * @param ContainerBuilder $container A ContainerBuilder instance
  33. */
  34. public function load(array $configs, ContainerBuilder $container)
  35. {
  36. $first = true;
  37. foreach ($configs as $config) {
  38. if (!isset($config['logger'])) {
  39. continue;
  40. }
  41. if ($first) {
  42. $first = false;
  43. $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  44. $loader->load('logger.xml');
  45. $container->setAlias('logger', 'zend.logger');
  46. }
  47. $this->registerLoggerConfiguration($config, $container);
  48. }
  49. }
  50. /**
  51. * Loads the logger configuration.
  52. *
  53. * Usage example:
  54. *
  55. * <zend:logger priority="info" path="/path/to/some.log" />
  56. *
  57. * @param array $config An array of configuration settings
  58. * @param ContainerBuilder $container A ContainerBuilder instance
  59. */
  60. protected function registerLoggerConfiguration($config, ContainerBuilder $container)
  61. {
  62. $config = $config['logger'];
  63. if (isset($config['priority'])) {
  64. $container->setParameter('zend.logger.priority', is_int($config['priority']) ? $config['priority'] : constant('\\Zend\\Log\\Logger::'.strtoupper($config['priority'])));
  65. }
  66. if (isset($config['path'])) {
  67. $container->setParameter('zend.logger.path', $config['path']);
  68. }
  69. if (isset($config['log_errors'])) {
  70. $definition = $container->findDefinition('zend.logger');
  71. if (false === $config['log_errors'] && $definition->hasMethodCall('registerErrorHandler')) {
  72. $container->findDefinition('zend.logger')->removeMethodCall('registerErrorHandler');
  73. } else {
  74. $container->findDefinition('zend.logger')->addMethodCall('registerErrorHandler');
  75. }
  76. }
  77. }
  78. /**
  79. * Returns the base path for the XSD files.
  80. *
  81. * @return string The XSD base path
  82. */
  83. public function getXsdValidationBasePath()
  84. {
  85. return __DIR__.'/../Resources/config/schema';
  86. }
  87. public function getNamespace()
  88. {
  89. return 'http://www.symfony-project.org/schema/dic/zend';
  90. }
  91. public function getAlias()
  92. {
  93. return 'zend';
  94. }
  95. }