Skip to content
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

DI\decorate() to decorate a previous definition #248

Closed
mnapoli opened this issue Apr 12, 2015 · 1 comment
Closed

DI\decorate() to decorate a previous definition #248

mnapoli opened this issue Apr 12, 2015 · 1 comment
Labels
Milestone

Comments

@mnapoli
Copy link
Member

@mnapoli mnapoli commented Apr 12, 2015

Following #214 (Extend and decorate definitions) this issue is targeted at decorating a previous definition using a callable.

Here is an example using a new DI\decorate() function:

    // Add custom behavior
    LoggerInterface::class => DI\decorate(function (LoggerInterface $logger) {
        $logger->setSomething('foo');
    }),
    // Return another object
    LoggerInterface::class => DI\decorate(function (LoggerInterface $logger) {
        return new Wrapper($logger);
    }),

It could also be implemented using factory() but it's less explicit:

    LoggerInterface::class => DI\factory(function (LoggerInterface $logger) {
        return new Wrapper($logger);
    }),
@mnapoli mnapoli added the enhancement label Apr 12, 2015
@mnapoli mnapoli added this to the 5.0 milestone Apr 12, 2015
@mnapoli mnapoli mentioned this issue Apr 12, 2015
31 of 31 tasks complete
mnapoli added a commit that referenced this issue Apr 16, 2015
@mnapoli
Copy link
Member Author

@mnapoli mnapoli commented Apr 16, 2015

Implemented in #249

@mnapoli mnapoli closed this Apr 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.