/** * Run task if it exists. */ public function runTask(array $argv) { $options = getopt($this->options); if (!isset($options['t'])) { $this->logger->error('No task defined, please define the desired task as first argument. Ej; ./cli.php -t WordFrequency'); } else { $tasksNamespace = 'App\\CLI\\'; $taskClass = $tasksNamespace . $options['t'] . self::TASK_CLASS_SUFFIX; if (class_exists($taskClass)) { $taskInstance = new $taskClass($this->logger); $taskInstance->main(getopt($this->options, $taskInstance->longOptions)); } else { $this->logger->error("Unknown task {$taskClass}."); } } }