• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Resource\Collection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中League\Fractal\Resource\Collection的典型用法代码示例。如果您正苦于以下问题:PHP Collection类的具体用法?PHP Collection怎么用?PHP Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Collection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: paginate

 /**
  * @return mixed
  */
 public function paginate()
 {
     $paginator = $this->repository->paginate();
     $bloco = $paginator->getCollection();
     $resource = new Collection($bloco, new CategoriaTecidoTransformer());
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $paginator;
 }
开发者ID:justem007,项目名称:rossina,代码行数:11,代码来源:CategoriaTecidoController.php


示例17: respondWithPaginator

 /**
  * @param Paginator $data
  * @param TransformerAbstract $transformer
  * @param array $headers
  * @return \Illuminate\Http\JsonResponse
  */
 public function respondWithPaginator(LengthAwarePaginator $data, TransformerAbstract $transformer, $headers = [])
 {
     $manager = new Manager();
     $manager->setSerializer(new ArraySerializer());
     $resource = new Collection($data->getCollection(), $transformer);
     $resource->setPaginator(new IlluminatePaginatorAdapter($data));
     $response = $manager->createData($resource)->toArray();
     return $this->respond(['post' => $this->_request->all(), 'data' => $response['data'], 'meta' => $response['meta'], 'error' => ['global' => '']], $headers);
 }
开发者ID:Buuntu,项目名称:Laravel-API,代码行数:15,代码来源:ApiController.php


示例18: createPaginated

 /**
  * create fractal's collection
  * 
  * @param Collection $collection
  * @param TransformerAbstract $transformer
  */
 public function createPaginated($paginator, $transformer, $include = [])
 {
     $fractal = app(League\Fractal\Manager::class);
     $fractal->parseIncludes($include);
     $collection = $paginator->getCollection();
     $resource = new Collection($collection, $transformer);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $fractal->createData($resource);
 }
开发者ID:rekale,项目名称:sikasir,代码行数:15,代码来源:TestCase.php


示例19: transformList

 /**
  * @param $key
  * @param array $resources
  * @param PaginatorInterface $paginator
  * @param null|string|array $includes
  * @return array
  */
 public function transformList($key, $resources, $includes = null, PaginatorInterface $paginator = null)
 {
     $transformer = $this->getTransformer($key);
     $resource = new Collection($resources, $transformer);
     if ($paginator !== null) {
         $resource->setPaginator($paginator);
     }
     return $this->convertResource($resource, $includes);
 }
开发者ID:bburnichon,项目名称:rest-bundle,代码行数:16,代码来源:ArrayTransformer.php


示例20: transformCollection

 /**
  * @param object[] $collection
  * @return \League\Fractal\Scope
  */
 public function transformCollection($collection)
 {
     $item = reset($collection);
     $resource = new Collection($collection, $this->getTransformer(get_class($item)), $this->getResourceName(get_class($item)));
     if (null !== $this->paginator) {
         $resource->setPaginator(new IlluminatePaginatorAdapter($this->paginator));
     }
     return $this->manager->createData($resource);
 }
开发者ID:HydrefLab,项目名称:laravel-adr,代码行数:13,代码来源:Transformer.php



注:本文中的League\Fractal\Resource\Collection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Provider\AbstractProvider类代码示例发布时间:2022-05-23
下一篇:
PHP Fractal\Manager类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap