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
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
Copy link
Member Author

@mnapoli mnapoli commented Apr 16, 2015

Implemented in #249

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

No branches or pull requests

1 participant