/** * {@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))); }
/** * {@inheritdoc} */ public function build(SetInterface $identities, ServerRequestInterface $request, HttpResource $definition, SpecificationInterface $specification = null, Range $range = null) : MapInterface { $map = new Map('string', HeaderInterface::class); if ($identities->size() === 0) { return $map; } $path = $request->url()->path(); return $map->put('Link', new Link($identities->reduce(new Set(HeaderValueInterface::class), function (Set $carry, IdentityInterface $identity) use($path) : Set { return $carry->add(new LinkValue(Url::fromString(rtrim((string) $path, '/') . '/' . $identity), 'resource', new Map('string', ParameterInterface::class))); }))); }
/** * Returns true if the iteration has more elements. (In other words, returns * true if next() would return an element rather than throwing an exception.) * @return boolean */ public function hasNext() { return $this->index + 1 < $this->set->size(); }