當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。