當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Fractal\Manager類代碼示例

本文整理匯總了PHP中League\Fractal\Manager的典型用法代碼示例。如果您正苦於以下問題:PHP Manager類的具體用法?PHP Manager怎麽用?PHP Manager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Manager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: show

 /**
  * @param $projectId
  * @param Manager $fractal
  * @param ProjectTransformer $projectTransformer
  * @return \Illuminate\Http\JsonResponse
  */
 public function show($projectId, Manager $fractal, ProjectTransformer $projectTransformer)
 {
     $project = $this->project->findOrFail($projectId);
     $item = new Item($project, $projectTransformer);
     $data = $fractal->createData($item)->toArray();
     return $this->respond($data);
 }
開發者ID:RonaldoSantana,項目名稱:treeline-lumen,代碼行數:13,代碼來源:ProjectsController.php

示例2: transform

/**
 * @VP:
 * I'm trying to pass a second parameter to my transformer but don't know how.
 * @param $resource
 */
function transform($resource)
{
    $manager = new Manager();
    $manager->setSerializer(new DataArraySerializer());
    $manager->parseIncludes(request()->get('includes', []));
    return $manager->createData($resource)->toArray();
}
開發者ID:JennySwift,項目名稱:health-tracker,代碼行數:12,代碼來源:helpers.php

示例3: register

 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     if ($this->isLumen()) {
         require_once 'fallback.php';
     }
     $this->registerRequiredProviders();
     $this->app->bind('datatables.html', function () {
         return $this->app->make(Html\Builder::class);
     });
     $this->app->singleton('datatables.fractal', function () {
         $fractal = new Manager();
         $config = $this->app['config'];
         $request = $this->app['request'];
         $includesKey = $config->get('datatables.fractal.includes', 'include');
         if ($request->get($includesKey)) {
             $fractal->parseIncludes($request->get($includesKey));
         }
         $serializer = $config->get('datatables.fractal.serializer', DataArraySerializer::class);
         $fractal->setSerializer(new $serializer());
         return $fractal;
     });
     $this->app->singleton('datatables', function () {
         return new Datatables($this->app->make(Request::class));
     });
     $this->registerAliases();
 }
開發者ID:yajra,項目名稱:laravel-datatables-oracle,代碼行數:31,代碼來源:DatatablesServiceProvider.php

示例4: includeContent

 /**
  * Include Content
  *
  * @param BaseElementModel $element Element
  *
  * @return League\Fractal\Resource\Item Content
  */
 public function includeContent(BaseElementModel $element)
 {
     $content = [];
     if ($this->depth > \Craft\craft()->config->get('contentRecursionLimit', 'httpMessagesRestMiddleware') - 1) {
         return;
     }
     foreach ($element->getFieldLayout()->getFields() as $fieldLayoutField) {
         $field = $fieldLayoutField->getField();
         $value = $element->getFieldValue($field->handle);
         if (get_class($field->getFieldType()) === 'Craft\\RichTextFieldType') {
             $value = $value->getRawContent();
         }
         if (is_object($value) && get_class($value) === 'Craft\\ElementCriteriaModel') {
             $class = get_class($value->getElementType());
             $element_type = $this->element_service->getElementTypeByClass($class);
             $manager = new Manager();
             $manager->parseIncludes(array_merge(['content'], explode(',', \Craft\craft()->request->getParam('include'))));
             $manager->setSerializer(new ArraySerializer());
             $transformer = $this->config_service->getTransformer($element_type);
             $value = $value->find();
             $body = new Collection($value, new $transformer($this->depth + 1));
             $value = $manager->createData($body)->toArray();
             $value = !empty($value['data']) ? $value['data'] : null;
         }
         $content[$field->handle] = $value;
     }
     if ($content) {
         return $this->item($content, new ContentTransformer($this->depth), 'content');
     }
 }
開發者ID:airtype,項目名稱:craft-httpmessagesfractalmiddleware,代碼行數:37,代碼來源:BaseTransformer.php

示例5: byLoan

 public function byLoan($id, Manager $fractal, LoancropTransformer $loancropTransformer)
 {
     $loancrops = Loancrop::where('loan_id', $id)->get();
     $collection = new Collection($loancrops, $loancropTransformer);
     $data = $fractal->createData($collection)->toArray();
     return $this->respond($data);
 }
開發者ID:wyrover,項目名稱:lenda-api,代碼行數:7,代碼來源:LoancropsController.php

示例6: response

 public function response($data, $totalCount = false, $query = false, $statusCode = 200)
 {
     if ($this->transformer) {
         $fractal = new Manager();
         if ($totalCount === false) {
             $resource = new Item($data, $this->transformer);
         } else {
             $resource = new Collection($data, $this->transformer);
         }
         $response = $fractal->createData($resource)->toArray();
     } else {
         $response = ['data' => $data];
     }
     if ($totalCount !== false) {
         $response['totalCount'] = (int) $totalCount;
     }
     if ($query !== false) {
         $response['search'] = $query;
     }
     $response = json_encode($response, JSON_UNESCAPED_UNICODE);
     if ($response === false) {
         InternalServerError500::throwException("Response couldn't encoded as JSON");
     }
     $this->app->response->status($statusCode);
     $this->app->response->body($response);
 }
開發者ID:kommuna,項目名稱:restmodel,代碼行數:26,代碼來源:APIController.php

示例7: __construct

 public function __construct(Manager $fractal)
 {
     $this->fractal = $fractal;
     if (Input::get('include')) {
         $fractal->parseIncludes(Input::get('include'));
     }
 }
開發者ID:ruigomeseu,項目名稱:sightseeing-web,代碼行數:7,代碼來源:ApiController.php

示例8: index

 public function index(Request $request, Manager $fractal)
 {
     if ($requestedEmbeds = $request->get('include')) {
         $fractal->parseIncludes($requestedEmbeds);
     }
     return $this->response->item($this->user, UserTransformer::class);
 }
開發者ID:tdtrung17693,項目名稱:Rabbitnote,代碼行數:7,代碼來源:UsersController.php

示例9: index

 public function index(Manager $fractal, SupportTransformer $transformer, $customerID)
 {
     $ac = ArticleCategory::where('id', '>=', 64)->take(10)->get();
     $resource = new Collection($ac, $transformer);
     $data = $fractal->createData($resource)->toArray();
     return $this->respondWithSuccess($data);
 }
開發者ID:smileofninja,項目名稱:lumenWebService,代碼行數:7,代碼來源:SupportController.php

示例10: listing

 public static function listing()
 {
     $fractal = new Manager();
     $data = new Collection(parent::all(), new GenreTransformer());
     $list = $fractal->createData($data)->toArray()['data'];
     return $list;
 }
開發者ID:nanaya,項目名稱:osu-web,代碼行數:7,代碼來源:Genre.php

示例11: responseWithTransformer

 /**
  * @param $resource
  * @return mixed
  */
 public function responseWithTransformer($resource, $code)
 {
     $manager = new Manager();
     $manager->setSerializer(new DataArraySerializer());
     $manager->parseIncludes(request()->get('includes', []));
     return response()->json($manager->createData($resource)->toArray(), $code);
 }
開發者ID:JennySwift,項目名稱:dental,代碼行數:11,代碼來源:Controller.php

示例12: serialize

 /**
  *  Serializes the original content
  *
  *  @param Fractal\ResourceAbstract $resource
  *  @return $this
  */
 protected function serialize($resource)
 {
     $manager = new Fractal\Manager();
     $data = $manager->createData($resource)->toArray()['data'];
     $serialized = json_encode($data);
     return parent::setContent($serialized);
 }
開發者ID:jotaen,項目名稱:fractal-response,代碼行數:13,代碼來源:FractalResponse.php

示例13: respondWithCollection

 public function respondWithCollection($collection, $callback)
 {
     $fractal = new Manager();
     $resource = new Collection($collection, $callback);
     $rootScope = $fractal->createData($resource);
     return $rootScope->toArray()['data'];
 }
開發者ID:grepollo,項目名稱:dkb_5sp,代碼行數:7,代碼來源:CbModel.php

示例14: __construct

 /**
  * @param Manager $fractal
  */
 public function __construct(Manager $fractal)
 {
     $this->fractal = $fractal;
     if (isset($_GET['include'])) {
         $fractal->parseIncludes($_GET['include']);
     }
 }
開發者ID:jamieshiers,項目名稱:calendar,代碼行數:10,代碼來源:ApiController.php

示例15: lessons

 /**
  * Returns only the lessons from the
  * current feed from Laracasts in JSON.
  */
 public function lessons()
 {
     $lessons = $this->lissandra->getLessons();
     $resource = new Collection($lessons, new LessonTransformer($lessons));
     $data = $this->fractal->createData($resource)->toArray()['data'];
     return $this->respondWithCORS($data);
 }
開發者ID:laravelista,項目名稱:lissandra,代碼行數:11,代碼來源:FeedController.php


注:本文中的League\Fractal\Manager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。