Art4\JsonApiClient\ResourceItemLink::set PHP Method

set() protected method

Set a link
protected set ( string $name, string | object $link ) : self
$name string The Name
$link string | object The Link
return self
    protected function set($name, $link)
    {
        // from spec: aA link MUST be represented as either:
        // - a string containing the link's URL.
        // - an object ("link object") which can contain the following members:
        if (!is_object($link) and !is_string($link)) {
            throw new ValidationException('Link attribute has to be an object or string, "' . gettype($link) . '" given.');
        }
        if (is_string($link)) {
            $this->container->set($name, strval($link));
            return $this;
        }
        // Now $link can only be an object
        $link_object = $this->manager->getFactory()->make('Link', [$this->manager, $this]);
        $link_object->parse($link);
        $this->container->set($name, $link_object);
        return $this;
    }