예제 #1
0
 /**
  * @internal
  * @param Scope $scope
  * @param       $data
  * @return array|bool
  * @throws \Exception
  */
 public function getEmbededModels(Scope $scope, $data)
 {
     $embeddedData = array();
     $embeddedDataCount = 0;
     $defaultEmbeds = array();
     if ($this->defaultEmbeds) {
         $scope->addDefaultEmbeds($this->defaultEmbeds);
         // clean multi level embeds to keep only the 1st child
         $defaultEmbeds = array_map(function ($embed) {
             $embedKeys = explode('.', $embed, 2);
             return $embedKeys[0];
         }, $this->defaultEmbeds);
     }
     $embeds = array_unique(array_merge($defaultEmbeds, $this->availableEmbeds));
     foreach ($embeds as $potentialEmbed) {
         // Check if an available embed is requested
         if (!$scope->isRequested($potentialEmbed)) {
             continue;
         }
         if (!($resource = $this->callGetMethod($potentialEmbed, $data, $embeddedData))) {
             continue;
         }
         $embeddedData[$potentialEmbed] = $scope->getComposedChildScope($potentialEmbed, $resource)->getComposite();
         ++$embeddedDataCount;
     }
     return $embeddedDataCount === 0 ? false : $embeddedData;
 }