/** * 呼び出し元のコントローラーから呼び出すモデルを判定しrun()を実行します。 */ protected function execute(InputInterface $input, OutputInterface $output) { // 実行中チェック $name = sprintf('%s.%s', $this->getName(), $input->getArgument('service')); $this->getContainer()->get('lib.command.manager')->createExecuting($name); $serviceName = $input->getArgument('service'); $controllerClass = get_class($this); // サービスのディレクトリ $serviceDir = preg_replace('/Command$/', '', basename(str_replace('\\', '/', $controllerClass))); // サービスのクラス名 $clazz = ''; foreach (explode('-', $serviceName) as $_word) { $clazz .= ucwords($_word); } if ($clazz === '') { throw new IllegalArgumentException('serviceが指定されていません。'); } $tmp = sprintf('Service\\%s\\%s', $serviceDir, $clazz); $classPath = preg_replace('/Command.*Command$/', $tmp, $controllerClass); $service = new $classPath(parent::getContainer(), $this, $input, $output); if (is_null($service)) { throw new \ErrorException('Service is not found.'); } $response = $service->run(); // 実行中チェックを削除 $this->getContainer()->get('lib.command.manager')->removeExecuting($name); return $response; }
/** * @inheritdoc */ protected function getContainer() { return parent::getContainer(); }