/**
  * Execute this middleware.
  *
  * @param  ServerRequestInterface $request  The PSR7 request.
  * @param  ResponseInterface      $response The PSR7 response.
  * @param  callable               $next     The Next middleware.
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $input = $request->getQueryParams();
     if ($this->inputLocation === 'body') {
         $input = (array) $request->getParsedBody();
     }
     list($success, $filteredInput, $error) = Filterer::filter($this->filters, $input);
     if (!$success) {
         return $response->withStatus(400, 'Bad Request')->withBody($this->streamFactory->make($error));
     }
     $this->container['input'] = $filteredInput;
     return $next($request, $response);
 }
Exemplo n.º 2
0
 /**
  * @see \DominionEntepries\Filterer::filter().
  *
  * @param array $spec    The filter specification.
  * @param array $input   The data to be filtered.
  * @param array $options Array of filterer options.
  *
  * @return array
  */
 public static final function filter(array $spec, array $input, array $options = [])
 {
     BaseFilterer::setFilterAliases(self::getFilterAliases() + BaseFilterer::getFilterAliases());
     return BaseFilterer::filter($spec, $input, $options);
 }