/** * Retrieve an instantiated CLI Task by given its name. * * @param string $name CLI Task name * * @return AbstractTask */ public function getTask($name) { // Check if task exists in namespace if ($this->hasTask($name)) { $taskClass = $this->_tasks[self::formatName($name)]; return new $taskClass($this); } throw CliException::taskDoesNotExist($name, $this->getFullName()); }
/** * Retrieve the correct namespace given a namespace path * * @param array $namespacePath CLI Namespace path * * @return AbstractNamespace */ private function _retrieveTaskNamespace($namespacePath) { $taskNamespace = $this; $currentNamespacePath = ''; // Consider possible missing namespace (ie. "help") and forward to "core" if (count($namespacePath) == 0) { $namespacePath = array('Core'); } // Loop through each namespace foreach ($namespacePath as $namespaceName) { $taskNamespace = $taskNamespace->getNamespace($namespaceName); // If the given namespace returned "null", throw exception if ($taskNamespace === null) { throw CliException::namespaceDoesNotExist($namespaceName, $currentNamespacePath); } $currentNamespacePath = (!empty($currentNamespacePath) ? ':' : '') . $taskNamespace->getName(); } return $taskNamespace; }