Last active
December 21, 2015 06:19
-
-
Save digitalkaoz/6263251 to your computer and use it in GitHub Desktop.
custom injections for different uses of a service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // $container->get('service') | |
| class Service | |
| { | |
| public function setLogger(LoggerInterface $logger) | |
| { | |
| $this->logger = $logger; | |
| } | |
| public function getLogger() | |
| { | |
| return $this->logger; | |
| } | |
| } | |
| class LoggerA implements LoggerInterface{} | |
| class LoggerB implements LoggerInterface{} | |
| class CommandA extends Command | |
| { | |
| public function execute() | |
| { | |
| $service = $this->container->get('service'); | |
| //should be LoggerA | |
| $logger = $service->getLogger(); | |
| } | |
| } | |
| class CommandB extends Command | |
| { | |
| public function execute() | |
| { | |
| $service = $this->container->get('service'); | |
| //should be LoggerB | |
| $logger = $service->getLogger(); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CommandA should log into a file, CommandB should log to console...