grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026validateUrl($url)) { $this->self = $url; } else { $this->getLogger()->error(LinksMessage::INVALID_URL_PARAMETER); } return clone $this; } /** * Tells Links that you intend to display pagination links even if you do not set the pagination values. * @return Links */ public function withPagination() { $this->hasPagination = true; return clone $this; } /** * @param string $url * @return Links */ public function withFirst($url) { $this->hasPagination = true; if ($this->validateUrl($url)) { $this->first = $url; } else { $this->getLogger()->error(LinksMessage::INVALID_URL_PARAMETER); } return clone $this; } /** * @param string $url * @return Links */ public function withPrev($url) { $this->hasPagination = true; if ($this->validateUrl($url)) { $this->prev = $url; } else { $this->getLogger()->error(LinksMessage::INVALID_URL_PARAMETER); } return clone $this; } /** * @param string $url * @return Links */ public function withNext($url) { $this->hasPagination = true; if ($this->validateUrl($url)) { $this->next = $url; } else { $this->getLogger()->error(LinksMessage::INVALID_URL_PARAMETER); } return clone $this; } /** * @param string $url * @return Links */ public function withLast($url) { $this->hasPagination = true; if ($this->validateUrl($url)) { $this->last = $url; } else { $this->getLogger()->error(LinksMessage::INVALID_URL_PARAMETER); } return clone $this; } /** * @param array|null $meta * @return Links */ public function withMeta($meta) { if ($this->meta === null) { $this->meta = $meta; } else { $this->meta = array_merge($this->meta, $meta); } return clone $this; } /** * @param string $url * @return Links */ public function withHref($url) { $this->href = $url; return clone $this; } /** * @param string $related * @return Links */ public function withRelated($related) { $this->related = $related; return clone $this; } /** * @return array */ public function toJsonApiResponse() { $response = array(); if ($this->hasSelf()) { $response['self'] = $this->self; } if ($this->hasHref()) { $response['href'] = $this->href; } if ($this->hasMeta()) { $response['meta'] = $this->meta; } if ($this->hasPagination()) { if ($this->first !== null) { $response['first'] = $this->first; } if ($this->prev !== null) { $response['prev'] = $this->prev; } if ($this->next !== null) { $response['next'] = $this->next; } if ($this->last !== null) { $response['last'] = $this->last; } } if ($this->hasRelated()) { $response['related'] = $this->related; } return $response; } /** * @return bool */ private function hasPagination() { return $this->hasPagination; } /** * @return bool */ private function hasSelf() { return $this->self !== null; } /** * @return bool */ private function hasHref() { return $this->href !== null; } /** * @return bool */ private function hasMeta() { return $this->meta !== null; } /** * @return bool */ private function hasRelated() { return $this->related !== null; } /** * @param string $url * @return bool true === valid, false === invalid */ private function validateUrl($url) { $isValid = filter_var( $url, FILTER_VALIDATE_URL ); return false !== $isValid; } /** * Sets a logger instance on the object. * * @param LoggerInterface $logger * * @return void */ public function setLogger(LoggerInterface $logger) { $this->logger = $logger; } /** * @return LoggerInterface */ public function getLogger() { if (!$this->logger) { $this->setLogger(new Logger()); } return $this->logger; } }