示例#1
0
 /**
  * {@inheritdoc}
  */
 public function build(SetInterface $identities, ServerRequestInterface $request, HttpResource $definition, SpecificationInterface $specification = null, Range $range = null) : MapInterface
 {
     $map = new Map('string', HeaderInterface::class);
     if (!$definition->isRangeable()) {
         return $map;
     }
     $map = $map->put('Accept-Ranges', new AcceptRanges(new AcceptRangesValue('resources')));
     if (!$range instanceof Range) {
         return $map;
     }
     $length = $range->lastPosition() - $range->firstPosition();
     return $map->put('Content-Range', new ContentRange(new ContentRangeValue('resources', $range->firstPosition(), $last = $range->firstPosition() + $identities->size(), $identities->size() < $length ? $last : $last + $length)));
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function all(string $name, SpecificationInterface $specification = null, Range $range = null) : SetInterface
 {
     $definition = $this->capabilities->get($name);
     if ($range !== null && !$definition->isRangeable()) {
         throw new ResourceNotRangeableException();
     }
     if ($specification !== null) {
         $query = '?' . $this->specificationTranslator->translate($specification);
     }
     $url = $this->resolver->resolve((string) $definition->url(), $query ?? (string) $definition->url());
     $url = Url::fromString($url);
     $headers = new Map('string', HeaderInterface::class);
     if ($range !== null) {
         $headers = $headers->put('Range', new RangeHeader(new RangeValue('resource', $range->firstPosition(), $range->lastPosition())));
     }
     $response = $this->transport->fulfill(new Request($url, new Method(Method::GET), new ProtocolVersion(1, 1), new Headers($headers), new NullStream()));
     return $this->serializer->denormalize($response, 'rest_identities', null, ['definition' => $definition]);
 }