Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -3,11 +3,13 @@
namespace Illuminate\Pagination;
use Closure;
use ArrayIterator;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Support\Htmlable;
/**
* @mixin \Illuminate\Support\Collection
*/
abstract class AbstractPaginator implements Htmlable
{
/**
@@ -50,7 +52,7 @@ abstract class AbstractPaginator implements Htmlable
*
* @var string|null
*/
protected $fragment = null;
protected $fragment;
/**
* The query string variable used to store the page.
@@ -60,7 +62,7 @@ abstract class AbstractPaginator implements Htmlable
protected $pageName = 'page';
/**
* The current page resolver callback.
* The current path resolver callback.
*
* @var \Closure
*/
@@ -74,11 +76,25 @@ abstract class AbstractPaginator implements Htmlable
protected static $currentPageResolver;
/**
* The default presenter resolver.
* The view factory resolver callback.
*
* @var \Closure
*/
protected static $presenterResolver;
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.
@@ -91,26 +107,34 @@ abstract class AbstractPaginator implements Htmlable
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 string
* @return array
*/
public function getUrlRange($start, $end)
{
$urls = [];
for ($page = $start; $page <= $end; $page++) {
$urls[$page] = $this->url($page);
}
return $urls;
return collect(range($start, $end))->mapWithKeys(function ($page) {
return [$page => $this->url($page)];
})->all();
}
/**
* Get a URL for a given page number.
* Get the URL for a given page number.
*
* @param int $page
* @return string
@@ -136,18 +160,6 @@ abstract class AbstractPaginator implements Htmlable
.$this->buildFragment();
}
/**
* Get the URL for the previous page.
*
* @return string|null
*/
public function previousPageUrl()
{
if ($this->currentPage() > 1) {
return $this->url($this->currentPage() - 1);
}
}
/**
* Get / set the URL fragment to be appended to URLs.
*
@@ -203,7 +215,7 @@ abstract class AbstractPaginator implements Htmlable
* @param string $value
* @return $this
*/
public function addQuery($key, $value)
protected function addQuery($key, $value)
{
if ($key !== $this->pageName) {
$this->query[$key] = $value;
@@ -239,11 +251,7 @@ abstract class AbstractPaginator implements Htmlable
*/
public function firstItem()
{
if (count($this->items) === 0) {
return;
}
return ($this->currentPage - 1) * $this->perPage + 1;
return count($this->items) > 0 ? ($this->currentPage - 1) * $this->perPage + 1 : null;
}
/**
@@ -253,11 +261,7 @@ abstract class AbstractPaginator implements Htmlable
*/
public function lastItem()
{
if (count($this->items) === 0) {
return;
}
return $this->firstItem() + $this->count() - 1;
return count($this->items) > 0 ? $this->firstItem() + $this->count() - 1 : null;
}
/**
@@ -270,6 +274,26 @@ abstract class AbstractPaginator implements Htmlable
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.
*
@@ -281,13 +305,50 @@ abstract class AbstractPaginator implements Htmlable
}
/**
* Determine if there are enough items to split into multiple pages.
* Get the query string variable used to store the page.
*
* @return bool
* @return string
*/
public function hasPages()
public function getPageName()
{
return ! ($this->currentPage() == 1 && ! $this->hasMorePages());
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;
}
/**
@@ -344,50 +405,46 @@ abstract class AbstractPaginator implements Htmlable
}
/**
* Set the default Presenter 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 presenter(Closure $resolver)
public static function viewFactoryResolver(Closure $resolver)
{
static::$presenterResolver = $resolver;
static::$viewFactoryResolver = $resolver;
}
/**
* Get the query string variable used to store the page.
* Set the default pagination view.
*
* @return string
* @param string $view
* @return void
*/
public function getPageName()
public static function defaultView($view)
{
return $this->pageName;
static::$defaultView = $view;
}
/**
* Set the query string variable used to store the page.
* Set the default "simple" pagination view.
*
* @param string $name
* @return $this
* @param string $view
* @return void
*/
public function setPageName($name)
public static function defaultSimpleView($view)
{
$this->pageName = $name;
return $this;
}
/**
* Set the base path to assign to all URLs.
*
* @param string $path
* @return $this
*/
public function setPath($path)
{
$this->path = $path;
return $this;
static::$defaultSimpleView = $view;
}
/**
@@ -397,7 +454,7 @@ abstract class AbstractPaginator implements Htmlable
*/
public function getIterator()
{
return new ArrayIterator($this->items->all());
return $this->items->getIterator();
}
/**
@@ -410,6 +467,16 @@ abstract class AbstractPaginator implements Htmlable
return $this->items->isEmpty();
}
/**
* Determine if the list of items is not empty.
*
* @return bool
*/
public function isNotEmpty()
{
return $this->items->isNotEmpty();
}
/**
* Get the number of items for the current page.
*
@@ -507,7 +574,7 @@ abstract class AbstractPaginator implements Htmlable
*/
public function __call($method, $parameters)
{
return call_user_func_array([$this->getCollection(), $method], $parameters);
return $this->getCollection()->$method(...$parameters);
}
/**

View File

@@ -1,48 +0,0 @@
<?php
namespace Illuminate\Pagination;
trait BootstrapFourNextPreviousButtonRendererTrait
{
/**
* Get the previous page pagination element.
*
* @param string $text
* @return string
*/
public function getPreviousButton($text = '&laquo;')
{
// If the current page is less than or equal to one, it means we can't go any
// further back in the pages, so we will render a disabled previous button
// when that is the case. Otherwise, we will give it an active "status".
if ($this->paginator->currentPage() <= 1) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->paginator->url(
$this->paginator->currentPage() - 1
);
return $this->getPageLinkWrapper($url, $text, 'prev');
}
/**
* Get the next page pagination element.
*
* @param string $text
* @return string
*/
public function getNextButton($text = '&raquo;')
{
// If the current page is greater than or equal to the last page, it means we
// can't go any further into the pages, as we're already on this last page
// that is available, so we will make it the "next" link style disabled.
if (! $this->paginator->hasMorePages()) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->paginator->url($this->paginator->currentPage() + 1);
return $this->getPageLinkWrapper($url, $text, 'next');
}
}

View File

@@ -1,135 +0,0 @@
<?php
namespace Illuminate\Pagination;
use Illuminate\Support\HtmlString;
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
use Illuminate\Contracts\Pagination\Presenter as PresenterContract;
class BootstrapFourPresenter implements PresenterContract
{
use BootstrapFourNextPreviousButtonRendererTrait, UrlWindowPresenterTrait;
/**
* The paginator implementation.
*
* @var \Illuminate\Contracts\Pagination\Paginator
*/
protected $paginator;
/**
* The URL window data structure.
*
* @var array
*/
protected $window;
/**
* Create a new Bootstrap presenter instance.
*
* @param \Illuminate\Contracts\Pagination\Paginator $paginator
* @param \Illuminate\Pagination\UrlWindow|null $window
* @return void
*/
public function __construct(PaginatorContract $paginator, UrlWindow $window = null)
{
$this->paginator = $paginator;
$this->window = is_null($window) ? UrlWindow::make($paginator) : $window->get();
}
/**
* Determine if the underlying paginator being presented has pages to show.
*
* @return bool
*/
public function hasPages()
{
return $this->paginator->hasPages();
}
/**
* Convert the URL window into Bootstrap HTML.
*
* @return \Illuminate\Support\HtmlString
*/
public function render()
{
if ($this->hasPages()) {
return new HtmlString(sprintf(
'<ul class="pagination">%s %s %s</ul>',
$this->getPreviousButton(),
$this->getLinks(),
$this->getNextButton()
));
}
return '';
}
/**
* Get HTML wrapper for an available page link.
*
* @param string $url
* @param int $page
* @param string|null $rel
* @return string
*/
protected function getAvailablePageWrapper($url, $page, $rel = null)
{
$rel = is_null($rel) ? '' : ' rel="'.$rel.'"';
return '<li class="page-item"><a class="page-link" href="'.htmlentities($url).'"'.$rel.'>'.$page.'</a></li>';
}
/**
* Get HTML wrapper for disabled text.
*
* @param string $text
* @return string
*/
protected function getDisabledTextWrapper($text)
{
return '<li class="page-item disabled"><a class="page-link">'.$text.'</a></li>';
}
/**
* Get HTML wrapper for active text.
*
* @param string $text
* @return string
*/
protected function getActivePageWrapper($text)
{
return '<li class="page-item active"><a class="page-link">'.$text.'</a></li>';
}
/**
* Get a pagination "dot" element.
*
* @return string
*/
protected function getDots()
{
return $this->getDisabledTextWrapper('...');
}
/**
* 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();
}
}

View File

@@ -1,48 +0,0 @@
<?php
namespace Illuminate\Pagination;
trait BootstrapThreeNextPreviousButtonRendererTrait
{
/**
* Get the previous page pagination element.
*
* @param string $text
* @return string
*/
public function getPreviousButton($text = '&laquo;')
{
// If the current page is less than or equal to one, it means we can't go any
// further back in the pages, so we will render a disabled previous button
// when that is the case. Otherwise, we will give it an active "status".
if ($this->paginator->currentPage() <= 1) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->paginator->url(
$this->paginator->currentPage() - 1
);
return $this->getPageLinkWrapper($url, $text, 'prev');
}
/**
* Get the next page pagination element.
*
* @param string $text
* @return string
*/
public function getNextButton($text = '&raquo;')
{
// If the current page is greater than or equal to the last page, it means we
// can't go any further into the pages, as we're already on this last page
// that is available, so we will make it the "next" link style disabled.
if (! $this->paginator->hasMorePages()) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->paginator->url($this->paginator->currentPage() + 1);
return $this->getPageLinkWrapper($url, $text, 'next');
}
}

View File

@@ -1,135 +0,0 @@
<?php
namespace Illuminate\Pagination;
use Illuminate\Support\HtmlString;
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
use Illuminate\Contracts\Pagination\Presenter as PresenterContract;
class BootstrapThreePresenter implements PresenterContract
{
use BootstrapThreeNextPreviousButtonRendererTrait, UrlWindowPresenterTrait;
/**
* The paginator implementation.
*
* @var \Illuminate\Contracts\Pagination\Paginator
*/
protected $paginator;
/**
* The URL window data structure.
*
* @var array
*/
protected $window;
/**
* Create a new Bootstrap presenter instance.
*
* @param \Illuminate\Contracts\Pagination\Paginator $paginator
* @param \Illuminate\Pagination\UrlWindow|null $window
* @return void
*/
public function __construct(PaginatorContract $paginator, UrlWindow $window = null)
{
$this->paginator = $paginator;
$this->window = is_null($window) ? UrlWindow::make($paginator) : $window->get();
}
/**
* Determine if the underlying paginator being presented has pages to show.
*
* @return bool
*/
public function hasPages()
{
return $this->paginator->hasPages();
}
/**
* Convert the URL window into Bootstrap HTML.
*
* @return \Illuminate\Support\HtmlString
*/
public function render()
{
if ($this->hasPages()) {
return new HtmlString(sprintf(
'<ul class="pagination">%s %s %s</ul>',
$this->getPreviousButton(),
$this->getLinks(),
$this->getNextButton()
));
}
return '';
}
/**
* Get HTML wrapper for an available page link.
*
* @param string $url
* @param int $page
* @param string|null $rel
* @return string
*/
protected function getAvailablePageWrapper($url, $page, $rel = null)
{
$rel = is_null($rel) ? '' : ' rel="'.$rel.'"';
return '<li><a href="'.htmlentities($url).'"'.$rel.'>'.$page.'</a></li>';
}
/**
* Get HTML wrapper for disabled text.
*
* @param string $text
* @return string
*/
protected function getDisabledTextWrapper($text)
{
return '<li class="disabled"><span>'.$text.'</span></li>';
}
/**
* Get HTML wrapper for active text.
*
* @param string $text
* @return string
*/
protected function getActivePageWrapper($text)
{
return '<li class="active"><span>'.$text.'</span></li>';
}
/**
* Get a pagination "dot" element.
*
* @return string
*/
protected function getDots()
{
return $this->getDisabledTextWrapper('...');
}
/**
* 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();
}
}

View File

@@ -7,9 +7,9 @@ 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\Presenter;
use Illuminate\Contracts\Pagination\LengthAwarePaginator as LengthAwarePaginatorContract;
class LengthAwarePaginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Jsonable, LengthAwarePaginatorContract
@@ -46,9 +46,9 @@ class LengthAwarePaginator extends AbstractPaginator implements Arrayable, Array
$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->lastPage);
$this->lastPage = max((int) ceil($total / $perPage), 1);
$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);
}
@@ -56,16 +56,81 @@ class LengthAwarePaginator extends AbstractPaginator implements Arrayable, Array
* Get the current page for the request.
*
* @param int $currentPage
* @param int $lastPage
* @param string $pageName
* @return int
*/
protected function setCurrentPage($currentPage, $lastPage)
protected function setCurrentPage($currentPage, $pageName)
{
$currentPage = $currentPage ?: static::resolveCurrentPage();
$currentPage = $currentPage ?: static::resolveCurrentPage($pageName);
return $this->isValidPageNumber($currentPage) ? (int) $currentPage : 1;
}
/**
* Render the paginator using the given view.
*
* @param string|null $view
* @param array $data
* @return \Illuminate\Support\HtmlString
*/
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 \Illuminate\Support\HtmlString
*/
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.
*
@@ -78,26 +143,6 @@ class LengthAwarePaginator extends AbstractPaginator implements Arrayable, Array
}
}
/**
* Determine if there are more items in the data source.
*
* @return bool
*/
public function hasMorePages()
{
return $this->currentPage() < $this->lastPage();
}
/**
* Get the total number of items being paginated.
*
* @return int
*/
public function total()
{
return $this->total;
}
/**
* Get the last page.
*
@@ -108,34 +153,6 @@ class LengthAwarePaginator extends AbstractPaginator implements Arrayable, Array
return $this->lastPage;
}
/**
* Render the paginator using the given presenter.
*
* @param \Illuminate\Contracts\Pagination\Presenter|null $presenter
* @return string
*/
public function links(Presenter $presenter = null)
{
return $this->render($presenter);
}
/**
* Render the paginator using the given presenter.
*
* @param \Illuminate\Contracts\Pagination\Presenter|null $presenter
* @return string
*/
public function render(Presenter $presenter = null)
{
if (is_null($presenter) && static::$presenterResolver) {
$presenter = call_user_func(static::$presenterResolver, $this);
}
$presenter = $presenter ?: new BootstrapThreePresenter($this);
return $presenter->render();
}
/**
* Get the instance as an array.
*
@@ -144,15 +161,18 @@ class LengthAwarePaginator extends AbstractPaginator implements Arrayable, Array
public function toArray()
{
return [
'total' => $this->total(),
'per_page' => $this->perPage(),
'current_page' => $this->currentPage(),
'last_page' => $this->lastPage(),
'current_page' => $this->currentPage(),
'data' => $this->items->toArray(),
'first_page_url' => $this->url(1),
'from' => $this->firstItem(),
'last_page' => $this->lastPage(),
'last_page_url' => $this->url($this->lastPage()),
'next_page_url' => $this->nextPageUrl(),
'path' => $this->path,
'per_page' => $this->perPage(),
'prev_page_url' => $this->previousPageUrl(),
'from' => $this->firstItem(),
'to' => $this->lastItem(),
'data' => $this->items->toArray(),
'to' => $this->lastItem(),
'total' => $this->total(),
];
}

View File

@@ -6,6 +6,22 @@ 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.
*
@@ -13,6 +29,10 @@ class PaginationServiceProvider extends ServiceProvider
*/
public function register()
{
Paginator::viewFactoryResolver(function () {
return $this->app['view'];
});
Paginator::currentPathResolver(function () {
return $this->app['request']->url();
});
@@ -21,7 +41,7 @@ class PaginationServiceProvider extends ServiceProvider
$page = $this->app['request']->input($pageName);
if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
return $page;
return (int) $page;
}
return 1;

View File

@@ -7,9 +7,9 @@ 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\Presenter;
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Jsonable, PaginatorContract
@@ -38,10 +38,9 @@ class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Cou
$this->perPage = $perPage;
$this->currentPage = $this->setCurrentPage($currentPage);
$this->path = $this->path != '/' ? rtrim($this->path, '/') : $this->path;
$this->items = $items instanceof Collection ? $items : Collection::make($items);
$this->path = $this->path !== '/' ? rtrim($this->path, '/') : $this->path;
$this->checkForMorePages();
$this->setItems($items);
}
/**
@@ -58,13 +57,16 @@ class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Cou
}
/**
* Check for more pages. The last item will be sliced off.
* Set the items for the paginator.
*
* @param mixed $items
* @return void
*/
protected function checkForMorePages()
protected function setItems($items)
{
$this->hasMore = count($this->items) > ($this->perPage);
$this->items = $items instanceof Collection ? $items : Collection::make($items);
$this->hasMore = $this->items->count() > $this->perPage;
$this->items = $this->items->slice(0, $this->perPage);
}
@@ -81,6 +83,47 @@ class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Cou
}
}
/**
* 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 $hasMore
* @return $this
*/
public function hasMorePagesWhen($hasMore = true)
{
$this->hasMore = $hasMore;
return $this;
}
/**
* Determine if there are more items in the data source.
*
@@ -91,34 +134,6 @@ class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Cou
return $this->hasMore;
}
/**
* Render the paginator using the given presenter.
*
* @param \Illuminate\Contracts\Pagination\Presenter|null $presenter
* @return string
*/
public function links(Presenter $presenter = null)
{
return $this->render($presenter);
}
/**
* Render the paginator using the given presenter.
*
* @param \Illuminate\Contracts\Pagination\Presenter|null $presenter
* @return string
*/
public function render(Presenter $presenter = null)
{
if (is_null($presenter) && static::$presenterResolver) {
$presenter = call_user_func(static::$presenterResolver, $this);
}
$presenter = $presenter ?: new SimpleBootstrapThreePresenter($this);
return $presenter->render();
}
/**
* Get the instance as an array.
*
@@ -127,10 +142,15 @@ class Paginator extends AbstractPaginator implements Arrayable, ArrayAccess, Cou
public function toArray()
{
return [
'per_page' => $this->perPage(), 'current_page' => $this->currentPage(),
'next_page_url' => $this->nextPageUrl(), 'prev_page_url' => $this->previousPageUrl(),
'from' => $this->firstItem(), 'to' => $this->lastItem(),
'current_page' => $this->currentPage(),
'data' => $this->items->toArray(),
'first_page_url' => $this->url(1),
'from' => $this->firstItem(),
'next_page_url' => $this->nextPageUrl(),
'path' => $this->path,
'per_page' => $this->perPage(),
'prev_page_url' => $this->previousPageUrl(),
'to' => $this->lastItem(),
];
}

View File

@@ -1,48 +0,0 @@
<?php
namespace Illuminate\Pagination;
use Illuminate\Support\HtmlString;
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
class SimpleBootstrapFourPresenter extends BootstrapFourPresenter
{
/**
* Create a simple Bootstrap 4 presenter.
*
* @param \Illuminate\Contracts\Pagination\Paginator $paginator
* @return void
*/
public function __construct(PaginatorContract $paginator)
{
$this->paginator = $paginator;
}
/**
* Determine if the underlying paginator being presented has pages to show.
*
* @return bool
*/
public function hasPages()
{
return $this->paginator->hasPages() && count($this->paginator->items()) > 0;
}
/**
* Convert the URL window into Bootstrap HTML.
*
* @return \Illuminate\Support\HtmlString
*/
public function render()
{
if ($this->hasPages()) {
return new HtmlString(sprintf(
'<ul class="pager">%s %s</ul>',
$this->getPreviousButton(),
$this->getNextButton()
));
}
return '';
}
}

View File

@@ -1,48 +0,0 @@
<?php
namespace Illuminate\Pagination;
use Illuminate\Support\HtmlString;
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
class SimpleBootstrapThreePresenter extends BootstrapThreePresenter
{
/**
* Create a simple Bootstrap 3 presenter.
*
* @param \Illuminate\Contracts\Pagination\Paginator $paginator
* @return void
*/
public function __construct(PaginatorContract $paginator)
{
$this->paginator = $paginator;
}
/**
* Determine if the underlying paginator being presented has pages to show.
*
* @return bool
*/
public function hasPages()
{
return $this->paginator->hasPages() && count($this->paginator->items()) > 0;
}
/**
* Convert the URL window into Bootstrap HTML.
*
* @return \Illuminate\Support\HtmlString
*/
public function render()
{
if ($this->hasPages()) {
return new HtmlString(sprintf(
'<ul class="pager">%s %s</ul>',
$this->getPreviousButton(),
$this->getNextButton()
));
}
return '';
}
}

View File

@@ -76,11 +76,7 @@ class UrlWindow
$window = $onEachSide * 2;
if (! $this->hasPages()) {
return [
'first' => null,
'slider' => null,
'last' => null,
];
return ['first' => null, 'slider' => null, 'last' => null];
}
// If the current page is very close to the beginning of the page range, we will
@@ -112,9 +108,9 @@ class UrlWindow
protected function getSliderTooCloseToBeginning($window)
{
return [
'first' => $this->paginator->getUrlRange(1, $window + 2),
'first' => $this->paginator->getUrlRange(1, $window + 2),
'slider' => null,
'last' => $this->getFinish(),
'last' => $this->getFinish(),
];
}
@@ -132,9 +128,9 @@ class UrlWindow
);
return [
'first' => $this->getStart(),
'first' => $this->getStart(),
'slider' => null,
'last' => $last,
'last' => $last,
];
}

View File

@@ -1,66 +0,0 @@
<?php
namespace Illuminate\Pagination;
trait UrlWindowPresenterTrait
{
/**
* Render the actual link slider.
*
* @return string
*/
protected function getLinks()
{
$html = '';
if (is_array($this->window['first'])) {
$html .= $this->getUrlLinks($this->window['first']);
}
if (is_array($this->window['slider'])) {
$html .= $this->getDots();
$html .= $this->getUrlLinks($this->window['slider']);
}
if (is_array($this->window['last'])) {
$html .= $this->getDots();
$html .= $this->getUrlLinks($this->window['last']);
}
return $html;
}
/**
* Get the links for the URLs in the given array.
*
* @param array $urls
* @return string
*/
protected function getUrlLinks(array $urls)
{
$html = '';
foreach ($urls as $page => $url) {
$html .= $this->getPageLinkWrapper($url, $page);
}
return $html;
}
/**
* Get HTML wrapper for a page link.
*
* @param string $url
* @param int $page
* @param string|null $rel
* @return string
*/
protected function getPageLinkWrapper($url, $page, $rel = null)
{
if ($page == $this->paginator->currentPage()) {
return $this->getActivePageWrapper($page);
}
return $this->getAvailablePageWrapper($url, $page, $rel);
}
}

View File

@@ -2,7 +2,7 @@
"name": "illuminate/pagination",
"description": "The Illuminate Pagination package.",
"license": "MIT",
"homepage": "http://laravel.com",
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
@@ -14,9 +14,9 @@
}
],
"require": {
"php": ">=5.5.9",
"illuminate/contracts": "5.2.*",
"illuminate/support": "5.2.*"
"php": ">=7.0",
"illuminate/contracts": "5.5.*",
"illuminate/support": "5.5.*"
},
"autoload": {
"psr-4": {
@@ -25,8 +25,11 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.2-dev"
"dev-master": "5.5-dev"
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}

View 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">&laquo;</span></li>
@else
<li class="page-item"><a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev">&laquo;</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">&raquo;</a></li>
@else
<li class="page-item disabled"><span class="page-link">&raquo;</span></li>
@endif
</ul>
@endif

View File

@@ -0,0 +1,36 @@
@if ($paginator->hasPages())
<ul class="pagination">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<li class="disabled"><span>&laquo;</span></li>
@else
<li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">&laquo;</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">&raquo;</a></li>
@else
<li class="disabled"><span>&raquo;</span></li>
@endif
</ul>
@endif

View File

@@ -0,0 +1,36 @@
@if ($paginator->hasPages())
<div class="ui pagination menu">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<a class="icon item disabled"> <i class="left chevron icon"></i> </a>
@else
<a class="icon item" href="{{ $paginator->previousPageUrl() }}" rel="prev"> <i class="left chevron icon"></i> </a>
@endif
{{-- Pagination Elements --}}
@foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
@if (is_string($element))
<a class="icon item disabled">{{ $element }}</a>
@endif
{{-- Array Of Links --}}
@if (is_array($element))
@foreach ($element as $page => $url)
@if ($page == $paginator->currentPage())
<a class="item active" href="{{ $url }}">{{ $page }}</a>
@else
<a class="item" href="{{ $url }}">{{ $page }}</a>
@endif
@endforeach
@endif
@endforeach
{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<a class="icon item" href="{{ $paginator->nextPageUrl() }}" rel="next"> <i class="right chevron icon"></i> </a>
@else
<a class="icon item disabled"> <i class="right chevron icon"></i> </a>
@endif
</div>
@endif

View 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

View 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