- function __construct(Header $links) {
- if (strcasecmp($links->name, "Link")) {
- 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);
- if ($this->params->params) {
- foreach ($this->params->params as $link => $param) {
- $this->relations[$param["arguments"]["rel"]] = new Url($link);
+ function __construct(Header $links = null) {
+ if ($links) {
+ if (strcasecmp($links->name, "Link")) {
+ throw new UnexpectedValueException("Expected 'Link' header, got: '{$links->name}'");
+ }
+ $params = new Params($links->value, ",", ";", "=",
+ Params::PARSE_RFC5988 | Params::PARSE_ESCAPED);
+ if ($params->params) {
+ foreach ($params->params as $link => $param) {
+ $this->relations[$param["arguments"]["rel"]] = new Url($link);
+ }