getContainer() public static method

Returns the currently active global container.
public static getContainer ( ) : League\Container\ContainerInterface
return League\Container\ContainerInterface
示例#1
0
文件: Temporary.php 项目: jjok/Robo
 /**
  * Provides direct access to the collection of temporaries, if necessary.
  */
 public static function getCollection()
 {
     if (!static::$collection) {
         static::$collection = \Robo\Robo::getContainer()->get('collection');
         register_shutdown_function(function () {
             static::complete();
         });
     }
     return static::$collection;
 }
示例#2
0
 protected function instantiateCommandClass($commandClass)
 {
     $container = Robo::getContainer();
     // Register the RoboFile with the container and then immediately
     // fetch it; this ensures that all of the inflectors will run.
     $commandFileName = "{$commandClass}Commands";
     $container->share($commandFileName, $commandClass);
     $roboCommandFileInstance = $container->get($commandFileName);
     if ($roboCommandFileInstance instanceof BuilderAwareInterface) {
         $builder = $container->get('collectionBuilder', [$roboCommandFileInstance]);
         $roboCommandFileInstance->setBuilder($builder);
     }
     return $roboCommandFileInstance;
 }
示例#3
0
文件: ApiGenTest.php 项目: jjok/Robo
 protected function _before()
 {
     $this->apigen = test::double('Robo\\Task\\ApiGen\\ApiGen', ['executeCommand' => null, 'output' => new \Symfony\Component\Console\Output\NullOutput(), 'logger' => new \Psr\Log\NullLogger()]);
     $this->container = Robo::getContainer();
 }
示例#4
0
 public function testInitCommand()
 {
     $container = \Robo\Robo::getContainer();
     $app = $container->get('application');
     $app->addInitRoboFileCommand(getcwd() . '/testRoboFile.php', 'RoboTestClass');
     $argv = ['placeholder', 'init'];
     $status = $this->runner->run($argv, $this->guy->capturedOutputStream(), $app);
     $this->guy->seeInOutput('testRoboFile.php will be created in the current directory');
     $this->assertEquals(0, $status);
     $this->assertTrue(file_exists('testRoboFile.php'));
     $commandContents = file_get_contents('testRoboFile.php');
     unlink('testRoboFile.php');
     $this->assertContains('class RoboTestClass', $commandContents);
 }
示例#5
0
 public function testInitCommand()
 {
     $container = \Robo\Robo::getContainer();
     $app = $container->get('application');
     $app->addInitRoboFileCommand('testRoboFile', 'RoboTestClass');
     $argv = ['placeholder', 'init'];
     $this->runner->execute($argv, Robo::output());
     $this->assertTrue(file_exists('testRoboFile'));
     $commandContents = file_get_contents('testRoboFile');
     unlink('testRoboFile');
     $this->assertContains('class RoboTestClass', $commandContents);
 }
示例#6
0
文件: Runner.php 项目: jjok/Robo
 /**
  * @param string|BuilderAwareInterface|ContainerAwareInterface  $commandClass
  *
  * @return null|object
  */
 protected function instantiateCommandClass($commandClass)
 {
     $container = Robo::getContainer();
     // Register the RoboFile with the container and then immediately
     // fetch it; this ensures that all of the inflectors will run.
     // If the command class is already an instantiated object, then
     // just use it exactly as it was provided to us.
     if (is_string($commandClass)) {
         $reflectionClass = new \ReflectionClass($commandClass);
         if ($reflectionClass->isAbstract()) {
             return;
         }
         $commandFileName = "{$commandClass}Commands";
         $container->share($commandFileName, $commandClass);
         $commandClass = $container->get($commandFileName);
     }
     // If the command class is a Builder Aware Interface, then
     // ensure that it has a builder.  Every command class needs
     // its own collection builder, as they have references to each other.
     if ($commandClass instanceof BuilderAwareInterface) {
         $builder = $container->get('collectionBuilder', [$commandClass]);
         $commandClass->setBuilder($builder);
     }
     if ($commandClass instanceof ContainerAwareInterface) {
         $commandClass->setContainer($container);
     }
     return $commandClass;
 }