diff --git a/lib/Doctrine/Common/Cli/CliController.php b/lib/Doctrine/Common/Cli/CliController.php index 1713d9067..5bb26de4b 100644 --- a/lib/Doctrine/Common/Cli/CliController.php +++ b/lib/Doctrine/Common/Cli/CliController.php @@ -67,13 +67,13 @@ class CliController extends AbstractNamespace { $this->setPrinter($printer); $this->setConfiguration($config); - + // Include core namespaces of tasks $ns = 'Doctrine\Common\Cli\Tasks'; $this->addNamespace('Core') ->addTask('help', $ns . '\HelpTask') ->addTask('version', $ns . '\VersionTask'); - + $ns = 'Doctrine\ORM\Tools\Cli\Tasks'; $this->addNamespace('Orm') ->addTask('clear-cache', $ns . '\ClearCacheTask') @@ -83,13 +83,13 @@ class CliController extends AbstractNamespace ->addTask('run-dql', $ns . '\RunDqlTask') ->addTask('schema-tool', $ns . '\SchemaToolTask') ->addTask('version', $ns . '\VersionTask'); - + $ns = 'Doctrine\DBAL\Tools\Cli\Tasks'; $this->addNamespace('Dbal') ->addTask('run-sql', $ns . '\RunSqlTask') ->addTask('version', $ns . '\VersionTask'); } - + /** * Add a single task to CLI Core Namespace. This method acts as a delegate. * Example of inclusion support to a single task: @@ -105,10 +105,10 @@ class CliController extends AbstractNamespace public function addTask($name, $class) { $this->getNamespace('Core')->addTask($name, $class); - + return $this; } - + /** * Processor of CLI Tasks. Handles multiple task calls, instantiate * respective classes and run them. @@ -119,37 +119,40 @@ class CliController extends AbstractNamespace { // Remove script file argument $scriptFile = array_shift($args); - + // If not arguments are defined, include "help" if (empty($args)) { array_unshift($args, 'Core:Help'); } - + // Process all sent arguments $args = $this->_processArguments($args); try { $this->getPrinter()->writeln('Doctrine Command Line Interface' . PHP_EOL, 'HEADER'); - + // Handle possible multiple tasks on a single command foreach($args as $taskData) { $taskName = $taskData['name']; $taskArguments = $taskData['args']; - + $this->runTask($taskName, $taskArguments); } + + return true; } catch (\Exception $e) { $message = $taskName . ' => ' . $e->getMessage(); - + if (isset($taskArguments['trace']) && $taskArguments['trace']) { $message .= PHP_EOL . PHP_EOL . $e->getTraceAsString(); } - + $this->getPrinter()->writeln($message, 'ERROR'); + + return false; } - } - + /** * Executes a given CLI Task * @@ -160,14 +163,14 @@ class CliController extends AbstractNamespace { // Retrieve namespace name, task name and arguments $taskPath = explode(':', $name); - + // Find the correct namespace where the task is defined $taskName = array_pop($taskPath); $taskNamespace = $this->_retrieveTaskNamespace($taskPath); - + $taskNamespace->runTask($taskName, $args); } - + /** * Processes arguments and returns a structured hierachy. * Example: @@ -211,12 +214,12 @@ class CliController extends AbstractNamespace $regex = '/\s*[,]?\s*"([^"]*)"|\s*[,]?\s*([^,]*)/i'; $preparedArgs = array(); $out = & $preparedArgs; - + foreach ($args as $arg){ // --foo --bar=baz if (substr($arg, 0, 2) == '--'){ $eqPos = strpos($arg, '='); - + // --foo if ($eqPos === false){ $key = substr($arg, 2); @@ -245,7 +248,7 @@ class CliController extends AbstractNamespace // -abc } else { $chars = str_split(substr($arg, 1)); - + foreach ($chars as $char){ $key = $char; $out[$key] = isset($out[$key]) ? $out[$key] : true; @@ -261,7 +264,7 @@ class CliController extends AbstractNamespace $out = & $preparedArgs[$key]['args']; } } - + return $preparedArgs; } @@ -276,25 +279,25 @@ class CliController extends AbstractNamespace { $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; } } \ No newline at end of file