ZendExtension.php 3.1 KB

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