Exemplo n.º 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;
 }
Exemplo n.º 2
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;
                     }
                 }
             }
         }
     }
 }