本文整理汇总了PHP中League\Fractal\Resource\Collection::setCursor方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::setCursor方法的具体用法?PHP Collection::setCursor怎么用?PHP Collection::setCursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Fractal\Resource\Collection
的用法示例。
在下文中一共展示了Collection::setCursor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
示例2: 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);
}
示例3: withCollection
/**
* Create a new collection resource with the given tranformer.
*
* @param array|object $collection
* @param object $transformer
* @param \League\Fractal\Pagination\CursorInterface $cursor
* @param string $key
* @return \Illuminate\Http\Response
*/
public function withCollection($collection, $transformer, FractalCursorInterface $cursor = null, $key = null)
{
$resource = new FractalCollection($collection, $transformer, $key);
if (!is_null($cursor)) {
$resource->setCursor($cursor);
}
return $this->build($resource);
}
示例4: 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);
}
示例5: 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());
}
示例6: respondWithCollection
/**
* Respond with a given collection.
*
* @param $collection
* @param int $skip
* @param int $limit
*
* @return mixed
*/
protected function respondWithCollection($collection, $skip = 0, $limit = 0)
{
$resource = new Collection($collection, $this->transformer, $this->resourceKeyPlural);
if ($limit) {
$cursor = new Cursor($skip, $skip + $limit, $collection->count());
$resource->setCursor($cursor);
}
$rootScope = $this->prepareRootScope($resource);
return $this->respond($rootScope->toArray());
}
示例7: testCursorOutput
public function testCursorOutput()
{
$manager = new Manager();
$inputData = array(array('foo' => 'bar', 'baz' => 'ban'));
$collection = new Collection($inputData, function (array $data) {
return $data;
});
$cursor = new Cursor(0, 'ban', 'ban', 2);
$collection->setCursor($cursor);
$rootScope = $manager->createData($collection);
$expectedOutput = array('meta' => array('cursor' => array('current' => 0, 'prev' => 'ban', 'next' => 'ban', 'count' => 2)), 'data' => $inputData);
$this->assertEquals($expectedOutput, $rootScope->toArray());
}
示例8: respondWithCursor
/**
* @param $paginator
* @param $callback
* @return JsonResponse
*/
protected function respondWithCursor($paginator, $callback)
{
$pagination = $paginator->getPaginate();
$resource = new Collection($pagination->items, $callback);
$cursor = new Cursor($pagination->current, $pagination->before, $pagination->next, $pagination->total_items);
$resource->setCursor($cursor);
$rootScope = $this->fractal->createData($resource);
return $this->respondWithArray($rootScope->toArray());
}