[HttpKernel] Add DI extension configs as ressources when possible

This commit is contained in:
Victor Berchet 2012-11-29 14:58:56 +01:00
parent 50a62da114
commit 7f16c1f5bc
3 changed files with 11 additions and 20 deletions

View File

@ -22,22 +22,12 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
*/
class Configuration implements ConfigurationInterface
{
private $debug;
/**
* Constructor
*
* @param Boolean $debug Whether to use the debug mode
*/
public function __construct($debug)
{
$this->debug = (Boolean) $debug;
}
/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
* @return TreeBuilder The tree builder
*
* @throws \RuntimeException When using the deprecated 'charset' setting
*/
public function getConfigTreeBuilder()
{
@ -54,7 +44,7 @@ class Configuration implements ConfigurationInterface
$message = 'The charset setting is deprecated. Just remove it from your configuration file.';
if ('UTF-8' !== $v) {
$message .= sprintf(' You need to define a getCharset() method in your Application Kernel class that returns "%s".', $v);
$message .= sprintf('You need to define a getCharset() method in your Application Kernel class that returns "%s".', $v);
}
throw new \RuntimeException($message);
@ -384,7 +374,7 @@ class Configuration implements ConfigurationInterface
->children()
->scalarNode('cache')->defaultValue('file')->end()
->scalarNode('file_cache_dir')->defaultValue('%kernel.cache_dir%/annotations')->end()
->booleanNode('debug')->defaultValue($this->debug)->end()
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
->end()
->end()
->end()

View File

@ -141,11 +141,6 @@ class FrameworkExtension extends Extension
));
}
public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($container->getParameter('kernel.debug'));
}
/**
* Loads Form configuration.
*

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\DependencyInjection;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
@ -84,6 +85,8 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn
* This can be overridden in a sub-class to specify the alias manually.
*
* @return string The alias
*
* @throws \BadMethodCallException When the extension name does not follow conventions
*/
public function getAlias()
{
@ -113,6 +116,9 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn
$class = $namespace . '\\Configuration';
if (class_exists($class)) {
$r = new \ReflectionClass($class);
$container->addResource(new FileResource($r->getFileName()));
if (!method_exists($class, '__construct')) {
$configuration = new $class();