Beispiel #1
0
 /**
  * Execute the given API action class, pass the input and return its response.
  *
  * @param string|ControllerInterface $controller
  * @param User $actor
  * @param array $queryParams
  * @param array $body
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function send($controller, User $actor, array $queryParams = [], array $body = [])
 {
     $request = ServerRequestFactory::fromGlobals(null, $queryParams, $body)->withAttribute('actor', $actor);
     if (is_string($controller)) {
         $controller = $this->container->make($controller);
     }
     if (!$controller instanceof ControllerInterface) {
         throw new InvalidArgumentException('Endpoint must be an instance of ' . ControllerInterface::class);
     }
     try {
         return $controller->handle($request);
     } catch (Exception $e) {
         return $this->errorHandler->handle($e);
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function __invoke($e, Request $request, Response $response, callable $out = null)
 {
     return $this->errorHandler->handle($e);
 }