Example #1
0
 /**
  * @return array
  */
 protected function analyzeCurrentData()
 {
     $relationship = $this->stack->end()->getRelationship();
     $data = $relationship->isShowData() === true ? $relationship->getData() : null;
     $isCollection = true;
     $isEmpty = true;
     $traversableData = null;
     $isOk = is_array($data) === true || is_object($data) === true || $data === null || $data instanceof Iterator;
     $isOk ?: Exceptions::throwInvalidArgument('data', $data);
     if (is_array($data) === true) {
         /** @var array $data */
         $isEmpty = empty($data);
         $traversableData = $data;
     } elseif ($data instanceof Iterator) {
         /** @var Iterator $data */
         $data->rewind();
         $isEmpty = $data->valid() === false;
         if ($isEmpty === false) {
             $traversableData = $data;
         } else {
             $traversableData = [];
         }
     } elseif (is_object($data) === true) {
         /** @var object $data */
         $isEmpty = $data === null;
         $isCollection = false;
         $traversableData = [$data];
     } elseif ($data === null) {
         $isCollection = false;
         $isEmpty = true;
     }
     return [$isEmpty, $isCollection, $traversableData];
 }
Example #2
0
 /**
  * @param array|object|null $data
  *
  * @return Iterator
  */
 private function parseData($data)
 {
     $curFrame = $this->stack->end();
     if (empty($data) === true) {
         (yield $this->createReplyForEmptyData($data));
     } else {
         if (is_array($data) === true) {
             $isOriginallyArrayed = true;
             $schema = $this->container->getSchema($data[0]);
         } else {
             $isOriginallyArrayed = false;
             $schema = $this->container->getSchema($data);
             $data = [$data];
         }
         // duplicated are allowed in data however they shouldn't be in includes
         $isDupAllowed = $curFrame->getLevel() < 2;
         $fieldSet = $this->getFieldSet($schema->getResourceType());
         foreach ($data as $resource) {
             $resourceObject = $schema->createResourceObject($resource, $isOriginallyArrayed, $fieldSet);
             $isCircular = $this->checkCircular($resourceObject);
             $this->stack->setCurrentResource($resourceObject);
             (yield $this->createReplyResourceStarted());
             if ($isCircular === true && $isDupAllowed === false || $this->shouldParseRelationships($resourceObject, $isCircular) === false) {
                 continue;
             }
             foreach ($schema->getRelationshipObjectIterator($resource) as $relationship) {
                 /** @var RelationshipObjectInterface $relationship */
                 $nextFrame = $this->stack->push();
                 $nextFrame->setRelationship($relationship);
                 try {
                     foreach ($this->parseData($relationship->getData()) as $parseResult) {
                         (yield $parseResult);
                     }
                 } finally {
                     $this->stack->pop();
                 }
             }
             (yield $this->createReplyResourceCompleted());
         }
     }
 }
Example #3
0
 /**
  * @return array
  */
 protected function analyzeCurrentData()
 {
     $relationship = $this->stack->end()->getRelationship();
     $data = $relationship->isShowData() === true ? $relationship->getData() : null;
     return $this->dataAnalyzer->analyze($data);
 }
Example #4
0
 /**
  * @return array|null|object
  */
 protected function getCurrentData()
 {
     $relationship = $this->stack->end()->getRelationship();
     $data = $relationship->isShowData() === true ? $relationship->getData() : null;
     return $data;
 }