Contributed by
Kévin Dunglas
in #21031.
Autowiring is a set of features that enable RAD ("Rapid Application Development") on Symfony applications. Some projects and developers need this kind of development and that's why we keep adding new features to it.
In Symfony 3.3, we decided to add support for getter autowiring for those applications using PHP 7.0 or newer. Consider the following sample classes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // src/AppBundle/Manager/Publisher.php
namespace AppBundle\Manager;
use AppBundle\Parser\Markdown;
class Publisher
{
protected function getMarkdownParser(): Markdown { }
// ...
}
// src/AppBundle/Parser/Markdown.php
namespace AppBundle\Parser\Markdown;
class Markdown
{
// ...
}
|
Now, add the following service configuration:
1 2 3 4 | # app/config/services.yml
services:
AppBundle\Manager\Publisher:
autowire: ['get*']
|
Getter autowiring automatically registers the Markdown
class as a service
and returns and instance of it when the getMarkdownParser()
method is called
in the Publisher
class (and only at this time, lazy loading it).
This feature is part of our experimental features program, so its implementation could change in Symfony 3.4 or we could even remove it entirely. That's why we need you to test it in your real applications and share your thoughts about it with us.
The documentation of this feature is not ready yet, but you can follow @symfonydocs on Twitter to get notified when we publish it.
What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...