merged branch vicb/sfcc (PR #6148)
This PR was merged into the master branch.
Commits
-------
7f16c1f
[HttpKernel] Add DI extension configs as ressources when possible
Discussion
----------
[HttpKernel] Add DI extension configs as ressources when possible
/cc @rdohms @richardmiller
---------------------------------------------------------------------------
by vicb at 2012-11-30T11:57:48Z
btw @fabpot what about having a base class for `Extension` in the DI ? Would make it easier to re-use it when using standalone components, Di and (the suggested) Config as the greatest part of the class is not HttpKernel specific.
---------------------------------------------------------------------------
by fabpot at 2012-12-06T08:47:28Z
@vicb your suggestion makes sense.
Can you also explain the goal of this PR?
---------------------------------------------------------------------------
by vicb at 2012-12-06T09:01:58Z
The goal of this PR is to avoid having to sfcc when you modify a DI extension configuration. I think @rdohms got trapped.
---------------------------------------------------------------------------
by vicb at 2012-12-06T09:08:08Z
see https://twitter.com/rdohms/status/274059267428978688
---------------------------------------------------------------------------
by stof at 2012-12-06T09:20:54Z
I thought about it several times but never took time to implement it. It is annoying to have to clear the cache when you modify a default value in the Configuration class. So +1
This commit is contained in:
commit
64b76ba1b4
@ -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()
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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();
|
||||
|
||||
|
Reference in New Issue
Block a user