namespace seekat\API;
-use http\Header;
-use http\Params;
-use http\QueryString;
-use http\Url;
+use http\ {
+ Header,
+ Params,
+ QueryString,
+ Url
+};
+use Serializable;
+use UnexpectedValueException;
-class Links implements \Serializable
+class Links implements Serializable
{
/**
* Parsed "Link" relations
- * @var \http\Params
+ * @var Params
*/
private $params;
-
+
/**
* Parsed "Link" relations
* @var array
/**
* Parse the hypermedia link header
*
- * @var string $header_value The value of the "Link" header
+ * @param Header $links The Link header
+ * @throws UnexpectedValueException
*/
function __construct(Header $links) {
if (strcasecmp($links->name, "Link")) {
- throw new \UnexpectedValueException("Expected 'Link' header, got: '{$links->name}'");
+ throw new UnexpectedValueException("Expected 'Link' header, got: '{$links->name}'");
}
$this->unserialize($links->value);
}
+ /**
+ * @return string
+ */
function __toString() : string {
return $this->serialize();
}
+ /**
+ * @return string
+ */
function serialize() {
return (string) $this->params;
}
+ /**
+ * @param string $links
+ */
function unserialize($links) {
$this->params = new Params($links, ",", ";", "=",
Params::PARSE_RFC5988 | Params::PARSE_ESCAPED);
*
* Returns the link's "last" relation if it exists and "next" is not set.
*
- * @return \http\Url
+ * @return Url
*/
function getNext() {
if (isset($this->relations["next"])) {
*
* Returns the link's "first" relation if it exists and "prev" is not set.
*
- * @return \http\Url
+ * @return Url
*/
function getPrev() {
if (isset($this->relations["prev"])) {
/**
* Get the URL of the link's "last" relation
*
- * @return \http\Url
+ * @return Url
*/
function getLast() {
if (isset($this->relations["last"])) {
/**
* Get the URL of the link's "first" relation
*
- * @return \http\Url
+ * @return Url
*/
function getFirst() {
if (isset($this->relations["first"])) {