public function parse($object)
{
if (!is_object($object)) {
throw new ValidationException('Resource has to be an object, "' . gettype($object) . '" given.');
}
if (!property_exists($object, 'type')) {
throw new ValidationException('A resource object MUST contain a type');
}
if (!property_exists($object, 'id')) {
throw new ValidationException('A resource object MUST contain an id');
}
if (is_object($object->type) or is_array($object->type)) {
throw new ValidationException('Resource type cannot be an array or object');
}
if (is_object($object->id) or is_array($object->id)) {
throw new ValidationException('Resource id cannot be an array or object');
}
$this->container->set('type', strval($object->type));
$this->container->set('id', strval($object->id));
if (property_exists($object, 'meta')) {
$meta = $this->manager->getFactory()->make('Meta', [$this->manager, $this]);
$meta->parse($object->meta);
$this->container->set('meta', $meta);
}
if (property_exists($object, 'attributes')) {
$attributes = $this->manager->getFactory()->make('Attributes', [$this->manager]);
$attributes->parse($object->attributes);
$this->container->set('attributes', $attributes);
}
if (property_exists($object, 'relationships')) {
$relationships = $this->manager->getFactory()->make('RelationshipCollection', [$this->manager, $this]);
$relationships->parse($object->relationships);
$this->container->set('relationships', $relationships);
}
if (property_exists($object, 'links')) {
$link = $this->manager->getFactory()->make('ResourceItemLink', [$this->manager, $this]);
$link->parse($object->links);
$this->container->set('links', $link);
}
return $this;
}