This commit is contained in:
Manish Verma
2016-12-13 18:18:25 +05:30
parent fc98add11c
commit 2d8e640e9b
2314 changed files with 97798 additions and 75664 deletions

View File

@@ -0,0 +1,163 @@
<?php
/*
* This file is part of the League\Fractal package.
*
* (c) Phil Sturgeon <me@philsturgeon.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Fractal\Pagination;
/**
* A generic cursor adapter.
*
* @author Isern Palaus <ipalaus@ipalaus.com>
* @author Michele Massari <michele@michelemassari.net>
*/
class Cursor implements CursorInterface
{
/**
* Current cursor value.
*
* @var mixed
*/
protected $current;
/**
* Previous cursor value.
*
* @var mixed
*/
protected $prev;
/**
* Next cursor value.
*
* @var mixed
*/
protected $next;
/**
* Items being held for the current cursor position.
*
* @var int
*/
protected $count;
/**
* Create a new Cursor instance.
*
* @param int $current
* @param null $prev
* @param mixed $next
* @param int $count
*
* @return void
*/
public function __construct($current = null, $prev = null, $next = null, $count = null)
{
$this->current = $current;
$this->prev = $prev;
$this->next = $next;
$this->count = $count;
}
/**
* Get the current cursor value.
*
* @return mixed
*/
public function getCurrent()
{
return $this->current;
}
/**
* Set the current cursor value.
*
* @param int $current
*
* @return Cursor
*/
public function setCurrent($current)
{
$this->current = $current;
return $this;
}
/**
* Get the prev cursor value.
*
* @return mixed
*/
public function getPrev()
{
return $this->prev;
}
/**
* Set the prev cursor value.
*
* @param int $prev
*
* @return Cursor
*/
public function setPrev($prev)
{
$this->prev = $prev;
return $this;
}
/**
* Get the next cursor value.
*
* @return mixed
*/
public function getNext()
{
return $this->next;
}
/**
* Set the next cursor value.
*
* @param int $next
*
* @return Cursor
*/
public function setNext($next)
{
$this->next = $next;
return $this;
}
/**
* Returns the total items in the current cursor.
*
* @return int
*/
public function getCount()
{
return $this->count;
}
/**
* Set the total items in the current cursor.
*
* @param int $count
*
* @return Cursor
*/
public function setCount($count)
{
$this->count = $count;
return $this;
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the League\Fractal package.
*
* (c) Phil Sturgeon <me@philsturgeon.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Fractal\Pagination;
/**
* A common interface for cursors to use.
*
* @author Isern Palaus <ipalaus@ipalaus.com>
*/
interface CursorInterface
{
/**
* Get the current cursor value.
*
* @return mixed
*/
public function getCurrent();
/**
* Get the prev cursor value.
*
* @return mixed
*/
public function getPrev();
/**
* Get the next cursor value.
*
* @return mixed
*/
public function getNext();
/**
* Returns the total items in the current cursor.
*
* @return int
*/
public function getCount();
}

View File

@@ -0,0 +1,114 @@
<?php
/*
* This file is part of the League\Fractal package.
*
* (c) Phil Sturgeon <me@philsturgeon.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Fractal\Pagination;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
/**
* A paginator adapter for illuminate/pagination.
*
* @author Maxime Beaudoin <firalabs@gmail.com>
* @author Marc Addeo <marcaddeo@gmail.com>
*/
class IlluminatePaginatorAdapter implements PaginatorInterface
{
/**
* The paginator instance.
*
* @var \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
protected $paginator;
/**
* Create a new illuminate pagination adapter.
*
* @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
*
* @return void
*/
public function __construct(LengthAwarePaginator $paginator)
{
$this->paginator = $paginator;
}
/**
* Get the current page.
*
* @return int
*/
public function getCurrentPage()
{
return $this->paginator->currentPage();
}
/**
* Get the last page.
*
* @return int
*/
public function getLastPage()
{
return $this->paginator->lastPage();
}
/**
* Get the total.
*
* @return int
*/
public function getTotal()
{
return $this->paginator->total();
}
/**
* Get the count.
*
* @return int
*/
public function getCount()
{
return $this->paginator->count();
}
/**
* Get the number per page.
*
* @return int
*/
public function getPerPage()
{
return $this->paginator->perPage();
}
/**
* Get the url for the given page.
*
* @param int $page
*
* @return string
*/
public function getUrl($page)
{
return $this->paginator->url($page);
}
/**
* Get the paginator instance.
*
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function getPaginator()
{
return $this->paginator;
}
}

View File

@@ -0,0 +1,132 @@
<?php
/*
* This file is part of the League\Fractal package.
*
* (c) Phil Sturgeon <me@philsturgeon.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Fractal\Pagination;
use Pagerfanta\Pagerfanta;
/**
* A paginator adapter for pagerfanta/pagerfanta.
*
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
*/
class PagerfantaPaginatorAdapter implements PaginatorInterface
{
/**
* The paginator instance.
*
* @var \Pagerfanta\Pagerfanta
*/
protected $paginator;
/**
* The route generator.
*
* @var callable
*/
protected $routeGenerator;
/**
* Create a new pagerfanta pagination adapter.
*
* @param \Pagerfanta\Pagerfanta $paginator
* @param callable $routeGenerator
*
* @return void
*/
public function __construct(Pagerfanta $paginator, $routeGenerator)
{
$this->paginator = $paginator;
$this->routeGenerator = $routeGenerator;
}
/**
* Get the current page.
*
* @return int
*/
public function getCurrentPage()
{
return $this->paginator->getCurrentPage();
}
/**
* Get the last page.
*
* @return int
*/
public function getLastPage()
{
return $this->paginator->getNbPages();
}
/**
* Get the total.
*
* @return int
*/
public function getTotal()
{
return count($this->paginator);
}
/**
* Get the count.
*
* @return int
*/
public function getCount()
{
return count($this->paginator->getCurrentPageResults());
}
/**
* Get the number per page.
*
* @return int
*/
public function getPerPage()
{
return $this->paginator->getMaxPerPage();
}
/**
* Get the url for the given page.
*
* @param int $page
*
* @return string
*/
public function getUrl($page)
{
return call_user_func($this->routeGenerator, $page);
}
/**
* Get the paginator instance.
*
* @return \Pagerfanta\Pagerfanta
*/
public function getPaginator()
{
return $this->paginator;
}
/**
* Get the the route generator.
*
* @return callable
*/
public function getRouteGenerator()
{
return $this->routeGenerator;
}
}

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of the League\Fractal package.
*
* (c) Phil Sturgeon <me@philsturgeon.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Fractal\Pagination;
/**
* A common interface for paginators to use
*
* @author Marc Addeo <marcaddeo@gmail.com>
*/
interface PaginatorInterface
{
/**
* Get the current page.
*
* @return int
*/
public function getCurrentPage();
/**
* Get the last page.
*
* @return int
*/
public function getLastPage();
/**
* Get the total.
*
* @return int
*/
public function getTotal();
/**
* Get the count.
*
* @return int
*/
public function getCount();
/**
* Get the number per page.
*
* @return int
*/
public function getPerPage();
/**
* Get the url for the given page.
*
* @param int $page
*
* @return string
*/
public function getUrl($page);
}

View File

@@ -0,0 +1,132 @@
<?php
/*
* This file is part of the League\Fractal package.
*
* (c) Phil Sturgeon <me@philsturgeon.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Fractal\Pagination;
use Zend\Paginator\Paginator;
/**
* A paginator adapter for zendframework/zend-paginator.
*
* @author Abdul Malik Ikhsan <samsonasik@gmail.com>
*/
class ZendFrameworkPaginatorAdapter implements PaginatorInterface
{
/**
* The paginator instance.
*
* @var \Zend\Paginator\Paginator
*/
protected $paginator;
/**
* The route generator.
*
* @var callable
*/
protected $routeGenerator;
/**
* Create a new zendframework pagination adapter.
*
* @param \Zend\Paginator\Paginator $paginator
* @param callable $routeGenerator
*
* @return void
*/
public function __construct(Paginator $paginator, $routeGenerator)
{
$this->paginator = $paginator;
$this->routeGenerator = $routeGenerator;
}
/**
* Get the current page.
*
* @return int
*/
public function getCurrentPage()
{
return $this->paginator->getCurrentPageNumber();
}
/**
* Get the last page.
*
* @return int
*/
public function getLastPage()
{
return $this->paginator->count();
}
/**
* Get the total.
*
* @return int
*/
public function getTotal()
{
return $this->paginator->getTotalItemCount();
}
/**
* Get the count.
*
* @return int
*/
public function getCount()
{
return $this->paginator->getCurrentItemCount();
}
/**
* Get the number per page.
*
* @return int
*/
public function getPerPage()
{
return $this->paginator->getItemCountPerPage();
}
/**
* Get the url for the given page.
*
* @param int $page
*
* @return string
*/
public function getUrl($page)
{
return call_user_func($this->routeGenerator, $page);
}
/**
* Get the paginator instance.
*
* @return \Zend\Paginator\Paginator
*/
public function getPaginator()
{
return $this->paginator;
}
/**
* Get the the route generator.
*
* @return callable
*/
public function getRouteGenerator()
{
return $this->routeGenerator;
}
}