/** * @inheritdoc */ public function addToData(ResourceObjectInterface $resource) { // check if 'not-arrayed' data were added you cannot add to 'non-array' data section anymore assert('$this->isDataArrayed === null || $this->isDataArrayed === true'); $this->isDataArrayed !== null ?: ($this->isDataArrayed = $resource->isInArray()); // check all resources have the same isInArray flag assert('$this->isDataArrayed === $resource->isInArray()'); $idx = $resource->getId(); $type = $resource->getType(); assert('isset($this->bufferForData[$type][$idx]) === false'); $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]); } }
/** * @inheritdoc */ public function addToData(ResourceObjectInterface $resource) { // check if 'not-arrayed' data were added you cannot add to 'non-array' data section anymore assert('$this->isDataArrayed === null || $this->isDataArrayed === true'); $this->isDataArrayed !== null ?: ($this->isDataArrayed = $resource->isInArray()); // check all resources have the same isInArray flag assert('$this->isDataArrayed === $resource->isInArray()'); $idx = $resource->getId(); $type = $resource->getType(); assert('isset($this->bufferForData[$type][$idx]) === false'); $this->bufferForData[$type][$idx] = $this->presenter->convertDataResourceToArray($resource, true); }