/** * @param PaginatedDataInterface $data * * @return void */ private function addPagingLinksIfNeeded(PaginatedDataInterface $data) { if ($data->isCollection() === true && (0 < $data->getOffset() || $data->hasMoreItems() === true) && $this->getOriginalUri() !== null) { $links = []; $linkClosure = $this->createLinkClosure($data->getLimit()); $prev = DocumentInterface::KEYWORD_PREV; $next = DocumentInterface::KEYWORD_NEXT; $data->getOffset() <= 0 ?: ($links[$prev] = $linkClosure(max(0, $data->getOffset() - $data->getLimit()))); $data->hasMoreItems() === false ?: ($links[$next] = $linkClosure($data->getOffset() + $data->getLimit())); $this->withLinks($links); } }
/** * @param PaginatedDataInterface $data * @param IncludeParameterInterface[] $paths * * @return RelationshipStorageInterface * * @SuppressWarnings(PHPMD.ElseExpression) */ private function readRelationships(PaginatedDataInterface $data, array $paths) { $result = $this->getFactory()->createRelationshipStorage(); if (empty($data->getData()) === false && empty($paths) === false) { $modelStorage = $this->getFactory()->createModelStorage($this->getModelSchemes()); $modelsAtPath = $this->getFactory()->createTagStorage(); // we gonna send this storage via function params so it is an equivalent for &array $classAtPath = new ArrayObject(); $model = null; if ($data->isCollection() === true) { foreach ($data->getData() as $model) { $uniqueModel = $modelStorage->register($model); if ($uniqueModel !== null) { $modelsAtPath->register($uniqueModel, static::$rootPath); } } } else { $model = $data->getData(); $uniqueModel = $modelStorage->register($model); if ($uniqueModel !== null) { $modelsAtPath->register($uniqueModel, static::$rootPath); } } $classAtPath[static::$rootPath] = get_class($model); foreach ($this->getPaths($paths) as list($parentPath, $childPaths)) { $this->loadRelationshipsLayer($result, $modelsAtPath, $classAtPath, $modelStorage, $parentPath, $childPaths); } } return $result; }