Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bug #27042 [DI] Handle invalid extension configuration class (ro0NL)
This PR was merged into the 4.1-dev branch.

Discussion
----------

[DI] Handle invalid extension configuration class

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | yes
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #27040
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

cc @iltar @stof

Commits
-------

5ce90bd [DI] Handle invalid bundle configuration class
  • Loading branch information
fabpot committed Apr 25, 2018
2 parents 817da64 + 5ce90bd commit 8a35c8b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions UPGRADE-4.1.md
Expand Up @@ -23,6 +23,7 @@ DependencyInjection
-------------------

* Deprecated the `TypedReference::canBeAutoregistered()` and `TypedReference::getRequiringClass()` methods.
* Deprecated support for auto-discovered extension configuration class which does not implement `ConfigurationInterface`.

EventDispatcher
---------------
Expand Down
1 change: 1 addition & 0 deletions UPGRADE-5.0.md
Expand Up @@ -20,6 +20,7 @@ DependencyInjection
-------------------

* Removed the `TypedReference::canBeAutoregistered()` and `TypedReference::getRequiringClass()` methods.
* Removed support for auto-discovered extension configuration class which does not implement `ConfigurationInterface`.

EventDispatcher
---------------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ CHANGELOG
* added support for service's decorators autowiring
* deprecated the `TypedReference::canBeAutoregistered()` and `TypedReference::getRequiringClass()` methods
* environment variables are validated when used in extension configuration
* deprecated support for auto-discovered extension configuration class which does not implement `ConfigurationInterface`

4.0.0
-----
Expand Down
16 changes: 14 additions & 2 deletions src/Symfony/Component/DependencyInjection/Extension/Extension.php
Expand Up @@ -82,11 +82,23 @@ public function getConfiguration(array $config, ContainerBuilder $container)
$class = get_class($this);
$class = substr_replace($class, '\Configuration', strrpos($class, '\\'));
$class = $container->getReflectionClass($class);
$constructor = $class ? $class->getConstructor() : null;

if ($class && (!$constructor || !$constructor->getNumberOfRequiredParameters())) {
if (!$class) {
return null;
}

if (!$class->implementsInterface(ConfigurationInterface::class)) {
@trigger_error(sprintf('Not implementing "%s" in the extension configuration class "%s" is deprecated since Symfony 4.1.', ConfigurationInterface::class, $class->getName()), E_USER_DEPRECATED);
//throw new LogicException(sprintf('The extension configuration class "%s" must implement "%s".', $class->getName(), ConfigurationInterface::class));

return null;
}

if (!($constructor = $class->getConstructor()) || !$constructor->getNumberOfRequiredParameters()) {
return $class->newInstance();
}

return null;
}

final protected function processConfiguration(ConfigurationInterface $configuration, array $configs)
Expand Down

0 comments on commit 8a35c8b

Please sign in to comment.