Example #1
0
 /**
  * Add a single task to CLI Namespace.
  * Example of inclusion support to a single task:
  *
  *     [php]
  *     $cliOrmNamespace->addTask('my-custom-task', 'MyProject\Cli\Tasks\MyCustomTask');
  *
  * @param string $name CLI Task name
  * @param string $class CLI Task class (FQCN - Fully Qualified Class Name)
  *
  * @return TaskNamespace This object instance
  */
 public function addTask($name, $class)
 {
     $name = self::formatName($name);
     if ($this->hasTask($name)) {
         throw CLIException::cannotOverrideTask($name);
     }
     return $this->overrideTask($name, $class);
 }
Example #2
0
 /**
  * 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;
 }