Art4\JsonApiClient\ErrorLink::parse PHP Method

parse() public method

Parses the data for this element
public parse ( mixed $object ) : self
$object mixed The data
return self
    public function parse($object)
    {
        if (!is_object($object)) {
            throw new ValidationException('Link has to be an object, "' . gettype($object) . '" given.');
        }
        $links = get_object_vars($object);
        if (!array_key_exists('about', $links)) {
            throw new ValidationException('ErrorLink MUST contain these properties: about');
        }
        if (!is_string($links['about']) and !is_object($links['about'])) {
            throw new ValidationException('Link has to be an object or string, "' . gettype($links['about']) . '" given.');
        }
        if (is_string($links['about'])) {
            $this->container->set('about', strval($links['about']));
        } else {
            $link = $this->manager->getFactory()->make('Link', [$this->manager, $this]);
            $link->parse($links['about']);
            $this->container->set('about', $link);
        }
        unset($links['about']);
        // custom links
        foreach ($links as $name => $value) {
            $this->setLink($name, $value);
        }
    }