示例#1
0
 /**
  * mainPipe
  *
  * @param Request       $request
  * @param Response      $response
  * @param callable|null $out
  *
  * @return mixed
  */
 public function mainPipe(Request $request, Response $response, callable $out = null)
 {
     if (empty($request->getAttribute(ResourceKey::getName()))) {
         return $out($request, $response);
     }
     $middlewareProvider = $this->getMiddlewareProvider();
     $mainPipe = new MiddlewarePipe();
     $request = $middlewareProvider->buildPipe($mainPipe, $request);
     return $mainPipe($request, $response, $out);
 }
示例#2
0
 /**
  * getResourceKey
  *
  * @param Request $request
  * @param null    $default
  *
  * @return mixed
  */
 protected function getResourceKey(Request $request, $default = null)
 {
     return $request->getAttribute(ResourceKey::getName(), $default);
 }
 /**
  * buildPipe
  *
  * @param MiddlewarePipe $middlewarePipe
  * @param Request        $request
  *
  * @return MiddlewarePipe
  * @throws ResourceException
  */
 public function buildPipe(MiddlewarePipe $middlewarePipe, Request $request)
 {
     $resourceKey = $request->getAttribute(ResourceKey::getName());
     if ($resourceKey === null) {
         throw new ResourceException('ResourceKey not set: ' . $resourceKey);
     }
     $operations = $this->buildResourceOperationCollection($resourceKey);
     $middlewarePipe->pipeOperations($operations);
     return $request;
 }