/** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return Container Returns itself to support chaining. * * @since 1.0 */ public function register(Container $container) { $ioClass = 'Phoenix\\IO\\IO'; $container->alias('io', $ioClass)->alias('Muse\\IO\\IO', $ioClass)->alias('Muse\\IO\\IOInterface', $ioClass)->share($ioClass, new IO($this->controller->getCommand())); $container->alias('operator.copy', 'Phoenix\\Generaotr\\FileOperator\\CopyOperator')->createObject('Phoenix\\Generaotr\\FileOperator\\CopyOperator'); $closure = function (Container $container) { return new OperatorFactory($container->get('io'), $this->controller->getTagVariables()); }; $container->share('operator.factory', $closure); }
/** * Execute the controller. * * @return boolean True if controller finished execution, false if the controller did not * finish execution. A controller might return false if some precondition for * the controller to run has not been satisfied. * * @since 12.1 * @throws \LogicException * @throws \RuntimeException */ public function execute() { $config = array(); $this->out()->out('Start generating...')->out(); // Prepare basic data. $command = $this->command; $name = $command->getArgument(0); list($type, $task) = explode('.', $this->getTask(), 2); $this->name = $config['name'] = $name; $this->type = $config['type'] = $type; $this->template = $config['template'] = $this->command->getOption('t'); $this->template = $config['table'] = $this->command->getOption('table'); $config['tagVariables'] = (array) $this->tagVariables; $config['migrate'] = $this->command->getOption('migrate'); $config['seed'] = $this->command->getOption('seed'); // Get Handler $task = StringNormalise::toClassNamespace(str_replace('.', '\\', $task)); $class = sprintf(__NAMESPACE__ . '\\%s\\%sController', ucfirst($this->type), $task); if (!class_exists($class)) { throw new \RuntimeException(sprintf('Task %s of type "%s" not support.', $this->getTask(), $this->type)); } /** @var AbstractTaskController $controller */ $controller = new $class($this->container, $this->io, new Structure($config)); $controller->execute(); $this->out()->out('Template generated.'); }
/** * Execute the controller. * * @return boolean True if controller finished execution, false if the controller did not * finish execution. A controller might return false if some precondition for * the controller to run has not been satisfied. * * @since 12.1 * @throws \LogicException * @throws \RuntimeException */ public function execute() { $config = array(); $this->out()->out('Start generating...')->out(); // Prepare basic data. $command = $this->command; $element = $command->getArgument(0, new ElementPrompter('Please enter extension element: ')); list($extension, $name, $element, $group) = $this->extractElement($element); $this->element = $config['element'] = $element; $this->type = $config['extension'] = $extension; $this->name = $config['name'] = $name; $this->group = $config['group'] = $group; $this->template = $config['template'] = $this->command->getOption('t'); $this->client = $config['client'] = $this->command->getOption('c'); if ($this->client == 'admin') { $this->client = $config['client'] = 'administrator'; } // Get Handler $task = array_map('ucfirst', explode('.', $this->getTask())); $task = implode('\\', $task); $class = 'GeneratorBundle\\Controller\\'; $class .= ucfirst($this->type) . '\\' . $task . 'Controller'; if (!class_exists($class)) { throw new \RuntimeException(sprintf('Action %s of %s not support.', $this->type, $this->getTask())); } /** @var AbstractTaskController $controller */ $controller = new $class($this->container, $this->io, new Registry($config)); $controller->execute(); $this->out()->out('Template generated.'); }
/** * Test prompter ask. * * @return void * * @since 2.0 */ public function testAsk() { $this->setStream("y"); $this->instance->ask(); $this->assertEquals(trim($this->io->getTestOutput()), trim('Tell me something: ')); // Ask by invoke $this->setStream("n"); /** @var $prompter AbstractPrompter */ $prompter = $this->instance; $in = $prompter(); $this->assertEquals($in, 'n'); // Set as default in command getArgument $command = new Command('test', $prompter->getIO()); $this->setStream("fly"); $this->io->setTestOutput(''); $in = $command->getArgument(9, $this->instance); $this->assertEquals(trim($this->io->getTestOutput()), trim('Tell me something: ')); $this->assertEquals($in, 'fly'); }
/** * execute * * @return mixed */ public function execute() { define('SQLSYNC_COMMAND', __DIR__); define('SQLSYNC_RESOURCE', JPATH_ROOT . '/resources/sqlsync'); define('SQLSYNC_PROFILE', SQLSYNC_RESOURCE); define('SQLSYNC_LIB', DEVELOPMENT_BUNDLE_ROOT . '/Sqlsync'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); return parent::execute(); }
/** * Configure command information. * * @return void */ public function initialise() { $this->help(<<<HELP Example: generator test Helper PathHelper Generate to: test/Helper/PathHelper.php generator test Helper PathHelper Foo/Bar/PathHelper Generate to: test/Foo/Bar/PathHelper.php HELP ); parent::initialise(); }
/** * clear * * @param AbstractSeeder|string $seeder * * @return static */ public function clear($seeder = null) { if ($seeder === null) { return $this; } if (is_string($seeder)) { $ref = new \ReflectionClass($this); include_once dirname($ref->getFileName()) . '/' . $seeder . '.php'; $seeder = new $seeder(); } $seeder->setDb($this->db); $seeder->setCommand($this->command); $this->command->out('Clear seeder ' . get_class($seeder)); $seeder->doClear(); return $this; }
/** * Initialise command information. * * @return void */ public function initialise() { parent::initialise(); $this->addOption('no-backup')->description('Do not backup database.'); }
/** * Get argument or close this appliction. * * @param integer $arg Argument offset. * @param string $msg Close message. * * @return string Return argument value. */ public function getOrClose($arg, $msg = '') { return $this->command->getOrClose($arg, $msg); }
/** * Get a value from standard input. * * @param string $question The question you want to ask user. * * @return string The input string from standard input. */ public function in($question = '') { return $this->command->in($question); }
/** * configure * * @return void */ public function configure() { parent::configure(); }
/** * Configure command information. * * @return void */ public function initialise() { // $this->addArgument(); parent::initialise(); }
/** * Execute this command. * * @return int|void */ protected function doExecute() { return parent::doExecute(); }
/** * Initialise command information. * * @return void */ public function initialise() { parent::initialise(); }
/** * Configure command information. * * @return void */ public function initialise() { $this->addOption(array('d', 'description'), null, 'Command description'); parent::initialise(); }
/** * getOption * * @param string $name * @param string $default * * @return mixed */ public function getOption($name, $default = null) { return $this->command->getOption($name, $default); }
/** * Test the err method. * * @return void * * @since 2.0 * * @covers Windwalker\Console\Command\AbstractCommand::err */ public function testErr() { $this->instance->getIO()->outputStream = ''; $this->instance->err('errrr', false); $this->assertEquals('errrr', $this->instance->getIO()->getTestOutput()); }
/** * Configure command information. * * @return void */ public function configure() { $this->addOption(array('d', 'description'), null, 'Command description'); parent::configure(); }
/** * Configure command information. * * @return void */ public function initialise() { $this->addOption('a')->alias('admin')->description('Use admin client.'); $this->addOption('w')->alias('windwalker')->description('Use Windwalker sum style.'); parent::initialise(); }
/** * testError * * @return void * * @expectedException \Exception */ public function testError() { $this->instance->error('test'); }
/** * Configure command information. * * @return void */ public function initialise() { $this->addGlobalOption('g')->alias('group')->description('The group id, default will use SuperUser group.'); parent::initialise(); }
/** * Configure command information. * * @return void */ public function configure() { // $this->addArgument(); parent::configure(); }
/** * initialise * * @return void */ public function initialise() { parent::initialise(); $this->addCommand(new GenerateCommand()); }