Skip to content

Zend config #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 commits merged into from
Feb 24, 2011
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[ZendBundle] Added a Configuration class
  • Loading branch information
stof committed Feb 24, 2011
commit 192583a225158c2f0d3022f9ec768806b36b4003
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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 <stof@notk.org>
*/
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have chosen INFO as the default priority as we only use INFO or DEBUG in the core.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used the level defined by default in the XML file (where I did not removed it but I should have)
I will change it.

->scalarNode('path')->defaultValue('%kernel.logs_dir%/%kernel.environment%.log')->end()
->booleanNode('log_errors')->defaultFalse()->end()
->end()
;

return $treeBuilder->buildTree();
}
}
52 changes: 14 additions & 38 deletions src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
*
* <zend:logger priority="info" path="/path/to/some.log" />
*
* @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');
}
}
}
}
Expand Down
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