Neomerx\JsonApi\Document\Document::addToData PHP Method

addToData() public method

public addToData ( Neomerx\JsonApi\Contracts\Schema\ResourceObjectInterface $resource )
$resource Neomerx\JsonApi\Contracts\Schema\ResourceObjectInterface
    public function addToData(ResourceObjectInterface $resource)
    {
        // check if 'not-arrayed' data were added you cannot add to 'non-array' data section anymore
        $this->isDataArrayed === true || $this->isDataArrayed === null ?: Exceptions::throwLogicException();
        $this->isDataArrayed !== null ?: ($this->isDataArrayed = $resource->isInArray());
        // check all resources have the same isInArray flag
        $this->isDataArrayed === $resource->isInArray() ?: Exceptions::throwLogicException();
        $idx = $resource->getId();
        $type = $resource->getType();
        isset($this->bufferForData[$type][$idx]) === false ?: Exceptions::throwLogicException();
        $this->bufferForData[$type][$idx] = $this->presenter->convertDataResourceToArray($resource, true);
        $this->hasBeenMetAlready[$type][$idx] = true;
        // check if resource has already been added to included
        // (for example as related resource of one of the previous main resources)
        if (isset($this->includedResources[$type][$idx]) === true) {
            $includedIndex = $this->includedResources[$type][$idx];
            // remove duplicate from 'included' (leave only in main resources)
            unset($this->included[$includedIndex]);
        }
    }