@@ -32,11 +32,11 @@ class Paginator implements ArrayableInterface, ArrayAccess, Countable, IteratorA
3232 protected $ total ;
3333
3434 /**
35- * Item, array or object indicating if next page is available .
35+ * Indicates if a pagination doing "quick" pagination has more items .
3636 *
37- * @var mixed
37+ * @var bool
3838 */
39- protected $ cursor ;
39+ protected $ hasMore ;
4040
4141 /**
4242 * The amount of items to show per page.
@@ -100,15 +100,11 @@ public function __construct(Factory $factory, array $items, $total, $perPage = n
100100 {
101101 $ this ->factory = $ factory ;
102102
103- // Paginator received only 3 parameters which means that it's being used
104- // in cursor mode. In this mode third argument $total is used as $perPage.
105103 if (is_null ($ perPage ))
106104 {
107- $ this ->items = array_slice ($ items , 0 , $ perPage );
108105 $ this ->perPage = (int ) $ total ;
109-
110- $ cursor = array_slice ($ items , $ this ->perPage , 1 );
111- $ this ->cursor = empty ($ cursor ) ? null : $ cursor [0 ];
106+ $ this ->items = array_slice ($ items , 0 , $ perPage );
107+ $ this ->hasMore = count (array_slice ($ items , $ this ->perPage , 1 )) > 0 ;
112108 }
113109 else
114110 {
@@ -139,12 +135,11 @@ public function setupPaginationContext()
139135 */
140136 protected function calculateCurrentAndLastPages ()
141137 {
142- if (is_null ( $ this ->total ))
138+ if ($ this ->isQuickPaginating ( ))
143139 {
144- $ page = $ this ->factory ->getCurrentPage ();
145- $ this ->currentPage = $ this ->isValidPageNumber ($ page ) ? (int ) $ page : 1 ;
140+ $ this ->currentPage = $ this ->factory ->getCurrentPage ();
146141
147- $ this ->lastPage = is_null ( $ this ->cursor ) ? $ this ->currentPage : $ this ->currentPage + 1 ;
142+ $ this ->lastPage = $ this ->hasMore ? $ this ->currentPage + 1 : $ this ->currentPage ;
148143 }
149144 else
150145 {
@@ -301,6 +296,16 @@ public function addQuery($key, $value)
301296 return $ this ;
302297 }
303298
299+ /**
300+ * Deteremine if the paginator is doing "quick" pagination.
301+ *
302+ * @return bool
303+ */
304+ public function isQuickPaginating ()
305+ {
306+ return is_null ($ this ->total );
307+ }
308+
304309 /**
305310 * Get the current page for the request.
306311 *
@@ -400,16 +405,6 @@ public function getTotal()
400405 return $ this ->total ;
401406 }
402407
403- /**
404- * Get cursor for this paginator.
405- *
406- * @return mixed
407- */
408- public function getCursor ()
409- {
410- return $ this ->cursor ;
411- }
412-
413408 /**
414409 * Set the base URL in use by the paginator.
415410 *
0 commit comments