Art4\JsonApiClient\DocumentLink::parse PHP Метод

parse() публичный Метод

Parses the data for this element
public parse ( mixed $object ) : self
$object mixed The data
Результат self
    public function parse($object)
    {
        if (!is_object($object)) {
            throw new ValidationException('DocumentLink has to be an object, "' . gettype($object) . '" given.');
        }
        $links = get_object_vars($object);
        if (array_key_exists('self', $links)) {
            if (!is_string($links['self']) and !is_object($links['self'])) {
                throw new ValidationException('property "self" has to be a string or object, "' . gettype($links['self']) . '" given.');
            }
            $this->setLink('self', $links['self']);
            unset($links['self']);
        }
        if (array_key_exists('related', $links)) {
            if (!is_string($links['related']) and !is_object($links['related'])) {
                throw new ValidationException('property "related" has to be a string or object, "' . gettype($links['related']) . '" given.');
            }
            $this->setLink('related', $links['related']);
            unset($links['related']);
        }
        // Pagination links, if data in parent attributes exists
        if ($this->parent->has('data')) {
            if (array_key_exists('first', $links)) {
                $this->setPaginationLink('first', $links['first']);
                unset($links['first']);
            }
            if (array_key_exists('last', $links)) {
                $this->setPaginationLink('last', $links['last']);
                unset($links['last']);
            }
            if (array_key_exists('prev', $links)) {
                $this->setPaginationLink('prev', $links['prev']);
                unset($links['prev']);
            }
            if (array_key_exists('next', $links)) {
                $this->setPaginationLink('next', $links['next']);
                unset($links['next']);
            }
        }
        // custom links
        foreach ($links as $name => $value) {
            $this->setLink($name, $value);
        }
    }