Skip to content

Commit 8198cf3

Browse files
javiereguiluznicolas-grekas
authored andcommitted
[DI] Renamed some PHP-DSL functions
1 parent 4410e25 commit 8198cf3

File tree

13 files changed

+65
-52
lines changed

13 files changed

+65
-52
lines changed

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`

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
}

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));

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

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
};

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')

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
};

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()

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()->defaults()->public();
1111
$s->set(BarService::class)
12-
->args([service('FooClass')]);
12+
->args([inline_service('FooClass')]);
1313
}
1414
};

Tests/Fixtures/config/php7.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
;
1212
$c->services()->defaults()->public()
1313
(Foo::class)
14-
->arg('$bar', ref('bar'))
14+
->arg('$bar', service('bar'))
1515
->public()
1616
('bar', Foo::class)
1717
->call('setFoo')

0 commit comments

Comments
 (0)