/** * Fire the included transformers. * * @internal * * @param \League\Fractal\TransformerAbstract $transformer * @param mixed $data * * @return array */ protected function fireIncludedTransformers($transformer, $data) { $this->availableIncludes = $transformer->getAvailableIncludes(); return $transformer->processIncludedResources($this, $data) ?: []; }
/** * Fire the included transformers. * * @internal * * @param \League\Fractal\TransformerAbstract $transformer * @param mixed $data * * @return array */ protected function fireIncludedTransformers($transformer, $data) { return $transformer->processIncludedResources($this, $data) ?: []; }
/** * This method is fired to loop through available includes, see if any of * them are requested and permitted for this scope. * * @internal * * @param Scope $scope * @param mixed $data * * @return array */ public function processIncludedResources(Scope $scope, $data) { $includedData = parent::processIncludedResources($scope, $data); if (is_array($includedData)) { foreach ($includedData as $include => $data) { if (false !== strpos($include, 'childrens')) { $key = str_replace($this->currentResourceKey, '', $include); $includedData[$key] = $includedData[$include]; unset($includedData[$include]); } } } return $includedData; }
/** * Quick hack until Fractal support embeded data without the use of * the data-key * * @see https://github.com/thephpleague/fractal/issues/37 * * {@inheritDoc} */ public function processIncludedResources(Scope $scope, $data) { $embeded = parent::processIncludedResources($scope, $data); if (!is_null($embeded) && !is_bool($embeded)) { $embeded = array_map(function ($d) { return current($d); }, $embeded); } return $embeded; }