This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection
Nicolas Grekas 8136fa5050 feature #24290 Adding Definition::addError() and a compiler pass to throw errors as exceptions (weaverryan)
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
-------

a85b37a Adding Definition::addError() and a compiler pass to throw errors as exceptions
2017-09-25 11:29:01 +02:00
..
Argument [DependencyInjection] Support local binding 2017-08-09 11:26:25 +02:00
Compiler feature #24290 Adding Definition::addError() and a compiler pass to throw errors as exceptions (weaverryan) 2017-09-25 11:29:01 +02:00
Config Merge branch '3.2' into 3.3 2017-06-02 11:51:43 +02:00
Dumper [DI] Turn services and aliases private by default, with BC layer 2017-09-19 11:28:48 +02:00
Exception Allow to get alternatives when ServiceNotFoundException occurs. 2017-08-17 15:22:42 +03:00
Extension Merge branch '2.8' into 3.3 2017-09-15 12:08:59 +02:00
LazyProxy [DI][ProxyManager] Pass the factory code to execute to DumperInterface::getProxyFactoryCode() 2017-07-27 19:12:50 +02:00
Loader [DI] Add "PHP fluent format" for configuring the container 2017-09-20 09:09:19 +02:00
ParameterBag Merge branch '3.3' into 3.4 2017-09-11 13:45:17 -07:00
Tests feature #24290 Adding Definition::addError() and a compiler pass to throw errors as exceptions (weaverryan) 2017-09-25 11:29:01 +02:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
Alias.php [DI] Turn services and aliases private by default, with BC layer 2017-09-19 11:28:48 +02:00
CHANGELOG.md [HttpKernel][DI] Enable Kernel to implement CompilerPassInterface 2017-09-20 15:13:20 +02:00
ChildDefinition.php [DI] Fix private-by-default BC layer 2017-09-19 23:28:23 +02:00
composer.json minor #22913 [Yaml] Deprecate tags using colon (GuilhemN) 2017-08-04 15:29:48 +02:00
Container.php Merge branch '2.7' into 2.8 2017-09-15 11:59:38 +02:00
ContainerAwareInterface.php [DI] Clean a phpdoc 2015-11-04 19:12:53 +01:00
ContainerAwareTrait.php Merge branch '2.3' into 2.7 2015-11-04 19:50:51 +01:00
ContainerBuilder.php [DI] Fix private-by-default BC layer 2017-09-19 23:28:23 +02:00
ContainerInterface.php [DI] Add ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE 2017-08-31 23:26:27 +02:00
Definition.php Adding Definition::addError() and a compiler pass to throw errors as exceptions 2017-09-25 11:28:57 +02:00
DefinitionDecorator.php [DI] Fix Cannot declare class ...\DefinitionDecorator, because the name is already in use 2017-05-07 11:42:51 +02:00
EnvVarProcessor.php added missing @author tag for new class 2017-09-24 15:33:47 +02:00
EnvVarProcessorInterface.php [DI] Allow processing env vars 2017-09-07 08:08:52 +02:00
ExpressionLanguage.php [DI] Fix using private services in expressions 2017-07-25 13:50:49 +02:00
ExpressionLanguageProvider.php [DI] Fix using private services in expressions 2017-07-25 13:50:49 +02:00
LICENSE updated LICENSE year 2017-01-02 12:30:00 -08:00
Parameter.php [DependencyInjection] fix phpDoc 2016-04-11 16:45:49 +02:00
phpunit.xml.dist fail when detecting risky tests 2017-04-12 09:39:27 +02:00
README.md Updated all the README files 2016-03-04 08:12:06 +01:00
Reference.php [DI] Enhance DX by throwing instead of triggering a deprecation notice 2017-03-28 08:18:44 +02:00
ResettableContainerInterface.php Implement resettable containers 2015-07-22 10:09:28 +02:00
ServiceLocator.php [DI] Remove useless state from ServiceLocator 2017-03-16 19:18:58 +01:00
ServiceSubscriberInterface.php [DI] Add and wire ServiceSubscriberInterface 2017-03-22 20:26:09 +01:00
TaggedContainerInterface.php remove api tags from code 2015-09-28 19:11:22 +02:00
TypedReference.php [DI] Restrict autowired registration to "same-vendor" namespaces 2017-04-06 11:28:30 +02:00
Variable.php [DependencyInjection] fix phpDoc 2016-04-11 16:45:49 +02:00

DependencyInjection Component

The DependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.

Resources