-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #42625 [DependencyInjection] Add service_closure() to the PHP…
…-DSL (HypeMC) This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Add service_closure() to the PHP-DSL | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | symfony/symfony-docs#15730 and symfony/symfony-docs#15731 Adds a `service_closure()` function to the PHP-DSL. Commits ------- f333fa0 [DI] Add service_closure() to the PHP-DSL
- Loading branch information
Showing
7 changed files
with
141 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
CHANGELOG | ||
========= | ||
|
||
5.4 | ||
--- | ||
|
||
* Add `service_closure()` to the PHP-DSL | ||
|
||
5.3 | ||
--- | ||
|
||
|
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
16 changes: 16 additions & 0 deletions
16
...ymfony/Component/DependencyInjection/Loader/Configurator/ClosureReferenceConfigurator.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,16 @@ | ||
<?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\Loader\Configurator; | ||
|
||
class ClosureReferenceConfigurator extends ReferenceConfigurator | ||
{ | ||
} |
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
15 changes: 15 additions & 0 deletions
15
...Symfony/Component/DependencyInjection/Tests/Fixtures/config/services_closure_argument.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,15 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
return function (ContainerConfigurator $c) { | ||
$s = $c->services()->defaults()->public(); | ||
|
||
$s->set('foo', 'Foo'); | ||
|
||
$s->set('service_closure', 'Bar') | ||
->args([service_closure('foo')]); | ||
|
||
$s->set('service_closure_invalid', 'Bar') | ||
->args([service_closure('invalid_service')->nullOnInvalid()]); | ||
}; |
82 changes: 82 additions & 0 deletions
82
...y/Component/DependencyInjection/Tests/Fixtures/php/services_closure_argument_compiled.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,82 @@ | ||
<?php | ||
|
||
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\DependencyInjection\Container; | ||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | ||
use Symfony\Component\DependencyInjection\Exception\LogicException; | ||
use Symfony\Component\DependencyInjection\Exception\RuntimeException; | ||
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
|
||
/** | ||
* @internal This class has been auto-generated by the Symfony Dependency Injection Component. | ||
*/ | ||
class ProjectServiceContainer extends Container | ||
{ | ||
protected $parameters = []; | ||
|
||
public function __construct() | ||
{ | ||
$this->services = $this->privates = []; | ||
$this->methodMap = [ | ||
'foo' => 'getFooService', | ||
'service_closure' => 'getServiceClosureService', | ||
'service_closure_invalid' => 'getServiceClosureInvalidService', | ||
]; | ||
|
||
$this->aliases = []; | ||
} | ||
|
||
public function compile(): void | ||
{ | ||
throw new LogicException('You cannot compile a dumped container that was already compiled.'); | ||
} | ||
|
||
public function isCompiled(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function getRemovedIds(): array | ||
{ | ||
return [ | ||
'Psr\\Container\\ContainerInterface' => true, | ||
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, | ||
]; | ||
} | ||
|
||
/** | ||
* Gets the public 'foo' shared service. | ||
* | ||
* @return \Foo | ||
*/ | ||
protected function getFooService() | ||
{ | ||
return $this->services['foo'] = new \Foo(); | ||
} | ||
|
||
/** | ||
* Gets the public 'service_closure' shared service. | ||
* | ||
* @return \Bar | ||
*/ | ||
protected function getServiceClosureService() | ||
{ | ||
return $this->services['service_closure'] = new \Bar(function () { | ||
return ($this->services['foo'] ?? ($this->services['foo'] = new \Foo())); | ||
}); | ||
} | ||
|
||
/** | ||
* Gets the public 'service_closure_invalid' shared service. | ||
* | ||
* @return \Bar | ||
*/ | ||
protected function getServiceClosureInvalidService() | ||
{ | ||
return $this->services['service_closure_invalid'] = new \Bar(function () { | ||
return NULL; | ||
}); | ||
} | ||
} |
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