예제 #1
0
 public static function consoleRun($params)
 {
     //require_once(realpath(__DIR__ . '/../vendor/json-rpc.php'));
     $console_enter = rex_request('watson_console', 'bool', 0);
     if ($console_enter) {
         $console_instances = $params['console_instances'];
         $consoleCommand = new ConsoleCommand();
         $response = '';
         if ($consoleCommand) {
             if ($consoleCommand->getCommand() == 'list') {
                 $response = $consoleCommand->getDocumentationList($console_instances);
             } elseif ($consoleCommand->getCommand() == 'watson:consoleCompletion') {
                 $response = $consoleCommand->getCompletion($console_instances);
             } else {
                 $instances = array();
                 foreach ($console_instances as $console_instance) {
                     if (in_array($consoleCommand->getCommand(), $console_instance->commands())) {
                         $instances[] = $console_instance;
                     }
                 }
                 if (count($instances) == 1) {
                     $instance = $instances[0];
                     if ($consoleCommand->getArgument(1) == 'help') {
                         $response = $consoleCommand->getDocumentation($instance);
                     } else {
                         $method = $consoleCommand->getClearCommand();
                         $class = get_class($instance);
                         $methods = get_class_methods($class);
                         if (in_array($method, $methods)) {
                             // Execute the command
                             $return = $instance->{$method}($consoleCommand);
                             if ($instance->isSuccess()) {
                                 $response = $consoleCommand->response($instance->getMessage(), null);
                             } elseif ($instance->hasError()) {
                                 $response = $consoleCommand->response(null, $instance->getMessage());
                             } else {
                                 $response = $consoleCommand->response('Befehl wurde ausgeführt', null);
                             }
                         } else {
                             $response = $consoleCommand->response(null, 'Befehl gefunden aber keine dazugehörige Methode.');
                         }
                     }
                 } elseif (count($instances) >= 1) {
                     $response = $consoleCommand->response(null, 'Mehrere Klassen mit demselben Befehl gefunden.');
                 } else {
                     $response = $consoleCommand->response(null, 'Keinen Befehl gefunden.');
                 }
             }
         } else {
             $response = $consoleCommand->response(null, 'Befehl nicht gefunden');
         }
         //ob_clean();
         header('Content-type: application/json');
         echo $response;
         exit;
     }
 }
예제 #2
0
 public function make(ConsoleCommand $consoleCommand)
 {
     $params = array();
     $params['active'] = !is_null($consoleCommand->getOption('active')) ? 1 : 0;
     $params['templatename'] = $consoleCommand->getArgument(1);
     $return = $this->createTemplate($params);
     if ($return['success'] != '') {
         return $this->setSuccess($return['success']);
     } else {
         return $this->setError($return['success']);
     }
 }