Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feature #36388 [DI] deprecate the inline() function from the PHP-DS…
…L 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
-------

647d971 [DI] deprecate the `inline()` function from the PHP-DSL in favor of `service()`
  • Loading branch information
fabpot committed Apr 12, 2020
2 parents 9a6695c + 647d971 commit 6ff7c2e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions UPGRADE-5.1.md
Expand Up @@ -24,6 +24,7 @@ DependencyInjection
configure them explicitly instead.
* Deprecated `Definition::getDeprecationMessage()`, use `Definition::getDeprecation()` instead.
* Deprecated `Alias::getDeprecationMessage()`, use `Alias::getDeprecation()` instead.
* The `inline()` function from the PHP-DSL has been deprecated, use `service()` instead

Dotenv
------
Expand Down
1 change: 1 addition & 0 deletions UPGRADE-6.0.md
Expand Up @@ -24,6 +24,7 @@ DependencyInjection
configure them explicitly instead.
* Removed `Definition::getDeprecationMessage()`, use `Definition::getDeprecation()` instead.
* Removed `Alias::getDeprecationMessage()`, use `Alias::getDeprecation()` instead.
* The `inline()` function from the PHP-DSL has been removed, use `service()` instead

Dotenv
------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ CHANGELOG
* added tags `container.preload`/`.no_preload` to declare extra classes to preload/services to not preload
* deprecated `Definition::getDeprecationMessage()`, use `Definition::getDeprecation()` instead
* deprecated `Alias::getDeprecationMessage()`, use `Alias::getDeprecation()` instead
* deprecated PHP-DSL's `inline()` function, use `service()` instead

5.0.0
-----
Expand Down
Expand Up @@ -92,8 +92,20 @@ function ref(string $id): ReferenceConfigurator

/**
* Creates an inline service.
*
* @deprecated since Symfony 5.1, use service() instead.
*/
function inline(string $class = null): InlineServiceConfigurator
{
trigger_deprecation('symfony/dependency-injection', '5.1', '"%s()" is deprecated, use "service()" instead.', __FUNCTION__);

return new InlineServiceConfigurator(new Definition($class));
}

/**
* Creates an inline service.
*/
function service(string $class = null): InlineServiceConfigurator
{
return new InlineServiceConfigurator(new Definition($class));
}
Expand Down
Expand Up @@ -18,7 +18,7 @@
*/
class InlineServiceConfigurator extends AbstractConfigurator
{
const FACTORY = 'inline';
const FACTORY = 'service';

use Traits\ArgumentTrait;
use Traits\AutowireTrait;
Expand Down
Expand Up @@ -7,5 +7,5 @@
return function (ContainerConfigurator $c) {
$s = $c->services();
$s->set(BarService::class)
->args([inline('FooClass')]);
->args([service('FooClass')]);
};
Expand Up @@ -9,6 +9,6 @@ public function __invoke(ContainerConfigurator $c)
{
$s = $c->services();
$s->set(BarService::class)
->args([inline('FooClass')]);
->args([service('FooClass')]);
}
};

0 comments on commit 6ff7c2e

Please sign in to comment.