Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function buildFrom(ServerRequestInterface $request, HttpResource $definition) : SpecificationInterface
 {
     $specification = null;
     foreach ($request->query() as $parameter) {
         if ($parameter->name() === 'range') {
             /*
             range is used in QueryExtractor to determine the range of the
             resources to return and thus can't be used as a filter
             */
             continue;
         }
         if (!$definition->properties()->contains($parameter->name())) {
             throw new FilterNotApplicableException($parameter->name());
         }
         if ($specification === null) {
             $specification = new Filter($parameter->name(), $parameter->value());
         } else {
             $specification = $specification->and(new Filter($parameter->name(), $parameter->value()));
         }
     }
     if ($specification === null) {
         throw new NoFilterFoundException();
     }
     return $specification;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function extract(ServerRequestInterface $request) : Range
 {
     if (!$request->headers()->has('Range')) {
         throw new RangeNotFoundException();
     }
     return new Range($request->headers()->get('Range')->values()->current()->firstPosition(), $request->headers()->get('Range')->values()->current()->lastPosition());
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function extract(ServerRequestInterface $request) : Range
 {
     if (!$request->query()->has('range') || !is_array($request->query()->get('range')->value()) || count($request->query()->get('range')->value()) !== 2) {
         throw new RangeNotFoundException();
     }
     return new Range($request->query()->get('range')->value()[0], $request->query()->get('range')->value()[1]);
 }