コード例 #1
0
ファイル: Manager.php プロジェクト: nodes-php/api
 /**
  * Main method to kick this all off.
  * Make a resource then pass it over, and use toArray().
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @param  \League\Fractal\Resource\ResourceInterface $resource
  * @param  string                                     $scopeIdentifier
  * @param  \League\Fractal\Scope                      $parentScopeInstance
  * @return \Nodes\Api\Transformer\Scope
  */
 public function createData(ResourceInterface $resource, $scopeIdentifier = null, FractalScope $parentScopeInstance = null)
 {
     $scopeInstance = new Scope($this, $resource, $scopeIdentifier);
     // Update scope history
     if ($parentScopeInstance !== null) {
         // This will be the new children list of parents (parents parents, plus the parent)
         $scopeArray = $parentScopeInstance->getParentScopes();
         $scopeArray[] = $parentScopeInstance->getScopeIdentifier();
         $scopeInstance->setParentScopes($scopeArray);
     }
     return $scopeInstance;
 }
コード例 #2
0
ファイル: TransformerAbstract.php プロジェクト: nodes-php/api
 /**
  * Call Include Method.
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @param  Scope  $scope
  * @param  string $includeName
  * @param  mixed  $data
  * @return \League\Fractal\Resource\ResourceInterface
  * @throws \Exception
  */
 protected function callIncludeMethod(Scope $scope, $includeName, $data)
 {
     $scopeIdentifier = $scope->getIdentifier($includeName);
     $params = $scope->getManager()->getIncludeParams($scopeIdentifier);
     // Check if the method name actually exists
     $methodName = 'include' . str_replace(' ', '', ucwords(str_replace('_', ' ', str_replace('-', ' ', $includeName))));
     $resource = call_user_func([$this, $methodName], $data, $params);
     if ($resource === null) {
         return false;
     }
     if (!$resource instanceof FractalResourceAbstract) {
         throw new \Exception(sprintf('Invalid return value from %s::%s(). Expected %s, received %s.', __CLASS__, $methodName, 'League\\Fractal\\Resource\\ResourceAbstract', gettype($resource)));
     }
     return $resource;
 }