-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Feature: decorators #110
Labels
type:feature
New feature
Comments
I made syntax examples. LoggerInterface::class => (new ContainerBuilder())
->callback(fn () => new Logger())
->decorate(fn ($container, $logger) => new LoggerDecorator($logger)); LoggerInterface::class => (new ContainerBuilder())
->callback(fn () => new Logger())
->decorate(LoggerDecorator::class),
LoggerDecorator::class => fn ($container) => new LoggerDecorator($container->get(LoggerInterface::class)), $definitions = [
LoggerInterface::class => fn () => new Logger(),
LoggerDecorator::class => fn ($container) => new LoggerDecorator($container->get(LoggerInterface::class)),
];
$containerBuilder
->decorate(LoggerInterface::class, LoggerDecorator::class)
->decorate(ContainerInterface::class, ContainerDecorator::class); |
Why do decorators better than nested/contextual containers? |
Using decorators we can to substitude any dependencies from PSR container, not only Yii container. Do you have examples with contextual container that solve this problem? |
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would be nice allow to decorate already existing services in container.
I see at least 2 variants of usage:
CompositeContainer
)// config/common.php
At now it parsed as
circle dependency
, but we can modernize this syntax. At now it doesn't matter.2. Decorating already existing services in current container
// config/common.php
or
// config/common.php
// config/common.dev.php
What is the expected result?
In all cases
$container->get(LoggerInterface::class)
should returnLoggerDecorator
What do you get instead?
In the first case we have
CircularReferenceException
. In the second case we haveLoggerInterface
implementation that passed via/* ... */ or
CircularReferenceException`.Additional info
I think we need to think all future features for another cases (I'm not about decorators only).
The text was updated successfully, but these errors were encountered: