コード例 #1
0
ファイル: Fractal.php プロジェクト: theHarvester/api
 /**
  * Transform a response with a transformer.
  *
  * @param mixed                          $response
  * @param object                         $transformer
  * @param \Dingo\Api\Transformer\Binding $binding
  * @param \Dingo\Api\Http\Request        $request
  *
  * @return array
  */
 public function transform($response, $transformer, Binding $binding, Request $request)
 {
     $this->parseFractalIncludes($request);
     $resource = $this->createResource($response, $transformer, $binding->getParameters());
     // If the response is a paginator then we'll create a new paginator
     // adapter for Laravel and set the paginator instance on our
     // collection resource.
     if ($response instanceof IlluminatePaginator) {
         $paginator = $this->createPaginatorAdapter($response);
         $resource->setPaginator($paginator);
     }
     if ($this->shouldEagerLoad($response)) {
         $eagerLoads = $this->mergeEagerLoads($transformer, $this->fractal->getRequestedIncludes());
         $response->load($eagerLoads);
     }
     foreach ($binding->getMeta() as $key => $value) {
         $resource->setMetaValue($key, $value);
     }
     $binding->fireCallback($resource, $this->fractal);
     $scopeIdentifier = null;
     if (array_key_exists('scopeIdentifier', $binding->getParameters())) {
         $scopeIdentifier = $binding->getParameters()['scopeIdentifier'];
     }
     return $this->fractal->createData($resource, $scopeIdentifier)->toArray();
 }
コード例 #2
0
 public function transform($response, $transformer, Binding $binding, Request $request)
 {
     // 过滤掉未允许的 include 项
     $include_manager = app(IncludeManager::class);
     $this->fractal->parseIncludes($include_manager->figureOutWhichIncludes());
     $resource = $this->createResource($response, $transformer, $binding->getParameters());
     // If the response is a paginator then we'll create a new paginator
     // adapter for Laravel and set the paginator instance on our
     // collection resource.
     if ($response instanceof IlluminatePaginator) {
         $paginator = $this->createPaginatorAdapter($response);
         $resource->setPaginator($paginator);
     }
     foreach ($binding->getMeta() as $key => $value) {
         $resource->setMetaValue($key, $value);
     }
     $binding->fireCallback($resource, $this->fractal);
     return $this->fractal->createData($resource)->toArray();
 }
コード例 #3
0
ファイル: ResponseBuilder.php プロジェクト: jacobDaeHyung/api
 /**
  * Set the meta data for the response.
  *
  * @param array $meta
  *
  * @return \Dingo\Api\Http\ResponseBuilder
  */
 public function setMeta(array $meta)
 {
     $this->binding->setMeta($meta);
     return $this;
 }
コード例 #4
-1
ファイル: Response.php プロジェクト: JamesGuthrie/api
 /**
  * Get the meta data for the response.
  *
  * @return array
  */
 public function getMeta()
 {
     return $this->binding->getMeta();
 }