Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: wodzik
  5.  * Date: 19.09.16
  6.  * Time: 18:05
  7.  */
  8.  
  9. namespace BrConsole;
  10.  
  11.  
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\DependencyInjection\ContainerInterface;
  16. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  17.  
  18. abstract class ContainerAwareCommand extends Command implements ContainerAwareInterface  {
  19.   /**
  20.    * @var ContainerInterface|null
  21.    */
  22.   protected $container;
  23.  
  24.   /**
  25.    * @return ContainerInterface
  26.    *
  27.    * @throws \LogicException
  28.    */
  29.   protected function getContainer()
  30.   {
  31.     if (null === $this->container) {
  32.       $console = $this->getApplication();
  33.       if (null === $console) {
  34.         throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.');
  35.       }
  36.  
  37.       $this->container = $console->getContainer();
  38.     }
  39.  
  40.     return $this->container;
  41.   }
  42.  
  43.   public function get($service) {
  44.     return $this->getContainer()->get($service);
  45.   }
  46.  
  47.   /**
  48.    * {@inheritdoc}
  49.    */
  50.   public function setContainer(ContainerInterface $container = null)
  51.   {
  52.     $this->container = $container;
  53.   }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement