8136fa5050
This PR was squashed before being merged into the 3.4 branch (closes #24290).
Discussion
----------
Adding Definition::addError() and a compiler pass to throw errors as exceptions
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes & no
| New feature? | yes
| BC breaks? | no
| Deprecations? | yes (very minor)
| Tests pass? | yes
| Fixed tickets | #23606
| License | MIT
| Doc PR | Not needed
Hi guys!
Very simple: when there is an error with a Definition, we can now call `Definition::addError()` instead of throwing an exception. Then, a new compiler pass (after removal) actually throws an exception. The advantage is that we can avoid throwing exceptions for services that are ultimately removed from the container. That's important for auto-registration, where we commonly register all services in `src/`... but then many of them are removed later.
A few interesting notes:
- We can probably convert more things from exceptions to `Definition::addError()`. I've only converted autowiring errors and things in `CheckArgumentsValidityPass` (that was necessary because it was throwing exceptions in some cases due to autowiring failing... which was the true error)
- `Definition` can hold multiple errors, but I'm only showing the first error in the exception message. The reason is clarity: I think usually the first error is the most (or only) important. But having `Definition::addError()` avoids the possibility of a later error overriding an earlier one
Cheers!
Commits
-------
|
||
---|---|---|
.. | ||
Argument | ||
Compiler | ||
Config | ||
Dumper | ||
Exception | ||
Extension | ||
LazyProxy | ||
Loader | ||
ParameterBag | ||
Tests | ||
.gitignore | ||
Alias.php | ||
CHANGELOG.md | ||
ChildDefinition.php | ||
composer.json | ||
Container.php | ||
ContainerAwareInterface.php | ||
ContainerAwareTrait.php | ||
ContainerBuilder.php | ||
ContainerInterface.php | ||
Definition.php | ||
DefinitionDecorator.php | ||
EnvVarProcessor.php | ||
EnvVarProcessorInterface.php | ||
ExpressionLanguage.php | ||
ExpressionLanguageProvider.php | ||
LICENSE | ||
Parameter.php | ||
phpunit.xml.dist | ||
README.md | ||
Reference.php | ||
ResettableContainerInterface.php | ||
ServiceLocator.php | ||
ServiceSubscriberInterface.php | ||
TaggedContainerInterface.php | ||
TypedReference.php | ||
Variable.php |
DependencyInjection Component
The DependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.