Tobscure\JsonApi\ElementInterface::getResources PHP Method

getResources() public method

Get the resources array.
public getResources ( ) : array
return array
    public function getResources();

Usage Example

示例#1
0
 /**
  * Get included resources.
  *
  * @param ElementInterface $element
  * @param bool $includeParent
  * @return Resource[]
  */
 protected function getIncluded(ElementInterface $element, $includeParent = false)
 {
     $included = [];
     foreach ($element->getResources() as $resource) {
         if ($resource->isIdentifier()) {
             continue;
         }
         if ($includeParent) {
             $included = $this->mergeResource($included, $resource);
         } else {
             $type = $resource->getType();
             $id = $resource->getId();
         }
         foreach ($resource->getUnfilteredRelationships() as $relationship) {
             $includedElement = $relationship->getData();
             if (!$includedElement instanceof ElementInterface) {
                 continue;
             }
             foreach ($this->getIncluded($includedElement, true) as $child) {
                 // If this resource is the same as the top-level "data"
                 // resource, then we don't want it to show up again in the
                 // "included" array.
                 if (!$includeParent && $child->getType() === $type && $child->getId() === $id) {
                     continue;
                 }
                 $included = $this->mergeResource($included, $child);
             }
         }
     }
     $flattened = [];
     array_walk_recursive($included, function ($a) use(&$flattened) {
         $flattened[] = $a;
     });
     return $flattened;
 }
All Usage Examples Of Tobscure\JsonApi\ElementInterface::getResources