Skip to content

Instantly share code, notes, and snippets.

@digitalkaoz
Last active December 21, 2015 06:19
Show Gist options
  • Select an option

  • Save digitalkaoz/6263251 to your computer and use it in GitHub Desktop.

Select an option

Save digitalkaoz/6263251 to your computer and use it in GitHub Desktop.
custom injections for different uses of a service
<?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();
}
}
@digitalkaoz

Copy link
Copy Markdown
Author

CommandA should log into a file, CommandB should log to console...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment