当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::setMetaValue方法代码示例

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


在下文中一共展示了Collection::setMetaValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: withPaginator

 /**
  * Respond with a paginator, and a transformer.
  *
  * @param LengthAwarePaginator $paginator
  * @param callable|\League\Fractal\TransformerAbstract $transformer
  * @param string $resourceKey
  * @param array $meta
  * @return ResponseFactory
  */
 public function withPaginator(LengthAwarePaginator $paginator, $transformer, $resourceKey = null, $meta = [])
 {
     $resource = new Collection($paginator->items(), $transformer, $resourceKey);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     foreach ($meta as $metaKey => $metaValue) {
         $resource->setMetaValue($metaKey, $metaValue);
     }
     $rootScope = $this->manager->createData($resource);
     return $this->withArray($rootScope->toArray());
 }
开发者ID:antho-firuze,项目名称:api-response,代码行数:19,代码来源:Response.php

示例2: testSerializingCollectionResourceWithMeta

 public function testSerializingCollectionResourceWithMeta()
 {
     $this->manager->parseIncludes('author');
     $booksData = array(array('title' => 'Foo', 'year' => '1991', '_author' => array('name' => 'Dave')), array('title' => 'Bar', 'year' => '1997', '_author' => array('name' => 'Bob')));
     $resource = new Collection($booksData, new GenericBookTransformer(), 'book');
     $resource->setMetaValue('foo', 'bar');
     $scope = new Scope($this->manager, $resource);
     $expected = array('book' => array(array('title' => 'Foo', 'year' => 1991), array('title' => 'Bar', 'year' => 1997)), 'linked' => array('author' => array(array('name' => 'Dave'), array('name' => 'Bob'))), 'meta' => array('foo' => 'bar'));
     $this->assertEquals($expected, $scope->toArray());
     $expectedJson = '{"book":[{"title":"Foo","year":1991},{"title":"Bar","year":1997}],"linked":{"author":[{"name":"Dave"},{"name":"Bob"}]},"meta":{"foo":"bar"}}';
     $this->assertEquals($expectedJson, $scope->toJson());
 }
开发者ID:iwillhappy1314,项目名称:laravel-admin,代码行数:12,代码来源:JsonApiSerializerTest.php

示例3: collection

 public function collection($rootname, $items, TransformerAbstract $transformer, $options = array())
 {
     $resources = new Collection($items, $transformer, $rootname);
     if (isset($options['meta'])) {
         foreach ($options['meta'] as $metaKey => $metaItem) {
             $resources->setMetaValue($metaKey, $metaItem);
         }
     }
     if (array_key_exists('cursor', $options)) {
         $resources->setCursor($options['cursor']);
     }
     if (array_key_exists('callback', $options)) {
         call_user_func($options['callback'], $resources);
     }
     if ($items instanceof IlluminatePaginator) {
         $paginatorInterface = array_key_exists('paginatorInterface', $options) ? $options['paginatorInterface'] : null;
         $this->paginateCollection($resources, $items, $paginatorInterface);
     }
     return isset($options['raw']) ? $resources : $this->buildResponse($resources);
 }
开发者ID:arthurnumen,项目名称:json-serializer-laravel,代码行数:20,代码来源:JsonSerializer.php

示例4: testSerializingCollectionResource

 public function testSerializingCollectionResource()
 {
     $manager = new Manager();
     $manager->parseIncludes('author');
     $manager->setSerializer(new DataArraySerializer());
     $booksData = array(array('title' => 'Foo', 'year' => '1991', '_author' => array('name' => 'Dave')), array('title' => 'Bar', 'year' => '1997', '_author' => array('name' => 'Bob')));
     // Try without metadata
     $resource = new Collection($booksData, new GenericBookTransformer(), 'book');
     $scope = new Scope($manager, $resource);
     $expected = array('data' => array(array('title' => 'Foo', 'year' => 1991, 'author' => array('data' => array('name' => 'Dave'))), array('title' => 'Bar', 'year' => 1997, 'author' => array('data' => array('name' => 'Bob')))));
     $this->assertEquals($expected, $scope->toArray());
     $expectedJson = '{"data":[{"title":"Foo","year":1991,"author":{"data":{"name":"Dave"}}},{"title":"Bar","year":1997,"author":{"data":{"name":"Bob"}}}]}';
     $this->assertEquals($expectedJson, $scope->toJson());
     // Same again with meta
     $resource = new Collection($booksData, new GenericBookTransformer(), 'book');
     $resource->setMetaValue('foo', 'bar');
     $scope = new Scope($manager, $resource);
     $expected = array('meta' => array('foo' => 'bar'), 'data' => array(array('title' => 'Foo', 'year' => 1991, 'author' => array('data' => array('name' => 'Dave'))), array('title' => 'Bar', 'year' => 1997, 'author' => array('data' => array('name' => 'Bob')))));
     $this->assertEquals($expected, $scope->toArray());
     $expectedJson = '{"data":[{"title":"Foo","year":1991,"author":{"data":{"name":"Dave"}}},{"title":"Bar","year":1997,"author":{"data":{"name":"Bob"}}}],"meta":{"foo":"bar"}}';
     $this->assertEquals($expectedJson, $scope->toJson());
 }
开发者ID:iwillhappy1314,项目名称:laravel-admin,代码行数:22,代码来源:DataArraySerializerTest.php

示例5: testSerializingCollectionResource

 public function testSerializingCollectionResource()
 {
     $manager = new Manager();
     $manager->parseIncludes('author');
     $manager->setSerializer(new ArraySerializer());
     $booksData = array(array('title' => 'Foo', 'year' => '1991', '_author' => array('name' => 'Dave')), array('title' => 'Bar', 'year' => '1997', '_author' => array('name' => 'Bob')));
     $resource = new Collection($booksData, new GenericBookTransformer(), 'book');
     // Try without metadata
     $scope = new Scope($manager, $resource);
     $expected = array(array('title' => 'Foo', 'year' => 1991, 'author' => array('name' => 'Dave')), array('title' => 'Bar', 'year' => 1997, 'author' => array('name' => 'Bob')));
     $this->assertEquals($expected, $scope->toArray());
     // JSON array of JSON objects
     $expectedJson = '[{"title":"Foo","year":1991,"author":{"name":"Dave"}},{"title":"Bar","year":1997,"author":{"name":"Bob"}}]';
     $this->assertEquals($expectedJson, $scope->toJson());
     // Same again with metadata
     $resource->setMetaValue('foo', 'bar');
     $scope = new Scope($manager, $resource);
     $expected = array(array('title' => 'Foo', 'year' => 1991, 'author' => array('name' => 'Dave')), array('title' => 'Bar', 'year' => 1997, 'author' => array('name' => 'Bob')), 'meta' => array('foo' => 'bar'));
     $this->assertEquals($expected, $scope->toArray());
     // This JSON sucks, because when you add a string key then it has to string up all the other keys. Using meta in Array is shit
     $expectedJson = '{"0":{"title":"Foo","year":1991,"author":{"name":"Dave"}},"1":{"title":"Bar","year":1997,"author":{"name":"Bob"}},"meta":{"foo":"bar"}}';
     $this->assertEquals($expectedJson, $scope->toJson());
 }
开发者ID:iwillhappy1314,项目名称:laravel-admin,代码行数:23,代码来源:ArraySerializerTest.php

示例6: withCollection

 /**
  * Response for collection of items
  *
  * @param $data
  * @param callable|\League\Fractal\TransformerAbstract $transformer
  * @param string $resourceKey
  * @param Cursor $cursor
  * @param array $meta
  * @return mixed
  */
 public function withCollection($data, $transformer, $resourceKey = null, Cursor $cursor = null, $meta = [])
 {
     $resource = new Collection($data, $transformer, $resourceKey);
     foreach ($meta as $metaKey => $metaValue) {
         $resource->setMetaValue($metaKey, $metaValue);
     }
     if (!is_null($cursor)) {
         $resource->setCursor($cursor);
     }
     $rootScope = $this->manager->createData($resource);
     return $this->withArray($rootScope->toArray());
 }
开发者ID:ryanmcoble,项目名称:remedy,代码行数:22,代码来源:AbstractResponse.php

示例7: prepareRootScope

 /**
  * Prepare root scope and set some meta information.
  *
  * @param Item|Collection $resource
  *
  * @return \League\Fractal\Scope
  */
 protected function prepareRootScope($resource)
 {
     $resource->setMetaValue('available_includes', $this->transformer->getAvailableIncludes());
     $resource->setMetaValue('default_includes', $this->transformer->getDefaultIncludes());
     return $this->fractal->createData($resource);
 }
开发者ID:pkfrom,项目名称:l5-api,代码行数:13,代码来源:BaseController.php


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