Skip to content

[DI] Add support for defining method calls in InlineServiceConfigurator #34916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
-----

* added support to autowire public typed properties in php 7.4
* added support for defining method calls, a configurator, and property setters in `InlineServiceConfigurator`

5.0.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ class InlineServiceConfigurator extends AbstractConfigurator
use Traits\ArgumentTrait;
use Traits\AutowireTrait;
use Traits\BindTrait;
use Traits\CallTrait;
Copy link
Member

@nicolas-grekas nicolas-grekas Dec 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could add also ConfiguratorTrait and PropertyTrait
but please confirm on a real app that this actually works before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it in a app powered by Symfony 4.3 before landing this PR and it worked like a charm, even with nested inlines.

For reference, service is defined like this :

$services
    ->set(EventStoreConnection::class)
    ->factory([EventStoreConnectionFactory::class, 'createFromConnectionString'])
    ->args([
        '%env(resolve:EVENT_STORE_DSN)%',
        inline(ConnectionSettings::class)
            ->factory([
                inline(ConnectionSettingsBuilder::class)
                    ->call('useCustomLogger', [ref(LoggerInterface::class)]),
                'build'
            ])
    ]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I get this :

<?php

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
// Returns the public 'Prooph\EventStore\Async\EventStoreConnection' shared service.

include_once $this->targetDirs[3].'/vendor/prooph/event-store-client/src/EventStoreConnectionFactory.php';
include_once $this->targetDirs[3].'/vendor/prooph/event-store-client/src/ConnectionSettings.php';
include_once $this->targetDirs[3].'/vendor/prooph/event-store-client/src/ConnectionSettingsBuilder.php';

$a = new \Prooph\EventStoreClient\ConnectionSettingsBuilder();
$a->useCustomLogger(($this->privates['logger'] ?? ($this->privates['logger'] = new \Symfony\Component\HttpKernel\Log\Logger())));

return $this->services['Prooph\\EventStore\\Async\\EventStoreConnection'] = \Prooph\EventStoreClient\EventStoreConnectionFactory::createFromConnectionString($this->getEnv('resolve:EVENT_STORE_DSN'), $a->build());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks, can you add ConfiguratorTrait and PropertyTrait please and validate they're ok too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are ! PR updated.

use Traits\ConfiguratorTrait;
use Traits\FactoryTrait;
use Traits\FileTrait;
use Traits\LazyTrait;
use Traits\ParentTrait;
use Traits\PropertyTrait;
use Traits\TagTrait;

public function __construct(Definition $definition)
Expand Down