Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feature #21031 [DI] Getter autowiring (dunglas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Getter autowiring | 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 This PR adds support for getter autowiring. #20973 must be merged first. Example: ```yaml # app/config/config.yml services: Foo\Bar: autowire: ['get*'] ``` ```php namespace Foo; class Bar { protected function getBaz(): Baz // this feature only works with PHP 7+ { } } class Baz { } ```` `Baz` will be automatically registered as a service and an instance will be returned when `Bar::getBaz` will be called (and only at this time, lazy loading). This feature requires PHP 7 or superior. Commits ------- c48c36b [DI] Add support for getter autowiring
- Loading branch information
Showing
5 changed files
with
160 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/Symfony/Component/DependencyInjection/Tests/Fixtures/GetterOverriding.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures; | ||
|
||
use Symfony\Component\DependencyInjection\Tests\Compiler\A; | ||
use Symfony\Component\DependencyInjection\Tests\Compiler\B; | ||
use Symfony\Component\DependencyInjection\Tests\Compiler\Bar; | ||
use Symfony\Component\DependencyInjection\Tests\Compiler\Foo; | ||
|
||
/** | ||
* To test getter autowiring with PHP >= 7.1. | ||
* | ||
* @author Kévin Dunglas <dunglas@gmail.com> | ||
*/ | ||
class GetterOverriding | ||
{ | ||
public function getFoo(): ?Foo | ||
{ | ||
// should be called | ||
} | ||
|
||
protected function getBar(): Bar | ||
{ | ||
// should be called | ||
} | ||
|
||
public function getNoTypeHint() | ||
{ | ||
// should not be called | ||
} | ||
|
||
public function getUnknown(): NotExist | ||
{ | ||
// should not be called | ||
} | ||
|
||
public function getExplicitlyDefined(): B | ||
{ | ||
// should be called but not autowired | ||
} | ||
|
||
public function getScalar(): string | ||
{ | ||
// should not be called | ||
} | ||
|
||
final public function getFinal(): A | ||
{ | ||
// should not be called | ||
} | ||
|
||
public function &getReference(): A | ||
{ | ||
// should not be called | ||
} | ||
} |