Pressroom template verwijderd, website naar root van repo
This commit is contained in:
577
vendor/laravel/framework/src/Illuminate/Pagination/AbstractPaginator.php
vendored
Normal file
577
vendor/laravel/framework/src/Illuminate/Pagination/AbstractPaginator.php
vendored
Normal file
@@ -0,0 +1,577 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Pagination;
|
||||
|
||||
use Closure;
|
||||
use ArrayIterator;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
abstract class AbstractPaginator implements Htmlable
|
||||
{
|
||||
/**
|
||||
* All of the items being paginated.
|
||||
*
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
protected $items;
|
||||
|
||||
/**
|
||||
* The number of items to be shown per page.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $perPage;
|
||||
|
||||
/**
|
||||
* The current page being "viewed".
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $currentPage;
|
||||
|
||||
/**
|
||||
* The base path to assign to all URLs.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path = '/';
|
||||
|
||||
/**
|
||||
* The query parameters to add to all URLs.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $query = [];
|
||||
|
||||
/**
|
||||
* The URL fragment to add to all URLs.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $fragment;
|
||||
|
||||
/**
|
||||
* The query string variable used to store the page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $pageName = 'page';
|
||||
|
||||
/**
|
||||
* The current path resolver callback.
|
||||
*
|
||||
* @var \Closure
|
||||
*/
|
||||
protected static $currentPathResolver;
|
||||
|
||||
/**
|
||||
* The current page resolver callback.
|
||||
*
|
||||
* @var \Closure
|
||||
*/
|
||||
protected static $currentPageResolver;
|
||||
|
||||
/**
|
||||
* The view factory resolver callback.
|
||||
*
|
||||
* @var \Closure
|
||||
*/
|
||||
protected static $viewFactoryResolver;
|
||||
|
||||
/**
|
||||
* The default pagination view.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $defaultView = 'pagination::default';
|
||||
|
||||
/**
|
||||
* The default "simple" pagination view.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $defaultSimpleView = 'pagination::simple-default';
|
||||
|
||||
/**
|
||||
* Determine if the given value is a valid page number.
|
||||
*
|
||||
* @param int $page
|
||||
* @return bool
|
||||
*/
|
||||
protected function isValidPageNumber($page)
|
||||
{
|
||||
return $page >= 1 && filter_var($page, FILTER_VALIDATE_INT) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for the previous page.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function previousPageUrl()
|
||||
{
|
||||
if ($this->currentPage() > 1) {
|
||||
return $this->url($this->currentPage() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a range of pagination URLs.
|
||||
*
|
||||
* @param int $start
|
||||
* @param int $end
|
||||
* @return array
|
||||
*/
|
||||
public function getUrlRange($start, $end)
|
||||
{
|
||||
return collect(range($start, $end))->mapWithKeys(function ($page) {
|
||||
return [$page => $this->url($page)];
|
||||
})->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for a given page number.
|
||||
*
|
||||
* @param int $page
|
||||
* @return string
|
||||
*/
|
||||
public function url($page)
|
||||
{
|
||||
if ($page <= 0) {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
// If we have any extra query string key / value pairs that need to be added
|
||||
// onto the URL, we will put them in query string form and then attach it
|
||||
// to the URL. This allows for extra information like sortings storage.
|
||||
$parameters = [$this->pageName => $page];
|
||||
|
||||
if (count($this->query) > 0) {
|
||||
$parameters = array_merge($this->query, $parameters);
|
||||
}
|
||||
|
||||
return $this->path
|
||||
.(Str::contains($this->path, '?') ? '&' : '?')
|
||||
.http_build_query($parameters, '', '&')
|
||||
.$this->buildFragment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get / set the URL fragment to be appended to URLs.
|
||||
*
|
||||
* @param string|null $fragment
|
||||
* @return $this|string|null
|
||||
*/
|
||||
public function fragment($fragment = null)
|
||||
{
|
||||
if (is_null($fragment)) {
|
||||
return $this->fragment;
|
||||
}
|
||||
|
||||
$this->fragment = $fragment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a set of query string values to the paginator.
|
||||
*
|
||||
* @param array|string $key
|
||||
* @param string|null $value
|
||||
* @return $this
|
||||
*/
|
||||
public function appends($key, $value = null)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
return $this->appendArray($key);
|
||||
}
|
||||
|
||||
return $this->addQuery($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an array of query string values.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return $this
|
||||
*/
|
||||
protected function appendArray(array $keys)
|
||||
{
|
||||
foreach ($keys as $key => $value) {
|
||||
$this->addQuery($key, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a query string value to the paginator.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
protected function addQuery($key, $value)
|
||||
{
|
||||
if ($key !== $this->pageName) {
|
||||
$this->query[$key] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the full fragment portion of a URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildFragment()
|
||||
{
|
||||
return $this->fragment ? '#'.$this->fragment : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the slice of items being paginated.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function items()
|
||||
{
|
||||
return $this->items->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of the first item in the slice.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function firstItem()
|
||||
{
|
||||
return count($this->items) > 0 ? ($this->currentPage - 1) * $this->perPage + 1 : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of the last item in the slice.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function lastItem()
|
||||
{
|
||||
return count($this->items) > 0 ? $this->firstItem() + $this->count() - 1 : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of items shown per page.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function perPage()
|
||||
{
|
||||
return $this->perPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are enough items to split into multiple pages.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPages()
|
||||
{
|
||||
return $this->currentPage() != 1 || $this->hasMorePages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the paginator is on the first page.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function onFirstPage()
|
||||
{
|
||||
return $this->currentPage() <= 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current page.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function currentPage()
|
||||
{
|
||||
return $this->currentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query string variable used to store the page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPageName()
|
||||
{
|
||||
return $this->pageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the query string variable used to store the page.
|
||||
*
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setPageName($name)
|
||||
{
|
||||
$this->pageName = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base path to assign to all URLs.
|
||||
*
|
||||
* @param string $path
|
||||
* @return $this
|
||||
*/
|
||||
public function withPath($path)
|
||||
{
|
||||
return $this->setPath($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base path to assign to all URLs.
|
||||
*
|
||||
* @param string $path
|
||||
* @return $this
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the current request path or return the default value.
|
||||
*
|
||||
* @param string $default
|
||||
* @return string
|
||||
*/
|
||||
public static function resolveCurrentPath($default = '/')
|
||||
{
|
||||
if (isset(static::$currentPathResolver)) {
|
||||
return call_user_func(static::$currentPathResolver);
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current request path resolver callback.
|
||||
*
|
||||
* @param \Closure $resolver
|
||||
* @return void
|
||||
*/
|
||||
public static function currentPathResolver(Closure $resolver)
|
||||
{
|
||||
static::$currentPathResolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the current page or return the default value.
|
||||
*
|
||||
* @param string $pageName
|
||||
* @param int $default
|
||||
* @return int
|
||||
*/
|
||||
public static function resolveCurrentPage($pageName = 'page', $default = 1)
|
||||
{
|
||||
if (isset(static::$currentPageResolver)) {
|
||||
return call_user_func(static::$currentPageResolver, $pageName);
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current page resolver callback.
|
||||
*
|
||||
* @param \Closure $resolver
|
||||
* @return void
|
||||
*/
|
||||
public static function currentPageResolver(Closure $resolver)
|
||||
{
|
||||
static::$currentPageResolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of the view factory from the resolver.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public static function viewFactory()
|
||||
{
|
||||
return call_user_func(static::$viewFactoryResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view factory resolver callback.
|
||||
*
|
||||
* @param \Closure $resolver
|
||||
* @return void
|
||||
*/
|
||||
public static function viewFactoryResolver(Closure $resolver)
|
||||
{
|
||||
static::$viewFactoryResolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default pagination view.
|
||||
*
|
||||
* @param string $view
|
||||
* @return void
|
||||
*/
|
||||
public static function defaultView($view)
|
||||
{
|
||||
static::$defaultView = $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default "simple" pagination view.
|
||||
*
|
||||
* @param string $view
|
||||
* @return void
|
||||
*/
|
||||
public static function defaultSimpleView($view)
|
||||
{
|
||||
static::$defaultSimpleView = $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator for the items.
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->items->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the list of items is empty or not.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->items->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of items for the current page.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->items->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the paginator's underlying collection.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getCollection()
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the paginator's underlying collection.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $collection
|
||||
* @return $this
|
||||
*/
|
||||
public function setCollection(Collection $collection)
|
||||
{
|
||||
$this->items = $collection;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given item exists.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($key)
|
||||
{
|
||||
return $this->items->has($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item at the given offset.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($key)
|
||||
{
|
||||
return $this->items->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item at the given offset.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($key, $value)
|
||||
{
|
||||
$this->items->put($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the item at the given key.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($key)
|
||||
{
|
||||
$this->items->forget($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the contents of the paginator to HTML.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toHtml()
|
||||
{
|
||||
return (string) $this->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make dynamic calls into the collection.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return $this->getCollection()->$method(...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the contents of the paginator when casting to string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) $this->render();
|
||||
}
|
||||
}
|
||||
197
vendor/laravel/framework/src/Illuminate/Pagination/LengthAwarePaginator.php
vendored
Normal file
197
vendor/laravel/framework/src/Illuminate/Pagination/LengthAwarePaginator.php
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Pagination;
|
||||
|
||||
use Countable;
|
||||
use ArrayAccess;
|
||||
use JsonSerializable;
|
||||
use IteratorAggregate;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Contracts\Support\Jsonable;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator as LengthAwarePaginatorContract;
|
||||
|
||||
class LengthAwarePaginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Jsonable, LengthAwarePaginatorContract
|
||||
{
|
||||
/**
|
||||
* The total number of items before slicing.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $total;
|
||||
|
||||
/**
|
||||
* The last available page.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lastPage;
|
||||
|
||||
/**
|
||||
* Create a new paginator instance.
|
||||
*
|
||||
* @param mixed $items
|
||||
* @param int $total
|
||||
* @param int $perPage
|
||||
* @param int|null $currentPage
|
||||
* @param array $options (path, query, fragment, pageName)
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($items, $total, $perPage, $currentPage = null, array $options = [])
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
|
||||
$this->total = $total;
|
||||
$this->perPage = $perPage;
|
||||
$this->lastPage = (int) ceil($total / $perPage);
|
||||
$this->path = $this->path != '/' ? rtrim($this->path, '/') : $this->path;
|
||||
$this->currentPage = $this->setCurrentPage($currentPage, $this->pageName);
|
||||
$this->items = $items instanceof Collection ? $items : Collection::make($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current page for the request.
|
||||
*
|
||||
* @param int $currentPage
|
||||
* @param string $pageName
|
||||
* @return int
|
||||
*/
|
||||
protected function setCurrentPage($currentPage, $pageName)
|
||||
{
|
||||
$currentPage = $currentPage ?: static::resolveCurrentPage($pageName);
|
||||
|
||||
return $this->isValidPageNumber($currentPage) ? (int) $currentPage : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the paginator using the given view.
|
||||
*
|
||||
* @param string $view
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function links($view = null, $data = [])
|
||||
{
|
||||
return $this->render($view, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the paginator using the given view.
|
||||
*
|
||||
* @param string $view
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function render($view = null, $data = [])
|
||||
{
|
||||
return new HtmlString(static::viewFactory()->make($view ?: static::$defaultView, array_merge($data, [
|
||||
'paginator' => $this,
|
||||
'elements' => $this->elements(),
|
||||
]))->render());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of elements to pass to the view.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function elements()
|
||||
{
|
||||
$window = UrlWindow::make($this);
|
||||
|
||||
return array_filter([
|
||||
$window['first'],
|
||||
is_array($window['slider']) ? '...' : null,
|
||||
$window['slider'],
|
||||
is_array($window['last']) ? '...' : null,
|
||||
$window['last'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of items being paginated.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function total()
|
||||
{
|
||||
return $this->total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are more items in the data source.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMorePages()
|
||||
{
|
||||
return $this->currentPage() < $this->lastPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for the next page.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function nextPageUrl()
|
||||
{
|
||||
if ($this->lastPage() > $this->currentPage()) {
|
||||
return $this->url($this->currentPage() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last page.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function lastPage()
|
||||
{
|
||||
return $this->lastPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance as an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'current_page' => $this->currentPage(),
|
||||
'data' => $this->items->toArray(),
|
||||
'from' => $this->firstItem(),
|
||||
'last_page' => $this->lastPage(),
|
||||
'next_page_url' => $this->nextPageUrl(),
|
||||
'path' => $this->path,
|
||||
'per_page' => $this->perPage(),
|
||||
'prev_page_url' => $this->previousPageUrl(),
|
||||
'to' => $this->lastItem(),
|
||||
'total' => $this->total(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the object into something JSON serializable.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the object to its JSON representation.
|
||||
*
|
||||
* @param int $options
|
||||
* @return string
|
||||
*/
|
||||
public function toJson($options = 0)
|
||||
{
|
||||
return json_encode($this->jsonSerialize(), $options);
|
||||
}
|
||||
}
|
||||
50
vendor/laravel/framework/src/Illuminate/Pagination/PaginationServiceProvider.php
vendored
Executable file
50
vendor/laravel/framework/src/Illuminate/Pagination/PaginationServiceProvider.php
vendored
Executable file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Pagination;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class PaginationServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__.'/resources/views', 'pagination');
|
||||
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->publishes([
|
||||
__DIR__.'/resources/views' => $this->app->resourcePath('views/vendor/pagination'),
|
||||
], 'laravel-pagination');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
Paginator::viewFactoryResolver(function () {
|
||||
return $this->app['view'];
|
||||
});
|
||||
|
||||
Paginator::currentPathResolver(function () {
|
||||
return $this->app['request']->url();
|
||||
});
|
||||
|
||||
Paginator::currentPageResolver(function ($pageName = 'page') {
|
||||
$page = $this->app['request']->input($pageName);
|
||||
|
||||
if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
|
||||
return $page;
|
||||
}
|
||||
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
176
vendor/laravel/framework/src/Illuminate/Pagination/Paginator.php
vendored
Normal file
176
vendor/laravel/framework/src/Illuminate/Pagination/Paginator.php
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Pagination;
|
||||
|
||||
use Countable;
|
||||
use ArrayAccess;
|
||||
use JsonSerializable;
|
||||
use IteratorAggregate;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Contracts\Support\Jsonable;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
|
||||
|
||||
class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Jsonable, PaginatorContract
|
||||
{
|
||||
/**
|
||||
* Determine if there are more items in the data source.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected $hasMore;
|
||||
|
||||
/**
|
||||
* Create a new paginator instance.
|
||||
*
|
||||
* @param mixed $items
|
||||
* @param int $perPage
|
||||
* @param int|null $currentPage
|
||||
* @param array $options (path, query, fragment, pageName)
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($items, $perPage, $currentPage = null, array $options = [])
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
|
||||
$this->perPage = $perPage;
|
||||
$this->currentPage = $this->setCurrentPage($currentPage);
|
||||
$this->path = $this->path != '/' ? rtrim($this->path, '/') : $this->path;
|
||||
|
||||
$this->setItems($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current page for the request.
|
||||
*
|
||||
* @param int $currentPage
|
||||
* @return int
|
||||
*/
|
||||
protected function setCurrentPage($currentPage)
|
||||
{
|
||||
$currentPage = $currentPage ?: static::resolveCurrentPage();
|
||||
|
||||
return $this->isValidPageNumber($currentPage) ? (int) $currentPage : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the items for the paginator.
|
||||
*
|
||||
* @param mixed $items
|
||||
* @return void
|
||||
*/
|
||||
protected function setItems($items)
|
||||
{
|
||||
$this->items = $items instanceof Collection ? $items : Collection::make($items);
|
||||
|
||||
$this->hasMore = count($this->items) > ($this->perPage);
|
||||
|
||||
$this->items = $this->items->slice(0, $this->perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for the next page.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function nextPageUrl()
|
||||
{
|
||||
if ($this->hasMorePages()) {
|
||||
return $this->url($this->currentPage() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the paginator using the given view.
|
||||
*
|
||||
* @param string|null $view
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function links($view = null, $data = [])
|
||||
{
|
||||
return $this->render($view, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the paginator using the given view.
|
||||
*
|
||||
* @param string|null $view
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function render($view = null, $data = [])
|
||||
{
|
||||
return new HtmlString(
|
||||
static::viewFactory()->make($view ?: static::$defaultSimpleView, array_merge($data, [
|
||||
'paginator' => $this,
|
||||
]))->render()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually indicate that the paginator does have more pages.
|
||||
*
|
||||
* @param bool $value
|
||||
* @return $this
|
||||
*/
|
||||
public function hasMorePagesWhen($value = true)
|
||||
{
|
||||
$this->hasMore = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are more items in the data source.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMorePages()
|
||||
{
|
||||
return $this->hasMore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance as an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'current_page' => $this->currentPage(),
|
||||
'data' => $this->items->toArray(),
|
||||
'from' => $this->firstItem(),
|
||||
'next_page_url' => $this->nextPageUrl(),
|
||||
'path' => $this->path,
|
||||
'per_page' => $this->perPage(),
|
||||
'prev_page_url' => $this->previousPageUrl(),
|
||||
'to' => $this->lastItem(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the object into something JSON serializable.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the object to its JSON representation.
|
||||
*
|
||||
* @param int $options
|
||||
* @return string
|
||||
*/
|
||||
public function toJson($options = 0)
|
||||
{
|
||||
return json_encode($this->jsonSerialize(), $options);
|
||||
}
|
||||
}
|
||||
218
vendor/laravel/framework/src/Illuminate/Pagination/UrlWindow.php
vendored
Normal file
218
vendor/laravel/framework/src/Illuminate/Pagination/UrlWindow.php
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Pagination;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator as PaginatorContract;
|
||||
|
||||
class UrlWindow
|
||||
{
|
||||
/**
|
||||
* The paginator implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
protected $paginator;
|
||||
|
||||
/**
|
||||
* Create a new URL window instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(PaginatorContract $paginator)
|
||||
{
|
||||
$this->paginator = $paginator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new URL window instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
|
||||
* @param int $onEachSide
|
||||
* @return array
|
||||
*/
|
||||
public static function make(PaginatorContract $paginator, $onEachSide = 3)
|
||||
{
|
||||
return (new static($paginator))->get($onEachSide);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the window of URLs to be shown.
|
||||
*
|
||||
* @param int $onEachSide
|
||||
* @return array
|
||||
*/
|
||||
public function get($onEachSide = 3)
|
||||
{
|
||||
if ($this->paginator->lastPage() < ($onEachSide * 2) + 6) {
|
||||
return $this->getSmallSlider();
|
||||
}
|
||||
|
||||
return $this->getUrlSlider($onEachSide);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the slider of URLs there are not enough pages to slide.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSmallSlider()
|
||||
{
|
||||
return [
|
||||
'first' => $this->paginator->getUrlRange(1, $this->lastPage()),
|
||||
'slider' => null,
|
||||
'last' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a URL slider links.
|
||||
*
|
||||
* @param int $onEachSide
|
||||
* @return array
|
||||
*/
|
||||
protected function getUrlSlider($onEachSide)
|
||||
{
|
||||
$window = $onEachSide * 2;
|
||||
|
||||
if (! $this->hasPages()) {
|
||||
return ['first' => null, 'slider' => null, 'last' => null];
|
||||
}
|
||||
|
||||
// If the current page is very close to the beginning of the page range, we will
|
||||
// just render the beginning of the page range, followed by the last 2 of the
|
||||
// links in this list, since we will not have room to create a full slider.
|
||||
if ($this->currentPage() <= $window) {
|
||||
return $this->getSliderTooCloseToBeginning($window);
|
||||
}
|
||||
|
||||
// If the current page is close to the ending of the page range we will just get
|
||||
// this first couple pages, followed by a larger window of these ending pages
|
||||
// since we're too close to the end of the list to create a full on slider.
|
||||
elseif ($this->currentPage() > ($this->lastPage() - $window)) {
|
||||
return $this->getSliderTooCloseToEnding($window);
|
||||
}
|
||||
|
||||
// If we have enough room on both sides of the current page to build a slider we
|
||||
// will surround it with both the beginning and ending caps, with this window
|
||||
// of pages in the middle providing a Google style sliding paginator setup.
|
||||
return $this->getFullSlider($onEachSide);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the slider of URLs when too close to beginning of window.
|
||||
*
|
||||
* @param int $window
|
||||
* @return array
|
||||
*/
|
||||
protected function getSliderTooCloseToBeginning($window)
|
||||
{
|
||||
return [
|
||||
'first' => $this->paginator->getUrlRange(1, $window + 2),
|
||||
'slider' => null,
|
||||
'last' => $this->getFinish(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the slider of URLs when too close to ending of window.
|
||||
*
|
||||
* @param int $window
|
||||
* @return array
|
||||
*/
|
||||
protected function getSliderTooCloseToEnding($window)
|
||||
{
|
||||
$last = $this->paginator->getUrlRange(
|
||||
$this->lastPage() - ($window + 2),
|
||||
$this->lastPage()
|
||||
);
|
||||
|
||||
return [
|
||||
'first' => $this->getStart(),
|
||||
'slider' => null,
|
||||
'last' => $last,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the slider of URLs when a full slider can be made.
|
||||
*
|
||||
* @param int $onEachSide
|
||||
* @return array
|
||||
*/
|
||||
protected function getFullSlider($onEachSide)
|
||||
{
|
||||
return [
|
||||
'first' => $this->getStart(),
|
||||
'slider' => $this->getAdjacentUrlRange($onEachSide),
|
||||
'last' => $this->getFinish(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page range for the current page window.
|
||||
*
|
||||
* @param int $onEachSide
|
||||
* @return array
|
||||
*/
|
||||
public function getAdjacentUrlRange($onEachSide)
|
||||
{
|
||||
return $this->paginator->getUrlRange(
|
||||
$this->currentPage() - $onEachSide,
|
||||
$this->currentPage() + $onEachSide
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the starting URLs of a pagination slider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStart()
|
||||
{
|
||||
return $this->paginator->getUrlRange(1, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ending URLs of a pagination slider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFinish()
|
||||
{
|
||||
return $this->paginator->getUrlRange(
|
||||
$this->lastPage() - 1,
|
||||
$this->lastPage()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the underlying paginator being presented has pages to show.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPages()
|
||||
{
|
||||
return $this->paginator->lastPage() > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current page from the paginator.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function currentPage()
|
||||
{
|
||||
return $this->paginator->currentPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last page from the paginator.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function lastPage()
|
||||
{
|
||||
return $this->paginator->lastPage();
|
||||
}
|
||||
}
|
||||
35
vendor/laravel/framework/src/Illuminate/Pagination/composer.json
vendored
Executable file
35
vendor/laravel/framework/src/Illuminate/Pagination/composer.json
vendored
Executable file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "illuminate/pagination",
|
||||
"description": "The Illuminate Pagination package.",
|
||||
"license": "MIT",
|
||||
"homepage": "https://laravel.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.6.4",
|
||||
"illuminate/contracts": "5.4.*",
|
||||
"illuminate/support": "5.4.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Pagination\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.4-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
36
vendor/laravel/framework/src/Illuminate/Pagination/resources/views/bootstrap-4.blade.php
vendored
Normal file
36
vendor/laravel/framework/src/Illuminate/Pagination/resources/views/bootstrap-4.blade.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
@if ($paginator->hasPages())
|
||||
<ul class="pagination">
|
||||
{{-- Previous Page Link --}}
|
||||
@if ($paginator->onFirstPage())
|
||||
<li class="page-item disabled"><span class="page-link">«</span></li>
|
||||
@else
|
||||
<li class="page-item"><a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev">«</a></li>
|
||||
@endif
|
||||
|
||||
{{-- Pagination Elements --}}
|
||||
@foreach ($elements as $element)
|
||||
{{-- "Three Dots" Separator --}}
|
||||
@if (is_string($element))
|
||||
<li class="page-item disabled"><span class="page-link">{{ $element }}</span></li>
|
||||
@endif
|
||||
|
||||
{{-- Array Of Links --}}
|
||||
@if (is_array($element))
|
||||
@foreach ($element as $page => $url)
|
||||
@if ($page == $paginator->currentPage())
|
||||
<li class="page-item active"><span class="page-link">{{ $page }}</span></li>
|
||||
@else
|
||||
<li class="page-item"><a class="page-link" href="{{ $url }}">{{ $page }}</a></li>
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- Next Page Link --}}
|
||||
@if ($paginator->hasMorePages())
|
||||
<li class="page-item"><a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next">»</a></li>
|
||||
@else
|
||||
<li class="page-item disabled"><span class="page-link">»</span></li>
|
||||
@endif
|
||||
</ul>
|
||||
@endif
|
||||
36
vendor/laravel/framework/src/Illuminate/Pagination/resources/views/default.blade.php
vendored
Normal file
36
vendor/laravel/framework/src/Illuminate/Pagination/resources/views/default.blade.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
@if ($paginator->hasPages())
|
||||
<ul class="pagination">
|
||||
{{-- Previous Page Link --}}
|
||||
@if ($paginator->onFirstPage())
|
||||
<li class="disabled"><span>«</span></li>
|
||||
@else
|
||||
<li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">«</a></li>
|
||||
@endif
|
||||
|
||||
{{-- Pagination Elements --}}
|
||||
@foreach ($elements as $element)
|
||||
{{-- "Three Dots" Separator --}}
|
||||
@if (is_string($element))
|
||||
<li class="disabled"><span>{{ $element }}</span></li>
|
||||
@endif
|
||||
|
||||
{{-- Array Of Links --}}
|
||||
@if (is_array($element))
|
||||
@foreach ($element as $page => $url)
|
||||
@if ($page == $paginator->currentPage())
|
||||
<li class="active"><span>{{ $page }}</span></li>
|
||||
@else
|
||||
<li><a href="{{ $url }}">{{ $page }}</a></li>
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- Next Page Link --}}
|
||||
@if ($paginator->hasMorePages())
|
||||
<li><a href="{{ $paginator->nextPageUrl() }}" rel="next">»</a></li>
|
||||
@else
|
||||
<li class="disabled"><span>»</span></li>
|
||||
@endif
|
||||
</ul>
|
||||
@endif
|
||||
17
vendor/laravel/framework/src/Illuminate/Pagination/resources/views/simple-bootstrap-4.blade.php
vendored
Normal file
17
vendor/laravel/framework/src/Illuminate/Pagination/resources/views/simple-bootstrap-4.blade.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@if ($paginator->hasPages())
|
||||
<ul class="pagination">
|
||||
{{-- Previous Page Link --}}
|
||||
@if ($paginator->onFirstPage())
|
||||
<li class="page-item disabled"><span class="page-link">@lang('pagination.previous')</span></li>
|
||||
@else
|
||||
<li class="page-item"><a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev">@lang('pagination.previous')</a></li>
|
||||
@endif
|
||||
|
||||
{{-- Next Page Link --}}
|
||||
@if ($paginator->hasMorePages())
|
||||
<li class="page-item"><a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next">@lang('pagination.next')</a></li>
|
||||
@else
|
||||
<li class="page-item disabled"><span class="page-link">@lang('pagination.next')</span></li>
|
||||
@endif
|
||||
</ul>
|
||||
@endif
|
||||
17
vendor/laravel/framework/src/Illuminate/Pagination/resources/views/simple-default.blade.php
vendored
Normal file
17
vendor/laravel/framework/src/Illuminate/Pagination/resources/views/simple-default.blade.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@if ($paginator->hasPages())
|
||||
<ul class="pagination">
|
||||
{{-- Previous Page Link --}}
|
||||
@if ($paginator->onFirstPage())
|
||||
<li class="disabled"><span>@lang('pagination.previous')</span></li>
|
||||
@else
|
||||
<li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">@lang('pagination.previous')</a></li>
|
||||
@endif
|
||||
|
||||
{{-- Next Page Link --}}
|
||||
@if ($paginator->hasMorePages())
|
||||
<li><a href="{{ $paginator->nextPageUrl() }}" rel="next">@lang('pagination.next')</a></li>
|
||||
@else
|
||||
<li class="disabled"><span>@lang('pagination.next')</span></li>
|
||||
@endif
|
||||
</ul>
|
||||
@endif
|
||||
Reference in New Issue
Block a user