Art4\JsonApiClient\ResourceCollection::parseResource PHP Method

parseResource() protected method

Generate a new resource from an object
protected parseResource ( object $data ) : Art4\JsonApiClient\ElementInterface
$data object The resource data
return Art4\JsonApiClient\ElementInterface The resource
    protected function parseResource($data)
    {
        if (!is_object($data)) {
            throw new ValidationException('Resources inside a collection MUST be objects, "' . gettype($data) . '" given.');
        }
        $object_vars = get_object_vars($data);
        // the 2 properties must be type and id
        // or the 3 properties must be type, id and meta
        if (count($object_vars) === 2 or count($object_vars) === 3 and property_exists($data, 'meta')) {
            $resource = $this->manager->getFactory()->make('ResourceIdentifier', [$this->manager, $this]);
            $resource->parse($data);
        } else {
            $resource = $this->manager->getFactory()->make('ResourceItem', [$this->manager, $this]);
            $resource->parse($data);
        }
        return $resource;
    }