From 192583a225158c2f0d3022f9ec768806b36b4003 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 24 Feb 2011 17:38:40 +0100 Subject: [PATCH 1/2] [ZendBundle] Added a Configuration class --- .../DependencyInjection/Configuration.php | 48 +++++++++++++++++ .../DependencyInjection/ZendExtension.php | 52 +++++-------------- 2 files changed, 62 insertions(+), 38 deletions(-) create mode 100644 src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php diff --git a/src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php new file mode 100644 index 0000000000000..63d647ba86fb8 --- /dev/null +++ b/src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\ZendBundle\DependencyInjection; + +use Symfony\Component\Config\Definition\Builder\NodeBuilder; +use Symfony\Component\Config\Definition\Builder\TreeBuilder; + +/** + * This class contains the configuration information for the bundle + * + * This information is solely responsible for how the different configuration + * sections are normalized, and merged. + * + * @author Christophe Coevoet + */ +class Configuration +{ + /** + * Generates the configuration tree. + * + * @return \Symfony\Component\Config\Definition\NodeInterface + */ + public function getConfigTree() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('zend', 'array'); + + $rootNode + ->arrayNode('logger') + ->canBeUnset() + ->scalarNode('priority')->defaultValue('CRIT')->end() + ->scalarNode('path')->defaultValue('%kernel.logs_dir%/%kernel.environment%.log')->end() + ->booleanNode('log_errors')->defaultFalse()->end() + ->end() + ; + + return $treeBuilder->buildTree(); + } +} diff --git a/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php b/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php index 8656484013d7a..c21d3e2a0c6e3 100644 --- a/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php +++ b/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php @@ -15,6 +15,7 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Definition\Processor; /** * ZendExtension is an extension for the Zend Framework libraries. @@ -37,52 +38,27 @@ class ZendExtension extends Extension */ public function load(array $configs, ContainerBuilder $container) { - $first = true; - foreach ($configs as $config) { - if (!isset($config['logger'])) { - continue; - } - - if ($first) { - $first = false; + $configuration = new Configuration(); + $processor = new Processor(); + $config = $processor->process($configuration->getConfigTree(), $configs); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('logger.xml'); - $container->setAlias('logger', 'zend.logger'); - } - - $this->registerLoggerConfiguration($config, $container); - } - } + if (isset($config['logger'])) { + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('logger.xml'); + $container->setAlias('logger', 'zend.logger'); - /** - * Loads the logger configuration. - * - * Usage example: - * - * - * - * @param array $config An array of configuration settings - * @param ContainerBuilder $container A ContainerBuilder instance - */ - protected function registerLoggerConfiguration($config, ContainerBuilder $container) - { - $config = $config['logger']; + $config = $config['logger']; - if (isset($config['priority'])) { $container->setParameter('zend.logger.priority', is_int($config['priority']) ? $config['priority'] : constant('\\Zend\\Log\\Logger::'.strtoupper($config['priority']))); - } - - if (isset($config['path'])) { $container->setParameter('zend.logger.path', $config['path']); - } - if (isset($config['log_errors'])) { $definition = $container->findDefinition('zend.logger'); - if (false === $config['log_errors'] && $definition->hasMethodCall('registerErrorHandler')) { - $container->findDefinition('zend.logger')->removeMethodCall('registerErrorHandler'); - } else { + if ($config['log_errors']) { $container->findDefinition('zend.logger')->addMethodCall('registerErrorHandler'); + } else { + if ($definition->hasMethodCall('registerErrorHandler')) { + $container->findDefinition('zend.logger')->removeMethodCall('registerErrorHandler'); + } } } } From 0488ebc2e81f1346eab07a918aed63a252188273 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 24 Feb 2011 17:48:41 +0100 Subject: [PATCH 2/2] Changed default priority to INFO --- .../Bundle/ZendBundle/DependencyInjection/Configuration.php | 2 +- src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php index 63d647ba86fb8..e97ea8e93980e 100644 --- a/src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php @@ -37,7 +37,7 @@ public function getConfigTree() $rootNode ->arrayNode('logger') ->canBeUnset() - ->scalarNode('priority')->defaultValue('CRIT')->end() + ->scalarNode('priority')->defaultValue('INFO')->end() ->scalarNode('path')->defaultValue('%kernel.logs_dir%/%kernel.environment%.log')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() diff --git a/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml b/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml index ec1d5a488b5c8..2fcfda890b0b3 100644 --- a/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml +++ b/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml @@ -6,7 +6,6 @@ Symfony\Bundle\ZendBundle\Logger\Logger - Zend\Log\Logger::CRIT true Symfony\Bundle\ZendBundle\Logger\DebugLogger Zend\Log\Writer\Stream pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy