Art4\JsonApiClient\Relationship::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('Relationship has to be an object, "' . gettype($object) . '" given.');
        }
        if (!property_exists($object, 'links') and !property_exists($object, 'data') and !property_exists($object, 'meta')) {
            throw new ValidationException('A Relationship object MUST contain at least one of the following properties: links, data, meta');
        }
        if (property_exists($object, 'data')) {
            $this->container->set('data', $this->parseData($object->data));
        }
        if (property_exists($object, 'meta')) {
            $meta = $this->manager->getFactory()->make('Meta', [$this->manager, $this]);
            $meta->parse($object->meta);
            $this->container->set('meta', $meta);
        }
        // Parse 'links' after 'data'
        if (property_exists($object, 'links')) {
            $link = $this->manager->getFactory()->make('RelationshipLink', [$this->manager, $this]);
            $link->parse($object->links);
            $this->container->set('links', $link);
        }
        return $this;
    }