parseCommand() public static method

Parses command and returns an array which contains class, method and arguments of the command
public static parseCommand ( string $command ) : array
$command string
return array
Beispiel #1
0
 /**
  * Parses given command, creates new class object and calls its method via call_user_func_array
  * @param string $command
  * @return mixed
  */
 public static function parseAndRunCommand($command)
 {
     try {
         list($class, $method, $args) = TaskManager::parseCommand($command);
         if (!class_exists($class)) {
             TaskLoader::loadController($class);
         }
         $obj = new $class();
         if (!method_exists($obj, $method)) {
             throw new TaskManagerException('method ' . $method . ' not found in class ' . $class);
         }
         return call_user_func_array(array($obj, $method), $args);
     } catch (\Exception $e) {
         echo 'Caught an exception: ' . get_class($e) . ': ' . PHP_EOL . $e->getMessage() . PHP_EOL;
         return false;
     }
 }