Exemple #1
0
 private function assembleResult(ExecutionResult $result, WebRequest $request)
 {
     $model = ['error' => null, 'missing' => null, 'success' => null, 'redirect' => null, 'output' => null];
     if ($result instanceof FailedResult) {
         $model['error'] = htmlentities($result->getMessage());
     } else {
         if ($result instanceof NoResult) {
             $model['success'] = true;
             $model['redirect'] = $this->getLastCrumb();
         } else {
             if ($result instanceof RenderedResult) {
                 $model['output'] = $result->getOutput();
             } else {
                 if ($result instanceof MissingParametersResult) {
                     $model['missing'] = $result->getParameters();
                 } else {
                     if ($result instanceof RedirectResult) {
                         $model['success'] = true;
                         $model['redirect'] = $request->getContext()->appended($result->getActionId())->withParameters(new Map($result->getParameters()));
                     } else {
                         if ($result instanceof NotPermittedResult) {
                             $model['error'] = 'You are not permitted to execute this action.';
                             $model['redirect'] = $this->app->getAccessControl($request)->acquirePermission();
                         }
                     }
                 }
             }
         }
     }
     return $model;
 }
Exemple #2
0
 private function printResult(Console $console, ExecutionResult $result, $outFile)
 {
     if ($result instanceof ValueResult) {
         $value = $result->getValue();
         $rendered = (string) $this->renderers->getRenderer($value)->render($value);
         if ($outFile) {
             file_put_contents($outFile, $rendered);
             $console->writeLine("Output written to [{$outFile}]");
         } else {
             $console->writeLine($rendered);
         }
         return self::OK;
     } else {
         if ($result instanceof MissingParametersResult) {
             $console->writeLine();
             $console->writeLine("Missing parameters!");
             foreach ($result->getMissingNames() as $missing) {
                 $console->writeLine('  ' . $missing . ': ' . $result->getException($missing)->getMessage());
             }
             return self::ERROR;
         } else {
             if ($result instanceof NotPermittedResult) {
                 $console->writeLine('Permission denied');
                 return self::ERROR;
             } else {
                 if ($result instanceof FailedResult) {
                     $console->writeLine("Error: " . $result->getMessage());
                     $exception = $result->getException();
                     $console->error(get_class($exception) . ': ' . $exception->getMessage() . ' ' . '[' . $exception->getFile() . ':' . $exception->getLine() . ']' . "\n" . $exception->getTraceAsString());
                     return $exception->getCode() ?: self::ERROR;
                 } else {
                     if ($result instanceof NoResult || $result instanceof RedirectResult) {
                         return self::OK;
                     } else {
                         $console->writeLine('Cannot print [' . (new \ReflectionClass($result))->getShortName() . ']');
                         return self::OK;
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
 private function printResult(Console $console, ExecutionResult $result)
 {
     if ($result instanceof RenderedResult) {
         $console->writeLine((string) $result->getOutput());
         return self::OK;
     } else {
         if ($result instanceof MissingParametersResult) {
             $console->writeLine("Missing parameters " . ValuePrinter::serialize($result->getParameters()));
             return self::ERROR;
         } else {
             if ($result instanceof NotPermittedResult) {
                 $console->writeLine('Permission denied');
                 return self::ERROR;
             } else {
                 if ($result instanceof FailedResult) {
                     $console->writeLine("Error: " . $result->getMessage());
                     $exception = $result->getException();
                     $console->error($exception->getMessage() . ' ' . '[' . $exception->getFile() . ':' . $exception->getLine() . ']' . "\n" . $exception->getTraceAsString());
                     return $exception->getCode() ?: self::ERROR;
                 } else {
                     if ($result instanceof NoResult || $result instanceof RedirectResult) {
                         return self::OK;
                     } else {
                         $console->writeLine('Cannot print [' . (new \ReflectionClass($result))->getShortName() . ']');
                         return self::OK;
                     }
                 }
             }
         }
     }
 }