Skip to content

Commit 98bac46

Browse files
committed
feature #36388 [DI] deprecate the inline() function from the PHP-DSL in favor of service() (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- [DI] deprecate the `inline()` function from the PHP-DSL in favor of `service()` | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | - | License | MIT | Doc PR | - In the PHP-DSL, the `inline()` function helps declaring ... inline services. I'm proposing to rename it to `service()`, for consistency with yaml tags. All other helpers but this one have the same name as the yaml tag. Let's do this while "nobody" uses this format yet :) Commits ------- 647d971ae4 [DI] deprecate the `inline()` function from the PHP-DSL in favor of `service()`
2 parents 88d7d29 + a513b34 commit 98bac46

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CHANGELOG
1717
* added tags `container.preload`/`.no_preload` to declare extra classes to preload/services to not preload
1818
* deprecated `Definition::getDeprecationMessage()`, use `Definition::getDeprecation()` instead
1919
* deprecated `Alias::getDeprecationMessage()`, use `Alias::getDeprecation()` instead
20+
* deprecated PHP-DSL's `inline()` function, use `service()` instead
2021

2122
5.0.0
2223
-----

Loader/Configurator/ContainerConfigurator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,20 @@ function ref(string $id): ReferenceConfigurator
9292

9393
/**
9494
* Creates an inline service.
95+
*
96+
* @deprecated since Symfony 5.1, use service() instead.
9597
*/
9698
function inline(string $class = null): InlineServiceConfigurator
99+
{
100+
trigger_deprecation('symfony/dependency-injection', '5.1', '"%s()" is deprecated, use "service()" instead.', __FUNCTION__);
101+
102+
return new InlineServiceConfigurator(new Definition($class));
103+
}
104+
105+
/**
106+
* Creates an inline service.
107+
*/
108+
function service(string $class = null): InlineServiceConfigurator
97109
{
98110
return new InlineServiceConfigurator(new Definition($class));
99111
}

Loader/Configurator/InlineServiceConfigurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class InlineServiceConfigurator extends AbstractConfigurator
2020
{
21-
const FACTORY = 'inline';
21+
const FACTORY = 'service';
2222

2323
use Traits\ArgumentTrait;
2424
use Traits\AutowireTrait;

Tests/Fixtures/config/basic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
return function (ContainerConfigurator $c) {
88
$s = $c->services();
99
$s->set(BarService::class)
10-
->args([inline('FooClass')]);
10+
->args([service('FooClass')]);
1111
};

Tests/Fixtures/config/object.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public function __invoke(ContainerConfigurator $c)
99
{
1010
$s = $c->services();
1111
$s->set(BarService::class)
12-
->args([inline('FooClass')]);
12+
->args([service('FooClass')]);
1313
}
1414
};

0 commit comments

Comments
 (0)