This PR was merged into the 2.7 branch.
Discussion
----------
fix some risky tests
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
PHPUnit 6 marks tests as risky when they have no assertions (and are not marked as skipped or incomplete). This PR will update our test suite accordingly.
Component that still need to be covered:
- [ ] Config
- [ ] Form
- [ ] HttpFoundation
- [ ] Security
- [ ] Workflow
Commits
-------
abf1787dcc fix some risky tests
* 3.2:
[Yaml] CS
[DI] Fix PhpDumper generated doc block
#20411 fix Yaml parsing for very long quoted strings
[Workflow] add Phpdoc for better IDE support
fix package name in conflict rule
improve message when workflows are missing
[Doctrine Bridge] fix priority for doctrine event listeners
Use PHP functions as array_map callbacks when possible
[Validator] revert wrong Phpdoc change
Use proper line endings
* 2.8:
[DI] Fix PhpDumper generated doc block
#20411 fix Yaml parsing for very long quoted strings
[Doctrine Bridge] fix priority for doctrine event listeners
Use PHP functions as array_map callbacks when possible
[Validator] revert wrong Phpdoc change
Use proper line endings
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Remove skipping magic for autowired methods
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no (master only)
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Wildcard based autowiring made it required to auto-skip methods that were not wireable.
Now that things need to be explicit (ie via the `@required` annotation, or via configuration), this "automagic" behavior is not required anymore.
Since it can lead to wtf moments ("*I* did *put that `@required` annotation, why is it ignored by autowiring?*"), I think we should remove it.
This also fixes another issue where configured method calls had their optional arguments wired, while we want only the constructor's to behave as such.
Commits
-------
a6bfe1c [DI] Remove skipping magic for autowired methods
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Introduce "container.service_locator" tag, replaces ServiceLocatorArgument
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no (master only)
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
I first started working on adding this new "container.service_locator" tag, so here it is.
It allows defining and dumping service-locator services properly, where it wasn't possible previously (you had to create a DI extension to do so.)
Then I realized that this allowed us to entirely drop `ServiceLocatorArgument` and replace it with the more flexible `ServiceClosureArgument`.
This makes things simpler overall, see diff stat.
Commits
-------
5d230b5871 [DI] Introduce "container.service_locator" tag, replaces ServiceLocatorArgument
This PR was squashed before being merged into the 3.3-dev branch (closes#21937).
Discussion
----------
[DependencyInjection] Handle void return types in closure-proxy
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | N/A
| License | MIT
| Doc PR | N/A
I recently got an error when registering an event listener that specifies a `void` return type. Dumping the container generates a closure proxy that always returns a value, which then conflicts with the return type hint.
E.G the following code is generated (some class names removed for readability)
```
$instance->addListener('kernel.view', /** @closure-proxy ... */ function (...\GetResponseForControllerResultEvent $event): void {
return ${($_ = isset($this->services[listener']) ? $this->services['listener'] : $this->get('listener')) && false ?: '_'}->onKernelView($event);
}, 128);
```
This then causes the error `A void function must not return a value in ...`
So void return types should be handled by removing the `return` inside the closure
Commits
-------
a5c5ad1 [DependencyInjection] Handle void return types in closure-proxy
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Allow extensions to create ServiceLocator as services
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
https://github.com/symfony/symfony/pull/21770/files?w=1
With this PR, DI extensions are able to create "service locator" services.
They are easily created as such:
```php
$container->register('my_service_locator', ServiceLocator::class)
->addArgument(array(
'exposed_id' => new ServiceClosureArgument(new Reference('internal_id')),
))
```
I already need this in two different PRs to come.
Commits
-------
1d9663326e [DI] Allow creating ServiceLocator-based services in extensions
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI][Router][DX] Invalidate routing cache when container parameters changed
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #21426
| License | MIT
| Doc PR | N/A
Supersedes #21443 but only for master.
Indeed, this implementation uses a new feature: a `ContainerParametersResource` which compares cached containers parameters (collected at some point, here by the `Router`) with current ones in the container.
On the contrary of the previous PR targeting 2.7, this will only invalidate routing cache when parameters actually used in the routes changed and will avoid always rebuilding the routing cache when the container is rebuilt, just to catch the edge case of someone modifying a parameter.
Commits
-------
fad4d9e2ef [DI][Router][DX] Invalidate routing cache when container parameters changed
This PR was squashed before being merged into the 3.3-dev branch (closes#21763).
Discussion
----------
[DI] Replace wildcard-based methods autowiring by `@required` annotation
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no (affects things that are only on master)
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
While playing a bit with new features in master around DI configuration, several people around me got bitten by wildcard-based autowiring. The typical example is adding `autowire: [set*]` in `_defaults`: use that on `resource: ../src/Command/` PSR4-based loading and boom, `setApplication` and `setHelperSet` will now be wrongly called. You could tell me "of course, don't to that" - but being bitten so early on a master-only feature makes me really unconfident that this will be easy enough for people after the release.
If wildcard-based autowiring is removed, then I don't see anymore the need for allowing arrays as in `autowire: [setFoo,getBar]`. Moreover, this array syntax has a core DX issue: it's a dead end as far as the learning curve is concerned. You learn it, then when becoming a more advanced dev, someone teaches you that you'd better use another syntax: explicit wiring.
And in fact, we don't need it at all, because something else already exists: just declare a method call, but don't define its arguments. If `autowire: true` is set, then the AutowiringPass already fills in the holes. There is only one tweak required to make this work: don't autowire optional arguments for method calls - or that'd be a BC break. To my PoV that's even better: this makes autowiring fit a "do the minimum to make it work" strategy. A really good one to me.
But there is still an issue: wildcard-based autowiring fits a need. Namely, it allows one to define a convention (eg. `'set*'`), and have all such methods that follow the convention be autowired. To me, this looks like doing it reverse (the DI config should adapt to the code, not reverse). So, to fill this need, let the declaration be in the source: just use an annotation!
This PR adds support for the `@required` annotation, borrowed from the Spring framework:
https://www.tutorialspoint.com/spring/spring_required_annotation.htm
Using the annotation is totally optional of course. If you do, *and if autowiring is on*, then it'll be autowired. If you don't, nothing changes: do manual wiring.
Even when not using autowiring, the annotation is still a nice hint for the consumer of your classes: it tells the reader that this method needs to be called for correct instantiation - thus lowering one drawback of setter injection (discoverability).
The implementation of the annotation parsing is done using a few regexp (no dep on any complex parser) - and works with inheritance, by leveraging the `@inheritdoc` tag (the default behavior being to *not* inherit anything from parent methods).
All in all, looking at the diff stats, it makes everything simpler. Good sign, isn't it?
Commits
-------
f286fcc25f [DI] Replace wildcard-based methods autowiring by `@required` annotation
9081699980 Revert "minor #21315 [DI][FrameworkBundle] Show autowired methods in descriptors (ogizanagi)"
This PR was merged into the 3.3-dev branch.
Discussion
----------
Fix DI test
| Q | A
| ------------- | ---
| Branch? | master
| Tests pass? | yes
Should fix appveyor/travis builds
Commits
-------
8740e44086 Fix DI test
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DependencyInjection] make the service container builder register its own self referencing definition
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | ~
| License | MIT
| Doc PR | ~
Commits
-------
9c97496b5f [DependencyInjection] make the service container builder register the definition of its related service container service (and aliases) in order to make compiler passes be able to reference the special service_container service.
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Simplify AutowirePass and other master-only cleanups
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
A few minor cleanups and fixes, and an overall simplification of AutowirePass.
Commits
-------
34e5cc7698 [DI] Simplify AutowirePass and other master-only cleanups
* 3.2:
[SecurityBundle] only pass relevant user provider
[Intl] Make tests pass after the ICU data update
[Intl] Update ICU data to 58.2
do not register the test listener twice
[DependencyInjection] removed dead code.
[Yaml] Stop replacing NULLs when merging
[WebServerBundle] fixed html attribute escape
* 2.8:
[SecurityBundle] only pass relevant user provider
[Intl] Make tests pass after the ICU data update
[Intl] Update ICU data to 58.2
do not register the test listener twice
[DependencyInjection] removed dead code.
[Yaml] Stop replacing NULLs when merging
[WebServerBundle] fixed html attribute escape
* 2.7:
[SecurityBundle] only pass relevant user provider
[Intl] Make tests pass after the ICU data update
[Intl] Update ICU data to 58.2
[DependencyInjection] removed dead code.
[Yaml] Stop replacing NULLs when merging
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Always consider abstract getters as autowiring candidates
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes (a missing part of getter autowiring really)
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
When a definition is set to be autowired with no method explicitly configured, we already wire the constructor.
We should also autowire abstract getters - with the same reasoning that makes us autowire the constructor: without concrete getters, the class is unusable. This just makes it usable again.
Commits
-------
8f246bde1d [DI] Always consider abstract getters as autowiring candidates
* 3.2:
Refactored other PHPUnit method calls to work with namespaced PHPUnit 6
Refactored other PHPUnit method calls to work with namespaced PHPUnit 6
Further refactorings to PHPUnit namespaces
resolve parameters in definition classes
* 2.8:
Refactored other PHPUnit method calls to work with namespaced PHPUnit 6
Further refactorings to PHPUnit namespaces
resolve parameters in definition classes
This PR was squashed before being merged into the 2.8 branch (closes#21663).
Discussion
----------
Updated PHPUnit namespaces
| Q | A
| ------------- | ---
| Branch? | 2.8
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Follow Up of #21564
Commits
-------
205ced4 Updated PHPUnit namespaces
* 3.2:
[DependencyInjection] Fix using autowiring types when there are more than 2 services
[DependencyInjection] Fix autowiring collisions detection
[DI] Bug in autowiring collisions detection
* 2.8:
[DependencyInjection] Fix using autowiring types when there are more than 2 services
[DependencyInjection] Fix autowiring collisions detection
[DI] Bug in autowiring collisions detection
This PR was merged into the 2.8 branch.
Discussion
----------
[DependencyInjection] Fix autowiring types when there are more than 2 services colliding
| Q | A
| ------------- | ---
| Branch? | 2.8
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
There is a bug in the `AutowirePass`, when using more than 2 services colliding and you want to use the autowiring types: it may not work depending on their order because `notGuessableTypes` is not reset.
Commits
-------
5981278537 [DependencyInjection] Fix using autowiring types when there are more than 2 services
This PR was merged into the 2.8 branch.
Discussion
----------
[DependencyInjection] Fix autowiring collisions detection
| Q | A
| ------------- | ---
| Branch? | 2.8
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR |
Fixes https://github.com/symfony/symfony/pull/21658 by implementing the second proposal of https://github.com/symfony/symfony/pull/21658#issuecomment-280858452:
> Another idea: store the types used previously and check that new services registered don't implement them.
Commits
-------
bb70472dce [DependencyInjection] Fix autowiring collisions detection
6f578ee514 [DI] Bug in autowiring collisions detection
* 3.2:
Fix typo in process error message
Update to PHPUnit namespaces
Minor typo fix messsagesData -> messagesData
remove translation data collector when not usable
* 3.2:
Permit empty suffix on Windows
fixed CS
[FrameworkBundle] Remove unused import
[Console][Table] fixed render when using multiple rowspans.
add docblocks for Twig url and path function to improve ide completion
check for circular refs caused by method calls
[Serializer] fix upper camel case conversion (see #21399)
[DI] Auto register extension configuration classes as a resource
[Console] Updated phpdoc on return types
* 2.8:
Permit empty suffix on Windows
[Console][Table] fixed render when using multiple rowspans.
add docblocks for Twig url and path function to improve ide completion
check for circular refs caused by method calls
[Serializer] fix upper camel case conversion (see #21399)
[DI] Auto register extension configuration classes as a resource
[Console] Updated phpdoc on return types
* 2.7:
Permit empty suffix on Windows
[Console][Table] fixed render when using multiple rowspans.
add docblocks for Twig url and path function to improve ide completion
check for circular refs caused by method calls
[Serializer] fix upper camel case conversion (see #21399)
[DI] Auto register extension configuration classes as a resource
[Console] Updated phpdoc on return types
This PR was merged into the 2.7 branch.
Discussion
----------
[DependencyInjection] check for circular refs caused by method calls
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #19362
| License | MIT
| Doc PR |
Before we check for circular references, dependencies coming from method calls are not part of the dependency graph. That why the pass is not able to detect circular references like the one described in #19362 during compilation of the container.
If we add another check after all the optimisation passes have been processed, we should be able to detect these circular references too.
Commits
-------
fe4f7eccf7 check for circular refs caused by method calls
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Deprecate underscore-services in YamlFileLoader
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | no
| Fixed tickets | -
| License | MIT
| Doc PR | -
As discussed when introducing `_defaults`
Commits
-------
7781082587 [DI] Deprecate underscore-services in YamlFileLoader
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI][FrameworkBundle] ServiceLocator: Tests dumpers & update descriptors
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | no
| Fixed tickets | N/A
| License | MIT
| Doc PR | N/A
This simply ensures the new feature is properly considered by the different dumpers, and updates the console descriptors to support the new `ServiceLocatorArgument`.
I also added the number of elements in an array/iterator/service_locator argument when using the `TextDescriptor` in this PR.
(fabbot is complaining about the new yaml tags support)
Commits
-------
aa9074d25a [DI][FrameworkBundle] ServiceLocator: Tests dumpers & update descriptors
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DependencyInjection] Use glob pattern to load config files
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #21173
| License | MIT
| Doc PR | -
This relates to #21173, but I'm not sure if it completely fixes the issue.
This allows to use a glob pattern to load config files, which makes the following possible:
```
# config.yml
imports:
- { resource: "*.yml" }
- { resource: "folder/*.yml" }
- { resource: "/etc/myapp/*.{yml,xml}" }
```
It can also be used in a container extension, if a bundle uses a lot of configs:
```
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('*.yml');
$loader->load('routing/*');
```
Commits
-------
519180ef56 Use glob pattern to load config file
This PR was merged into the 2.7 branch.
Discussion
----------
[DI] Auto register extension configuration classes as a resource
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | symfony/symfony-docs#... <!--highly recommended for new features-->
Auto-register an extension configuration class as a resource from a compiler pass; not implicitly by the base extension class.
Causing some extensions to register its configuration, whereas others dont (e.g. framework bundle).
Fixes consistent cache invalidation whenever a configuration definition changes.
Commits
-------
142416b7d4 [DI] Auto register extension configuration classes as a resource
* 3.2: (27 commits)
Improve tracking of environment variables in the case of private services
[DI] Align AutowirePass with 2.8
property constraints can be added in child classes
added test for staticClassLoader in LazyLoadingMetadatafactory
fixed PHPUnit setUp and tearDown method visibility
spelling fixes
Readd Symfony version status in the toolbar
[Security] LdapUserProvider should not throw an exception if the UID key does not exist in an LDAP entry
make sure that null can be the invalid value
[VarDumper] Improve dump of AMQP* Object
Fix annotations cache folder path
[FrameworkBundle] Wire ArrayCache for annotation reader at bootstrap
Ignore missing 'debug.file_link_formatter' service in Debug bundle
[VarDumper] Fixed dumping of terminated generator
bumped Symfony version to 3.2.4
updated VERSION for 3.2.3
updated CHANGELOG for 3.2.3
bumped Symfony version to 2.8.18
updated VERSION for 2.8.17
updated CHANGELOG for 2.8.17
...
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DependencyInjection] Add support for named arguments
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | todo
This PR introduces named arguments for services definitions. It's especially useful to inject parameters in an autowired service. It is (at least partially) an alternative to #21376 and #20738.
Usage:
```yml
services:
_defaults: { autowire: true }
Acme\NewsletterManager: { $apiKey: "%mandrill_api_key%" }
# Alternative (traditional) syntax
services:
newsletter_manager:
class: Acme\NewsletterManager
arguments:
$apiKey: "%mandrill_api_key%"
autowire: true
```
```php
use Doctrine\ORM\EntityManager;
use Psr\Log\LoggerInterface;
namespace Acme;
class NewsletterManager
{
private $logger;
private $em;
private $apiKey;
public function __construct(LoggerInterface $logger, EntityManager $em, $apiKey)
{
$this->logger = $logger;
$this->em = $em;
$this->apiKey = $apiKey;
}
}
```
Commits
-------
8a126c8537 [DI] Deprecate string keys in arguments
2ce36a6074 [DependencyInjection] Add a new pass to check arguments validity
6e501296f9 [DependencyInjection] Add support for named arguments
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Add prototype services for PSR4-based discovery and registration
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | to be done
Talking with @dunglas, we wondered if this could be a good idea, as a more general approach to folder-based service registration as done in [DunglasActionBundle](https://github.com/dunglas/DunglasActionBundle/blob/master/DependencyInjection/DunglasActionExtension.php).
So here is the implementation.
This allows one to define a set of services as such:
```yaml
services:
App\:
resources: ../src/{Controller,Command} # relative to the current file as usual
autowire: true # or any other attributes really
```
This looks for php files in the "src" folder, derivates PSR-4 class names from them, and uses `class_exists` for final discovery. The resulting services are named after the classes found this way.
The "resource" attribute can be a glob to select only a subset of the classes/files.
This approach has several advantages over [DunglasActionBundle](https://github.com/dunglas/DunglasActionBundle/blob/master/DependencyInjection/DunglasActionExtension.php):
- it is resilient to missing parent classes (see test case)
- it loads classes using the normal code path (the autoloader), thus play well with them (e.g. if one registered a special autoloader).
- it is more predictable, because it uses discovered paths as the only source of ids/classes to register - vs relying on `get_declared_classes`, which would make things context sensitive.
Fits well with current initiatives to me.
Commits
-------
03470b788e [DI] Add "psr4" service attribute for PSR4-based discovery and registration
This PR was merged into the 3.3-dev branch.
Discussion
----------
[Config][DI] Add ComposerResource to track the runtime engine + deps
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
So that the container is invalidated whenever a new PHP runtime is used, a PHP-extension is added, or vendors are changed.
Commits
-------
a960c761d1 [Config][DI] Add ComposerResource to track runtime + vendors
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Deprecate (un)setting pre-defined services
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | no
| Fixed tickets | #19192
| License | MIT
| Doc PR | -
This PR is the subset of #19668 that fixes#19192: it deprecates (un)setting pre-defined services.
This opens the path to some optimizations in the dumped container in 4.0.
Commits
-------
fdb2140b81 [DI] Deprecate (un)setting pre-defined services
This PR was squashed before being merged into the 3.3-dev branch (closes#21194).
Discussion
----------
[Yaml] Add tags support
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | https://github.com/symfony/symfony/issues/21185
| License | MIT
| Doc PR |
This PR adds custom tags support to the Yaml component.
Symfony tags (`!!binary`, `!str`, etc.) are still managed in the parser to have a lighter diff but we'll be able to convert them later if we want to.
The primary addition of this PR is the `TagInterface`:
```php
interface TagInterface
{
public function construct(mixed $value): mixed;
}
```
It can be used to register custom tags. An example that could be used to convert [the syntax `=iterator`](https://github.com/symfony/symfony/pull/20907#issuecomment-270728216) to a tag:
```php
final class IteratorTag implements TagInterface
{
public function construct(mixed $value): mixed
{
return new IteratorArgument($value);
}
}
$parser = new Parser(['iterator' => new IteratorTag()]);
```
If you think this is too complex, @nicolas-grekas [proposed an alternative](https://github.com/symfony/symfony/issues/21185#issuecomment-271074840) to my proposal externalizing this support by introducing a new class `TaggedValue`.
Commits
-------
4744107 [Yaml] Add tags support
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] ContainerBuilder::compile() can optionally resolve env vars in parameter bag
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | #21420
| License | MIT
| Doc PR | -
Here is a new feature allowing one to do `$container->compile(true)` and get the env vars resolved using the current env.
Commits
-------
a3fd512271 [DI] ContainerBuilder::compile() can optionally resolve env vars in parameter bag
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI][Config] Add & use ReflectionClassResource
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | #21079
| License | MIT
| Doc PR | -
With new changes comming to 3.3, we need a more generic reflection tracking logic than the one already managed by the autowiring subsystem.
This PR adds a new ReflectionClassResource in the Config component, and a new ContainerBuilder::getReflectionClass() method in the DI one (for fetching+tracking reflection-related info).
ReflectionClassResource tracks changes to any public or protected properties/method.
PR updated and ready, best viewed [ignoring whitespaces](https://github.com/symfony/symfony/pull/21419/files?w=1).
changelog:
* added `ReflectionClassResource` class
* added second `$exists` constructor argument to `ClassExistenceResource` - with a special mode that prevents fatal errors from happening when some parent class is broken (logic generalized from AutowiringPass)
* made `ClassExistenceResource` also work with interfaces and traits
* added `ContainerBuilder::getReflectionClass()` for retrieving and tracking reflection class info
* deprecated `ContainerBuilder::getClassResource()`, use `ContainerBuilder::getReflectionClass()` or `ContainerBuilder::addObjectResource()` instead
Commits
-------
37e44939ef [DI][Config] Add & use ReflectionClassResource
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Allow to count on lazy collection arguments
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/21450#issuecomment-275931764
| License | MIT
| Doc PR | todo (with https://github.com/symfony/symfony-docs/issues/7336)
When using the new iterator feature of the DI component to lazy load collection, we always know the number of arguments in the collection (only the invalidBehavior set to `IGNORE_ON_INVALID_REFERENCE` may change this number). So we are able to generate and use a `RewindableGenerator` implementing `\Countable` by computing this value ahead.
So, in a service accepting `array|iterable`, like in the `GuardAuthenticationListener` (see #21450):
```php
class GuardAuthenticationListener implements ListenerInterface
{
private $guardAuthenticators;
/**
* @param iterable|GuardAuthenticatorInterface[] $guardAuthenticators The authenticators, with keys that match what's passed to GuardAuthenticationProvider
* @param LoggerInterface $logger A LoggerInterface instance
*/
public function __construct($guardAuthenticators, LoggerInterface $logger = null)
{
// ...
}
public function handle(GetResponseEvent $event)
{
if (null !== $this->logger) {
$context = array()
if (is_array($this->guardAuthenticators) || $this->guardAuthenticators instanceof \Countable) {
$context['authenticators'] = count($this->guardAuthenticators);
}
$this->logger->debug('Checking for guard authentication credentials.', $context);
}
// ...
}
}
```
we still keep the ability to call count without loosing the lazy load benefits.
Commits
-------
f23e460 [DI] Allow to count on lazy collection arguments
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] : Fix bad generation of proxy class when use overriden getter on class with constructor
[DI] : Fix bad generation of proxy class when use overriden getter on class with constructor
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #21507
| License | MIT
- [X] Add test fail
- [X] Fix bug
- [X] Run test pass
Commits
-------
2440b0f [DI] : Fix bad generation of proxy class when use overriden getter on class with constructor
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Add getter injection
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #20657
| License | MIT
| Doc PR | symfony/symfony-docs#7300
Getter overriding by the container will allow a new kind of dependency injection which enables easier laziness and more immutable classes, by not requiring any corresponding setter. See linked issue for more.
This is WIP:
- [x] wire the concept
- [x] dump anonymous classes with PhpDumper
- [x] generate at runtime in ContainerBuilder::createService
- [x] tests
- [x] make it work on PHP 5
Commits
-------
cb498580d1 [DI] Add getter injection
* 3.2:
fixed typo
fixed composer.json
[HttpKernel] Fix Bundle name regression
always check for all fields to be mapped
clarify exception when no args are configured
[PropertyAccess] Handle interfaces in the invalid argument exception
[DI] Fix defaults overriding empty strings in AutowirePass
[Debug] Workaround "null" $context
[Debug] Remove $context arg from handleError(), preparing for PHP 7.2
[FrameworkBundle] Dont wire "annotations.cached_reader" before removing passes
[Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
Fix tests with ICU 57.1
Fix the condition checking the minimum ICU version
* 3.1:
fixed typo
fixed composer.json
always check for all fields to be mapped
clarify exception when no args are configured
[PropertyAccess] Handle interfaces in the invalid argument exception
[DI] Fix defaults overriding empty strings in AutowirePass
[Debug] Workaround "null" $context
[Debug] Remove $context arg from handleError(), preparing for PHP 7.2
[Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
Fix tests with ICU 57.1
Fix the condition checking the minimum ICU version
* 2.8:
always check for all fields to be mapped
clarify exception when no args are configured
[PropertyAccess] Handle interfaces in the invalid argument exception
[DI] Fix defaults overriding empty strings in AutowirePass
[Debug] Workaround "null" $context
[Debug] Remove $context arg from handleError(), preparing for PHP 7.2
[Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
Fix tests with ICU 57.1
Fix the condition checking the minimum ICU version
* 2.7:
always check for all fields to be mapped
clarify exception when no args are configured
[PropertyAccess] Handle interfaces in the invalid argument exception
[Debug] Workaround "null" $context
[Debug] Remove $context arg from handleError(), preparing for PHP 7.2
[Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
Fix tests with ICU 57.1
Fix the condition checking the minimum ICU version
This PR was squashed before being merged into the 3.3-dev branch (closes#21348).
Discussion
----------
[DependencyInjection] Yaml: check if $tags is an array before using it
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Commits
-------
1c9b5c9 [DependencyInjection] Yaml: check if is an array before using it
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Add Yaml syntax for short services definition
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | N/A
| License | MIT
| Doc PR | todo
In my experience, most (at least, a lot) of the service definitions in an end-application only require the class and constructor arguments.
#21133 allows to get rid of the `class` attribute by using the service id.
Which means only arguments remain for most use-cases. Hence, we could support this syntax:
#### Before:
```yml
services:
App\Foo\Bar:
arguments: ['@baz', 'foo', '%qux%']
```
#### After:
```yml
services:
App\Foo\Bar: ['@baz', 'foo', '%qux%']
```
It works especially well along with services `_defaults` introduced in #21071 :
```yml
services:
_defaults:
public: false
autowire: ['set*']
tags: ['serializer.normalizer']
App\Serializer\FooNormalizer: ['@baz', 'foo', '%qux%']
```
Commits
-------
83b599c6ad [DI] Add Yaml syntax for short services definition
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Factorize compiler passes around new AbstractRecursivePass
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
This PR introduces an AbstractRecursivePass that is able to visit the definition tree recursively everywhere a Definition or a Reference can be nested.
All existing compiler passes that need recursivity are updated to leverage this new class.
This remove a bunch of boilerplate that was previously repeated all over.
It also fixes compiler passes that eg missed looking at configurators for no reason (this "fix" is a new feature really).
It then applies recursivity to AutowirePass, that does not handle it today, but should.
I'm happy that the net result is a loss of 153 lines :)
Commits
-------
6acb80f48f [DI] Factorize compiler passes around new AbstractRecursivePass
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Remove synthetic services from methodMap + generated methods
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
For synthetic services, the generated methods are just dead code to fill opcache ;)
And having them in "methodMap" prevents using the property for checking if a service comes from a (non-synthetic) definition or not.
This prepares some changes that we'd like to do in 4.0, see #19668.
Commits
-------
c1e1e999f3 [DI] Remove synthetic services from methodMap + generated methods
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Mark generated containers as final
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | no
| Fixed tickets | -
| License | MIT
| Doc PR | -
So that we don't have to care anymore about BC for protected methods in generated containers.
Will leverage deprecations triggered in #20493
Commits
-------
ce0ee1e484 [DI] Mark generated containers as final
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Deprecate case insentivity of service identifiers
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | minor (see UPGRADE note)
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | #21193
| License | MIT
| Doc PR | -
As discussed in linked RFC.
Commits
-------
d08f1101df [DI] Deprecate case insentivity of service identifiers
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] FileLoaders: Allow to explicit type to load
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | https://github.com/symfony/symfony/issues/20308
| License | MIT
| Doc PR | Not yet
(fabbot will scream out regarding the PR fixtures)
Commits
-------
6b660c2114 [DI] FileLoaders: Allow to explicit type to load
* 3.2:
[DI] Add missing legacy group on testLegacy
Minor tweaks
Fix merge
[DI] Dont share service when no id provided
Fix Container and PhpDumper test inaccuracies
[DI] Fix missing new line after private alias
[ClassLoader] Throw an exception if the cache is not writeable
Fixing regression in TwigEngine exception handling.
* 3.1:
Fix merge
[DI] Dont share service when no id provided
Fix Container and PhpDumper test inaccuracies
[DI] Fix missing new line after private alias
[ClassLoader] Throw an exception if the cache is not writeable
Fixing regression in TwigEngine exception handling.
* 2.8:
Fix merge
[DI] Dont share service when no id provided
Fix Container and PhpDumper test inaccuracies
[DI] Fix missing new line after private alias
[ClassLoader] Throw an exception if the cache is not writeable
Fixing regression in TwigEngine exception handling.
* 2.7:
[DI] Dont share service when no id provided
Fix Container and PhpDumper test inaccuracies
[DI] Fix missing new line after private alias
[ClassLoader] Throw an exception if the cache is not writeable
Fixing regression in TwigEngine exception handling.
This PR was merged into the 2.7 branch.
Discussion
----------
Fix Container and PhpDumper test inaccuracies
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Stumbled upon and fixed some minor inaccuracies in tests for DI container, they might have lead to undetected changes of `Container`'s behavior
Commits
-------
24b93cc Fix Container and PhpDumper test inaccuracies
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Dont call get() when not required - µ-optim
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
(could be applied on 3.2, please advise)
Helps a bit on https://rawgit.com/kocsismate/php-di-container-benchmarks/master/var/benchmark.html
note: if we want more performance, we should consider deprecating case insensitivity of service identifiers.
Commits
-------
7a42199115 [DI] Dont call get() when not required - µ-optim
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DependencyInjection] Implement lazy collection type using generators
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | -
| Fixed tickets | #20875
| License | MIT
| Doc PR | -
Following the RFC https://github.com/symfony/symfony/issues/20875, this PR aims to implement lazy services collections using generators internally.
For now, I suggest to support only XML and PHP definitions. Supporting YAML means adding another convention to the language and this is not the aim of this PR.
- [x] value object holding the semantic (IteratorArgument)
- [x] iterator dumping
- [x] lazyness awareness in CheckCircularReferencesPass & GraphvizDumper
- [x] rewindable iterators
- [x] `*_ON_INVALID_REFERENCE` behavior
- [x] ContainerBuilder::createService
- [x] ArgumentInterface handling in compiler passes
Commits
-------
1dbf52ad03 [DI] Add "=iterator" arguments to Yaml loader
5313943692 [DependencyInjection] Implement lazy collection type using generators
* 3.1:
fixed obsolete getMock() usage
fixed obsolete getMock() usage
fixed obsolete getMock() usage
[WebProfilerBundle] Display multiple HTTP headers in WDT
do not remove the Twig ExceptionController service
removed obsolete condition
do not try to register incomplete definitions
* 2.8:
fixed obsolete getMock() usage
fixed obsolete getMock() usage
[WebProfilerBundle] Display multiple HTTP headers in WDT
do not remove the Twig ExceptionController service
removed obsolete condition
do not try to register incomplete definitions
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Make ContainerBuilder::resolveEnvPlaceholders() able to inline the values of referenced env vars.
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Being able to resolve environment variables at compile time as a replacement for `SYMFONY__` special env vars, unlocking their deprecation (see #20100).
Commits
-------
713b081 [DI] Make ContainerBuilder::resolveEnvPlaceholders() able to inline the values of referenced env vars.
The DefinitionDecorator class does not deal with decorated services. It
reflects a parent-child-relationship between definitions instead. To
avoid confusion, this commit deprecates the existing DefinitionDecorator
class and introduces a new ChildDefinition class as replacement.
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DependencyInjection] Added Yaml syntax shortcut for name-only tags
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | todo
This PR adds a little shorcut for tags without any attributes. There are increasingly more name-only tags in Symfony and having to do `{ name: twig.extension }` for these seems way too verbose to me.
**Before**
```yaml
services:
app.twig_extension:
class: AppBundle\Twig\AppExtension
tags:
- { name: twig.extension }
```
**After**
```yaml
services:
app.twig_extension:
class: AppBundle\Twig\AppExtension
tags: [twig.extension]
# or
# - twig.extension
```
This of course means we introduce a new format to achieve the same goal. I believe this isn't a big problem as the decision is distinctive and simple: If you configure tag attributes, use the long format, otherwise use the short format.
Backwards compatibility
---
In this PR, an exception was removed to allow this new shortcut format. The BC promise doesn't cover exceptions and I think removing the exception here should cause anything to break:
* Applications shouldn't rely on exceptions
* If code was triggering this exception before, it would not cause any behaviour change after this PR: The service just retrieves an unused tag, which is simply ignored by the container.
Commits
-------
7fa8c8a Added Yaml syntax shortcut for name-only tags
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DependencyInjection] Added a shortcut method for autowired definitions
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | todo
This is a simple proposal to make adding autowired definitions to the `ContainerBuilder` a little easier. Registering autowired services in PHP code was quite verbose at the moment, while the whole point of autowiring is quick service registration.
**Before**
```php
$container->register('app.twig_extension', AppExtension::class)
->setAutowired(true)
->addTag('twig.extension')
;
```
**After**
```php
$container->autowire('app.twig_extension', AppExtension::class)
->addTag('twig.extension')
;
```
With https://github.com/symfony/symfony/pull/20264, this will be even nicer:
```php
$container->autowire(AppExtension::class)
->addTag('twig.extension')
;
```
Commits
-------
6ef4ce8 Added a shortcut method for autowired definitions
* 3.1: (28 commits)
Fix merge
[Validator] add class name to the cache key
[Serializer] Remove AbstractObjectNormalizer::isAttributeToNormalize
Throw less misleading exception when property access not found
[Twig] Fix deprecations with Twig 1.29
Fixed typo
[FrameworkBundle] Removed the kernel.debug parameter from the cache pool namespace seed
Fix email address
fix the docblock in regard to the role argument
Don't use the "app" global variable in the profiler
[VarDumper] fix tests when xdebug is enabled
Fix merge
FIXED NON EXISTING TYPE DECLARATION
[Cache] Fix dumping SplDoublyLinkedList iter mode
[Console] fixed PHP7 Errors when not using Dispatcher
Regression test for missing controller arguments (3.1)
Regression test for missing controller arguments
fix a test checking for a value
[Form][DX] FileType "multiple" fixes
fixed CS
...
* 2.8:
[Twig] Fix deprecations with Twig 1.29
Fixed typo
Fix email address
fix the docblock in regard to the role argument
[VarDumper] fix tests when xdebug is enabled
Fix merge
[Cache] Fix dumping SplDoublyLinkedList iter mode
[Console] fixed PHP7 Errors when not using Dispatcher
Regression test for missing controller arguments
fix a test checking for a value
[Form][DX] FileType "multiple" fixes
fixed CS
[TwigBundle] Fix twig loader registered twice
[WebProfilerBundle] Fix dump block is unfairly restrained
[Console] Fix wrong handling of multiline arg/opt descriptions
[DependencyInjection] PhpDumper.php: hasReference() should not search references in lazy service arguments.
[Form] fixed "empty_value" option deprecation
Cast result to int before adding to it
This PR was merged into the 2.7 branch.
Discussion
----------
Cast result to int before adding to it
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
This fixes the occasional warning about non-numeric values when using PHP 7.1.
Commits
-------
70c42f2 Cast result to int before adding to it