Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] Add theconstructor option to service definition#18070

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

alexandre-daubois
Copy link
Member

@OskarStarkOskarStark added the Waiting Code MergeDocs for features pending to be merged labelMar 18, 2023
@carsonbotcarsonbot modified the milestones:6.3,nextMar 18, 2023
fabpot added a commit to symfony/symfony that referenced this pull requestMar 31, 2023
…utoconfigure]` (alexandre-daubois)This PR was merged into the 6.3 branch.Discussion----------[DependencyInjection] Add `constructor` option to `#[Autoconfigure]`| Q             | A| ------------- | ---| Branch?       | 6.3| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Tickets       | _NA_| License       | MIT| Doc PR        |symfony/symfony-docs#18070Following [this discussion](https://twitter.com/nicolasgrekas/status/1634259754104025088?s=20) on Twitter, here is my try to use service factories with attributes. This PR adds the `constructor` option to the `Autoconfigure` attribute, and more generally, the `constructor` option on service definitions.This allows to write services using a factory this way:```php#[Autoconfigure(constructor: 'create')]class FactoryAttributeService{    public function __construct(private readonly string $bar)    {    }    public function getBar(): string    {        return $this->bar;    }    public static function create(string $foo = 'foo'): static    {        return new self($foo);    }}```Commits-------8dda3f0 [DependencyInjection] Add `constructor` option to services declaration and to `#[Autoconfigure]`
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull requestMar 31, 2023
…utoconfigure]` (alexandre-daubois)This PR was merged into the 6.3 branch.Discussion----------[DependencyInjection] Add `constructor` option to `#[Autoconfigure]`| Q             | A| ------------- | ---| Branch?       | 6.3| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Tickets       | _NA_| License       | MIT| Doc PR        |symfony/symfony-docs#18070Following [this discussion](https://twitter.com/nicolasgrekas/status/1634259754104025088?s=20) on Twitter, here is my try to use service factories with attributes. This PR adds the `constructor` option to the `Autoconfigure` attribute, and more generally, the `constructor` option on service definitions.This allows to write services using a factory this way:```php#[Autoconfigure(constructor: 'create')]class FactoryAttributeService{    public function __construct(private readonly string $bar)    {    }    public function getBar(): string    {        return $this->bar;    }    public static function create(string $foo = 'foo'): static    {        return new self($foo);    }}```Commits-------8dda3f0b77 [DependencyInjection] Add `constructor` option to services declaration and to `#[Autoconfigure]`
@javiereguiluzjaviereguiluz removed the Waiting Code MergeDocs for features pending to be merged labelJun 6, 2023
@javiereguiluzjaviereguiluz modified the milestones:next,6.3Jun 6, 2023
@javiereguiluz
Copy link
Member

I totally missed this one. Thanks for this contribution Alex!

alexandre-daubois reacted with hooray emoji

@javiereguiluzjaviereguiluz merged commite08dc4c intosymfony:6.3Jun 6, 2023
@alexandre-dauboisalexandre-daubois deleted the service-constructor branchJune 6, 2023 08:48
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
6.3
Development

Successfully merging this pull request may close these issues.

4 participants
@alexandre-daubois@javiereguiluz@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp