Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: wodzik
- * Date: 19.09.16
- * Time: 18:05
- */
- namespace BrConsole;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- use Symfony\Component\DependencyInjection\ContainerAwareInterface;
- abstract class ContainerAwareCommand extends Command implements ContainerAwareInterface {
- /**
- * @var ContainerInterface|null
- */
- protected $container;
- /**
- * @return ContainerInterface
- *
- * @throws \LogicException
- */
- protected function getContainer()
- {
- if (null === $this->container) {
- $console = $this->getApplication();
- if (null === $console) {
- throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.');
- }
- $this->container = $console->getContainer();
- }
- return $this->container;
- }
- public function get($service) {
- return $this->getContainer()->get($service);
- }
- /**
- * {@inheritdoc}
- */
- public function setContainer(ContainerInterface $container = null)
- {
- $this->container = $container;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement