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


PHP Resource\Collection類代碼示例

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


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

示例1: createPagedCollection

 protected function createPagedCollection(LengthAwarePaginator $paginator, TransformerAbstract $transformer)
 {
     $data = $paginator->getCollection();
     $collection = new Collection($data, $transformer);
     $collection->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $this->fractal->createData($collection)->toArray();
 }
開發者ID:Gamespectre,項目名稱:spectator-api,代碼行數:7,代碼來源:FractalDataTrait.php

示例2: paginatedCollection

 public function paginatedCollection(Paginator $paginator, $transformer = null, $resourceKey = null)
 {
     $paginator->appends(\Request::query());
     $resource = new Collection($paginator->getCollection(), $this->getTransformer($transformer), $resourceKey);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $this->manager->createData($resource)->toArray();
 }
開發者ID:huglester,項目名稱:larasponse,代碼行數:7,代碼來源:Fractal.php

示例3: index

 public function index()
 {
     $forms = Form::paginate();
     $resource = new Collection($forms->getCollection(), new FormTransformer(), 'forms');
     $resource->setPaginator(new IlluminatePaginatorAdapter($forms));
     return $this->fractal()->createData($resource)->toJson();
 }
開發者ID:cincyultimate,項目名稱:cupa-api-poc,代碼行數:7,代碼來源:FormController.php

示例4: createResponseArray

 public function createResponseArray($data, $entity, Request $request)
 {
     $this->request = $request;
     $fractal = new Manager();
     $fractal->parseIncludes($request->query->get('include', []));
     $fractal->setSerializer(new ArraySerializer());
     $transformer = $this->transformerFactory->get($entity);
     if ($data instanceof Pagerfanta) {
         $pager = $data;
         $pager->setMaxPerPage($request->query->get('limit', 10));
         $pager->setCurrentPage($request->query->get('page', 1));
         $results = $pager->getCurrentPageResults();
         $resource = new Collection($results, $transformer);
         $resource->setPaginator(new PagerfantaPaginatorAdapter($pager, [$this, 'paginationRouter']));
     } elseif ($data instanceof DoctrineQuery) {
         $ormAdapter = new DoctrineORMAdapter($data);
         $pager = new Pagerfanta($ormAdapter);
         $pager->setMaxPerPage($request->query->get('limit', 10));
         $pager->setCurrentPage($request->query->get('page', 1));
         $results = $pager->getCurrentPageResults();
         $resource = new Collection($results, $transformer);
         $resource->setPaginator(new PagerfantaPaginatorAdapter($pager, [$this, 'paginationRouter']));
     } elseif (is_array($data)) {
         $resource = new Collection($data, $transformer);
     } else {
         $resource = new Item($data, $transformer);
     }
     $data = $fractal->createData($resource)->toArray();
     return $data;
 }
開發者ID:cvele,項目名稱:fondacija,代碼行數:30,代碼來源:RestResponse.php

示例5: cursorCollection

 /**
  * @param $data
  * @param \League\Fractal\TransformerAbstract $transformer
  * @param \League\Fractal\Pagination\Cursor|int $cursor
  * @param string $resourceKey
  * @return \League\Fractal\Scope
  */
 public function cursorCollection($data, $transformer = null, $cursor = null, $resourceKey = null)
 {
     $transformer = $this->getTransformer($transformer);
     $resource = new Collection($data, $transformer, $resourceKey);
     $resource->setCursor($this->makeCursor($cursor, $data));
     return $this->manager->createData($resource);
 }
開發者ID:creativify,項目名稱:kraken,代碼行數:14,代碼來源:FractalTransformerManager.php

示例6: paginateCollection

 private function paginateCollection(Collection $collection, IlluminatePaginator $paginator, PaginatorInterface $adapter = null)
 {
     if (is_null($adapter)) {
         $adapter = new IlluminatePaginatorAdapter($paginator);
     }
     $collection->setPaginator($adapter);
 }
開發者ID:arthurnumen,項目名稱:json-serializer-laravel,代碼行數:7,代碼來源:JsonSerializer.php

示例7: respondWithCursor

 /**
  *
  * Returns a JSON Array along with a cursor for pagination.
  *
  * @param $collection
  * @param $callback
  * @param CursorInterface $cursor
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function respondWithCursor($collection, $callback, CursorInterface $cursor)
 {
     $resource = new Collection($collection, $callback);
     $resource->setCursor($cursor);
     $rootScope = $this->fractal->createData($resource);
     return $this->respondWithArray($rootScope->toArray());
 }
開發者ID:jasonb8293,項目名稱:fox-api,代碼行數:16,代碼來源:ApiController.php

示例8: index

 public function index()
 {
     $clinics = Clinic::paginate();
     $resource = new Collection($clinics->getCollection(), new ClinicTransformer(), 'clinics');
     $resource->setPaginator(new IlluminatePaginatorAdapter($clinics));
     return $this->fractal()->createData($resource)->toJson();
 }
開發者ID:cincyultimate,項目名稱:cupa-api-poc,代碼行數:7,代碼來源:ClinicController.php

示例9: index

 public function index()
 {
     $users = User::paginate();
     $resource = new Collection($users->getCollection(), new UserTransformer(), 'users');
     $resource->setPaginator(new IlluminatePaginatorAdapter($users));
     return $this->fractal()->createData($resource)->toJson();
 }
開發者ID:cincyultimate,項目名稱:cupa-api-poc,代碼行數:7,代碼來源:UserController.php

示例10: respondWithPaginatedCollection

 public function respondWithPaginatedCollection(AbstractPaginator $paginator, $callback)
 {
     $resource = new Collection($paginator->getCollection(), $callback);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     $rootScope = $this->fractal->createData($resource);
     return $rootScope;
 }
開發者ID:gitter-badger,項目名稱:FCE,代碼行數:7,代碼來源:Fractal.php

示例11: actionGetElements

 /**
  * Returns the requested elements as JSON
  *
  * @param callable|null $configFactory A function for generating the config
  * @param array|null    $config        The API endpoint configuration
  *
  * @throws Exception
  * @throws HttpException
  */
 public function actionGetElements($configFactory = null, array $config = null)
 {
     if ($configFactory !== null) {
         $params = craft()->urlManager->getRouteParams();
         $variables = isset($params['variables']) ? $params['variables'] : null;
         $config = $this->_callWithParams($configFactory, $variables);
     }
     // Merge in default config options
     $config = array_merge(['paginate' => true, 'pageParam' => 'page', 'elementsPerPage' => 100, 'first' => false, 'transformer' => 'Craft\\ElementApi_ElementTransformer'], craft()->config->get('defaults', 'elementapi'), $config);
     if ($config['pageParam'] == 'p') {
         throw new Exception('The pageParam setting cannot be set to "p" because that’s the parameter Craft uses to check the requested path.');
     }
     if (!isset($config['elementType'])) {
         throw new Exception('Element API configs must specify the elementType.');
     }
     /** @var ElementCriteriaModel $criteria */
     $criteria = craft()->elements->getCriteria($config['elementType'], ['limit' => null]);
     if (!empty($config['criteria'])) {
         $criteria->setAttributes($config['criteria']);
     }
     // Load Fractal
     $pluginPath = craft()->path->getPluginsPath() . 'elementapi/';
     require $pluginPath . 'vendor/autoload.php';
     $fractal = new Manager();
     $fractal->setSerializer(new ArraySerializer());
     // Define the transformer
     if (is_callable($config['transformer']) || $config['transformer'] instanceof TransformerAbstract) {
         $transformer = $config['transformer'];
     } else {
         Craft::import('plugins.elementapi.ElementApi_ElementTransformer');
         $transformer = Craft::createComponent($config['transformer']);
     }
     if ($config['first']) {
         $element = $criteria->first();
         if (!$element) {
             throw new HttpException(404);
         }
         $resource = new Item($element, $transformer);
     } else {
         if ($config['paginate']) {
             // Create the paginator
             require $pluginPath . 'ElementApi_PaginatorAdapter.php';
             $paginator = new ElementApi_PaginatorAdapter($config['elementsPerPage'], $criteria->total(), $config['pageParam']);
             // Fetch this page's elements
             $criteria->offset = $config['elementsPerPage'] * ($paginator->getCurrentPage() - 1);
             $criteria->limit = $config['elementsPerPage'];
             $elements = $criteria->find();
             $paginator->setCount(count($elements));
             $resource = new Collection($elements, $transformer);
             $resource->setPaginator($paginator);
         } else {
             $resource = new Collection($criteria, $transformer);
         }
     }
     JsonHelper::sendJsonHeaders();
     echo $fractal->createData($resource)->toJson();
     // End the request
     craft()->end();
 }
開發者ID:jonleesmith,項目名稱:jonleesmith,代碼行數:68,代碼來源:ElementApiController.php

示例12: index

 public function index(Manager $fractal, TransactionTransformer $transactionTransformer)
 {
     $transactions = Transaction::orderBy('time', 'desc')->paginate(10);
     $collection = new Collection($transactions, $transactionTransformer);
     $collection->setPaginator(new IlluminatePaginatorAdapter($transactions));
     $data = $fractal->createData($collection)->toArray();
     return $this->respond($data);
 }
開發者ID:ashbreeze,項目名稱:OmniChain-API,代碼行數:8,代碼來源:TransactionController.php

示例13: testGetTransformer

 public function testGetTransformer()
 {
     $resource = new Collection($this->simpleCollection, function () {
     });
     $this->assertTrue(is_callable($resource->getTransformer()));
     $resource = new Collection($this->simpleCollection, 'SomeClass');
     $this->assertEquals($resource->getTransformer(), 'SomeClass');
 }
開發者ID:iwillhappy1314,項目名稱:laravel-admin,代碼行數:8,代碼來源:CollectionTest.php

示例14: respondWithPaginate

 protected function respondWithPaginate($paginator, $callback)
 {
     $collection = $paginator->getCollection();
     $resource = new Collection($collection, $callback);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     $rootScope = $this->fractal->createData($resource);
     return $this->respondWithArray($rootScope->toArray());
 }
開發者ID:udinkecil,項目名稱:tracerstudy,代碼行數:8,代碼來源:ApiController.php

示例15: transform

 /**
  * Manage and finalize the data transformation.
  *
  * @param  \League\Fractal\Resource\Item|\League\Fractal\Resource\Collection  $data
  * @param  int  $code
  * @param  array  $meta
  * @return \Illuminate\Http\JsonResponse
  */
 public function transform($data, $code = 200, $meta = [])
 {
     $data->setMeta($meta);
     $manager = new Manager();
     $manager->setSerializer(new DataArraySerializer());
     $response = $manager->createData($data)->toArray();
     return response()->json($response, 200, [], JSON_UNESCAPED_SLASHES);
 }
開發者ID:DoSomething,項目名稱:gladiator,代碼行數:16,代碼來源:ApiController.php


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