Skip to content

Commit cf04f1e

Browse files
bug symfony#36800 [DI] Renamed some PHP-DSL functions (javiereguiluz)
This PR was squashed before being merged into the 5.1-dev branch. Discussion ---------- [DI] Renamed some PHP-DSL functions | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - As discussed in symfony#36778, Symfony wants to move from XML to PHP for its own configuration. I propose these function renames to make the PHP-DSL a bit easier to understand: ```php <?php // Before $services->set(Foo::class) ->args([ref(Bar::class), service('stdClass')]); // After $services->set(Foo::class) ->args([service(Bar::class), inline_service('stdClass')]); ``` Commits ------- 366405b [DI] Renamed some PHP-DSL functions
2 parents 5dd99f2 + 366405b commit cf04f1e

File tree

15 files changed

+69
-54
lines changed

15 files changed

+69
-54
lines changed

UPGRADE-5.1.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ DependencyInjection
2424
configure them explicitly instead.
2525
* Deprecated `Definition::getDeprecationMessage()`, use `Definition::getDeprecation()` instead.
2626
* Deprecated `Alias::getDeprecationMessage()`, use `Alias::getDeprecation()` instead.
27-
* The `inline()` function from the PHP-DSL has been deprecated, use `service()` instead
27+
* The `inline()` function from the PHP-DSL has been deprecated, use `inline_service()` instead
28+
* The `ref()` function from the PHP-DSL has been deprecated, use `service()` instead
2829

2930
Dotenv
3031
------

UPGRADE-6.0.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ DependencyInjection
2424
configure them explicitly instead.
2525
* Removed `Definition::getDeprecationMessage()`, use `Definition::getDeprecation()` instead.
2626
* Removed `Alias::getDeprecationMessage()`, use `Alias::getDeprecation()` instead.
27-
* The `inline()` function from the PHP-DSL has been removed, use `service()` instead
27+
* The `inline()` function from the PHP-DSL has been removed, use `inline_service()` instead.
28+
* The `ref()` function from the PHP-DSL has been removed, use `service()` instead.
2829

2930
Dotenv
3031
------

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.1.0
55
-----
66

7+
* deprecated `inline()` in favor of `inline_service()` and `ref()` in favor of `service()` when using the PHP-DSL
78
* allow decorators to reference their decorated service using the special `.inner` id
89
* added support to autowire public typed properties in php 7.4
910
* added support for defining method calls, a configurator, and property setters in `InlineServiceConfigurator`

src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,40 @@ final public function withPath(string $path): self
8484

8585
/**
8686
* Creates a service reference.
87+
*
88+
* @deprecated since Symfony 5.1, use service() instead.
8789
*/
8890
function ref(string $id): ReferenceConfigurator
8991
{
92+
trigger_deprecation('symfony/dependency-injection', '5.1', '"%s()" is deprecated, use "service()" instead.', __FUNCTION__);
93+
9094
return new ReferenceConfigurator($id);
9195
}
9296

97+
/**
98+
* Creates a reference to a service.
99+
*/
100+
function service(string $serviceId): ReferenceConfigurator
101+
{
102+
return new ReferenceConfigurator($serviceId);
103+
}
104+
93105
/**
94106
* Creates an inline service.
95107
*
96-
* @deprecated since Symfony 5.1, use service() instead.
108+
* @deprecated since Symfony 5.1, use inline_service() instead.
97109
*/
98110
function inline(string $class = null): InlineServiceConfigurator
99111
{
100-
trigger_deprecation('symfony/dependency-injection', '5.1', '"%s()" is deprecated, use "service()" instead.', __FUNCTION__);
112+
trigger_deprecation('symfony/dependency-injection', '5.1', '"%s()" is deprecated, use "inline_service()" instead.', __FUNCTION__);
101113

102114
return new InlineServiceConfigurator(new Definition($class));
103115
}
104116

105117
/**
106118
* Creates an inline service.
107119
*/
108-
function service(string $class = null): InlineServiceConfigurator
120+
function inline_service(string $class = null): InlineServiceConfigurator
109121
{
110122
return new InlineServiceConfigurator(new Definition($class));
111123
}

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/FactoryTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final public function factory($factory): self
2727
if (\is_string($factory) && 1 === substr_count($factory, ':')) {
2828
$factoryParts = explode(':', $factory);
2929

30-
throw new InvalidArgumentException(sprintf('Invalid factory "%s": the "service:method" notation is not available when using PHP-based DI configuration. Use "[ref(\'%s\'), \'%s\']" instead.', $factory, $factoryParts[0], $factoryParts[1]));
30+
throw new InvalidArgumentException(sprintf('Invalid factory "%s": the "service:method" notation is not available when using PHP-based DI configuration. Use "[service(\'%s\'), \'%s\']" instead.', $factory, $factoryParts[0], $factoryParts[1]));
3131
}
3232

3333
$this->definition->setFactory(static::processValue($factory, true));

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/anonymous.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
$s->set(null, StdClassDecorator::class)
1515
->decorate('decorated', 'decorator42')
16-
->args([ref('decorator42')]);
16+
->args([service('decorator42')]);
1717

1818
$s->set('listener_aggregator', FooClass::class)->public()->args([tagged_iterator('listener')]);
1919

src/Symfony/Component/DependencyInjection/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()->defaults()->public();
99
$s->set(BarService::class)
10-
->args([service('FooClass')]);
10+
->args([inline_service('FooClass')]);
1111
};

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/child.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
->parent(BarService::class)
1616
->public()
1717
->decorate('bar', 'b', 1)
18-
->args([ref('b')])
18+
->args([service('b')])
1919
->class('Class2')
2020
->file('file.php')
2121
->parent('bar')

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/defaults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
->autoconfigure()
1414
->autowire()
1515
->tag('t', ['a' => 'b'])
16-
->bind(Foo::class, ref('bar'))
16+
->bind(Foo::class, service('bar'))
1717
->public();
1818

19-
$s->set(Foo::class)->args([ref('bar')])->public();
19+
$s->set(Foo::class)->args([service('bar')])->public();
2020
$s->set('bar', Foo::class)->call('setFoo')->autoconfigure(false);
2121
};

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/instanceof.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
$s = $c->services()->defaults()->public();
1010
$s->instanceof(Prototype\Foo::class)
1111
->property('p', 0)
12-
->call('setFoo', [ref('foo')])
12+
->call('setFoo', [service('foo')])
1313
->tag('tag', ['k' => 'v'])
1414
->share(false)
1515
->lazy()

0 commit comments

Comments
 (0)