Returns the currently active global container.
public static getContainer ( ) : League\Container\ContainerInterface | ||
리턴 | League\Container\ContainerInterface |
/** * 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; }
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; }
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(); }
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); }
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); }
/** * @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; }