10000 [DI] Add support for defining method calls in InlineServiceConfigurator by Lctrs · Pull Request #34916 · symfony/symfony · GitHub
[go: up one dir, main page]

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

Conversation

Lctrs
Copy link
Contributor
@Lctrs Lctrs commented Dec 10, 2019
Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR N/A

@@ -23,6 +23,7 @@ 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.

@Lctrs
Copy link
Contributor Author
Lctrs commented Dec 10, 2019

Test failure in the Process component. Not related.

@nicolas-grekas
Copy link
Member

Can you please add a corresponding line in the CHANGELOG of the component?

@Lctrs
Copy link
Contributor Author
Lctrs commented Dec 11, 2019

@nicolas-grekas Done. Is the wording okay for you ?

@nicolas-grekas
Copy link
Member

Thank you @Lctrs.

nicolas-grekas added a commit that referenced this pull request Dec 13, 2019
…rviceConfigurator (Lctrs)

This PR was squashed before being merged into the 5.1-dev branch.

Discussion
----------

[DI] Add support for defining method calls in InlineServiceConfigurator

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | N/A

Commits
-------

5af6e21 [DI] Add support for defining method calls in InlineServiceConfigurator
@nicolas-grekas nicolas-grekas merged commit 5af6e21 into symfony:master Dec 13, 2019
@Lctrs Lctrs deleted the patch-1 branch December 13, 2019 12:13
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
@fabpot fabpot mentioned this pull request May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0