Skip to content

Commit

Permalink
[Config] added ability to set info message and example to node defini…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
kbond committed Dec 13, 2011
1 parent fd12796 commit 73ac773
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 11 deletions.
Expand Up @@ -31,7 +31,7 @@ class DoctrineExtension extends AbstractDoctrineExtension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration($container->getParameter('kernel.debug'));
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

if (!empty($config['dbal'])) {
Expand Down Expand Up @@ -412,4 +412,9 @@ public function getNamespace()
{
return 'http://symfony.com/schema/dic/doctrine';
}

public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($container->getParameter('kernel.debug'));
}
}
Expand Up @@ -13,6 +13,8 @@

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand Down Expand Up @@ -56,7 +58,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->setAlias('debug.controller_resolver', 'controller_resolver');
}

$configuration = new Configuration($container->getParameter('kernel.debug'));
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

if (isset($config['charset'])) {
Expand Down Expand Up @@ -146,6 +148,11 @@ public function load(array $configs, ContainerBuilder $container)
));
}

public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($container->getParameter('kernel.debug'));
}

/**
* Loads Form configuration.
*
Expand Down
Expand Up @@ -36,7 +36,7 @@ class MonologExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

if (isset($config['handlers'])) {
Expand Down
Expand Up @@ -48,9 +48,9 @@ public function load(array $configs, ContainerBuilder $container)
if (!array_filter($configs)) {
return;
}

// normalize and merge the actual configuration
$mainConfig = new MainConfiguration($this->factories, $this->userProviderFactories);
$mainConfig = $this->getConfiguration($configs, $container);

$config = $this->processConfiguration($mainConfig, $configs);

// load services
Expand Down Expand Up @@ -569,5 +569,11 @@ public function getNamespace()
{
return 'http://symfony.com/schema/dic/security';
}

public function getConfiguration(array $config, ContainerBuilder $container)
{
// first assemble the factories
return new MainConfiguration($this->factories, $this->userProviderFactories);
}
}

Expand Up @@ -43,7 +43,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('swiftmailer.xml');
$container->setAlias('mailer', 'swiftmailer.mailer');

$configuration = new Configuration($container->getParameter('kernel.debug'));
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

if (null === $config['transport']) {
Expand Down Expand Up @@ -145,4 +145,9 @@ public function getNamespace()
{
return 'http://symfony.com/schema/dic/swiftmailer';
}

public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($container->getParameter('kernel.debug'));
}
}
Expand Up @@ -36,7 +36,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('twig.xml');

$configuration = new Configuration();
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('twig.exception_listener.controller', $config['exception_controller']);
Expand Down
Expand Up @@ -39,7 +39,7 @@ class WebProfilerExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Config/Definition/ArrayNode.php
Expand Up @@ -49,6 +49,16 @@ public function __construct($name, NodeInterface $parent = null)
$this->allowNewKeys = true;
$this->performDeepMerging = true;
}

/**
* Retrieves the children of this node.
*
* @return array The children
*/
public function getChildren()
{
return $this->children;
}

/**
* Sets the xml remappings that should be performed.
Expand Down
42 changes: 42 additions & 0 deletions src/Symfony/Component/Config/Definition/BaseNode.php
Expand Up @@ -29,6 +29,8 @@ abstract class BaseNode implements NodeInterface
protected $allowOverwrite;
protected $required;
protected $equivalentValues;
protected $info;
protected $example;

/**
* Constructor.
Expand All @@ -51,6 +53,46 @@ public function __construct($name, NodeInterface $parent = null)
$this->required = false;
$this->equivalentValues = array();
}

/**
* Sets info message
*
* @param string $info The info text
*/
public function setInfo($info)
{
$this->info = $info;
}

/**
* Returns info message
*
* @return string The info text
*/
public function getInfo()
{
return $this->info;
}

/**
* Sets the example configuration for this node.
*
* @param array $example
*/
public function setExample($example)
{
$this->example = $example;
}

/**
* Retrieves the example configuration for this node.
*
* @return mixed The example
*/
public function getExample()
{
return $this->example;
}

/**
* Adds an equivalent value.
Expand Down
Expand Up @@ -32,6 +32,8 @@ abstract class NodeDefinition implements NodeParentInterface
protected $trueEquivalent;
protected $falseEquivalent;
protected $parent;
protected $info;
protected $example;

/**
* Constructor
Expand Down Expand Up @@ -60,6 +62,34 @@ public function setParent(NodeParentInterface $parent)

return $this;
}

/**
* Sets info message
*
* @param string $info The info text
*
* @return NodeDefinition
*/
public function setInfo($info)
{
$this->info = $info;

return $this;
}

/**
* Sets example configuration
*
* @param example $example
*
* @return NodeDefinition
*/
public function setExample($example)
{
$this->example = $example;

return $this;
}

/**
* Returns the parent node.
Expand Down Expand Up @@ -91,8 +121,13 @@ public function getNode($forceRootNode = false)
if (null !== $this->validation) {
$this->validation->rules = ExprBuilder::buildExpressions($this->validation->rules);
}

$node = $this->createNode();

$node->setInfo($this->info);
$node->setExample($this->example);

return $this->createNode();
return $node;
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/Symfony/Component/Config/Definition/PrototypedArrayNode.php
Expand Up @@ -78,6 +78,16 @@ public function setKeyAttribute($attribute, $remove = true)
$this->removeKeyAttribute = $remove;
}

/**
* Retrieves the name of the attribute which value should be used as key.
*
* @return string The name of the attribute
*/
public function getKeyAttribute()
{
return $this->keyAttribute;
}

/**
* Sets the default value of this node.
*
Expand Down Expand Up @@ -122,6 +132,16 @@ public function setPrototype(PrototypeNodeInterface $node)
{
$this->prototype = $node;
}

/**
* Retrieves the prototype
*
* @return PrototypeNodeInterface The prototype
*/
public function getPrototype()
{
return $this->prototype;
}

/**
* Disable adding concrete children for prototyped nodes.
Expand Down
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Extension;

use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* ConfigurationExtensionInterface is the interface implemented by container extension classes.
*
* @author Kevin Bond <kevinbond@gmail.com>
*/
interface ConfigurationExtensionInterface
{
/**
* Returns extension configuration
*
* @param array $config $config An array of configuration values
* @param ContainerBuilder $container A ContainerBuilder instance
*
* @return ConfigurationInterface|null The configuration or null
*/
function getConfiguration(array $config, ContainerBuilder $container);
}
Expand Up @@ -5,6 +5,9 @@
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Container;

/*
Expand All @@ -21,7 +24,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
abstract class Extension implements ExtensionInterface
abstract class Extension implements ExtensionInterface, ConfigurationExtensionInterface
{
private $classes = array();

Expand Down Expand Up @@ -100,4 +103,24 @@ protected final function processConfiguration(ConfigurationInterface $configurat

return $processor->processConfiguration($configuration, $configs);
}

/**
* {@inheritDoc}
*/
public function getConfiguration(array $config, ContainerBuilder $container)
{
$reflected = new \ReflectionClass($this);
$namespace = $reflected->getNamespaceName();

$class = $namespace . '\\Configuration';
if (class_exists($class)) {
if (!method_exists($class, '__construct')) {
$configuration = new $class();

return $configuration;
}
}

return null;
}
}

0 comments on commit 73ac773

Please sign in to comment.