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

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

Comments

Projects
None yet
1 participant
@mnapoli
Member

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 referenced this issue Apr 12, 2015

Merged

v5.0 #200

31 of 31 tasks complete

mnapoli added a commit that referenced this issue Apr 16, 2015

@mnapoli

This comment has been minimized.

Show comment
Hide comment
@mnapoli

mnapoli Apr 16, 2015

Member

Implemented in #249

Member

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