Paginator.php 0000666 00000010443 13436754557 0007232 0 ustar 00 $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 = $this->items->count() > $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 $hasMore * @return $this */ public function hasMorePagesWhen($hasMore = true) { $this->hasMore = $hasMore; 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(), '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(), ]; } /** * 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); } } LengthAwarePaginator.php 0000666 00000011762 13436754557 0011361 0 ustar 00 $value) { $this->{$key} = $value; } $this->total = $total; $this->perPage = $perPage; $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); } /** * 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|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. * * @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(), '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(), '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); } } resources/views/bootstrap-4.blade.php 0000666 00000003605 13436754557 0013703 0 ustar 00 @if ($paginator->hasPages())
@endif resources/views/simple-default.blade.php 0000666 00000001312 13436754557 0014431 0 ustar 00 @if ($paginator->hasPages()) @endif resources/views/simple-bootstrap-4.blade.php 0000666 00000001702 13436754557 0015166 0 ustar 00 @if ($paginator->hasPages()) @endif resources/views/default.blade.php 0000666 00000003251 13436754557 0013146 0 ustar 00 @if ($paginator->hasPages()) @endif resources/views/semantic-ui.blade.php 0000666 00000003222 13436754557 0013736 0 ustar 00 @if ($paginator->hasPages()) @endif AbstractPaginator.php 0000666 00000031057 13436754557 0010722 0 ustar 00 = 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 : ''; } /** * Load a set of relationships onto the mixed relationship collection. * * @param string $relation * @param array $relations * @return $this */ public function loadMorph($relation, $relations) { $this->getCollection()->loadMorph($relation, $relations); return $this; } /** * 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; } /** * Indicate that Bootstrap 3 styling should be used for generated links. * * @return void */ public static function useBootstrapThree() { static::defaultView('pagination::default'); static::defaultSimpleView('pagination::simple-default'); } /** * Get an iterator for the items. * * @return \ArrayIterator */ public function getIterator() { return $this->items->getIterator(); } /** * Determine if the list of items is empty. * * @return bool */ public function isEmpty() { 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. * * @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(); } } composer.json 0000666 00000001477 13436754557 0007326 0 ustar 00 { "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": "^7.1.3", "illuminate/contracts": "5.6.*", "illuminate/support": "5.6.*" }, "autoload": { "psr-4": { "Illuminate\\Pagination\\": "" } }, "extra": { "branch-alias": { "dev-master": "5.6-dev" } }, "config": { "sort-packages": true }, "minimum-stability": "dev" } UrlWindow.php 0000666 00000013013 13436754557 0007234 0 ustar 00 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(); } } PaginationServiceProvider.php 0000666 00000002277 13436754557 0012441 0 ustar 00 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 (int) $page; } return 1; }); } }