Art4\JsonApiClient\Attributes::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('Attributes has to be an object, "' . gettype($object) . '" given.');
        }
        if (property_exists($object, 'type') or property_exists($object, 'id') or property_exists($object, 'relationships') or property_exists($object, 'links')) {
            throw new ValidationException('These properties are not allowed in attributes: `type`, `id`, `relationships`, `links`');
        }
        $object_vars = get_object_vars($object);
        if (count($object_vars) === 0) {
            return $this;
        }
        foreach ($object_vars as $name => $value) {
            $this->container->set($name, $value);
        }
        return $this;
    }