File tree Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 14
14
use Elastica \Query ;
15
15
use Elastica \SearchableInterface ;
16
16
17
- class ElasticaAdapter implements AdapterInterface
17
+ class ElasticaAdapter implements LazyAdapterInterface
18
18
{
19
19
/**
20
20
* @var Query
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Pagerfanta package.
5
+ *
6
+ * (c) Pablo Díez <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Pagerfanta \Adapter ;
13
+
14
+ /**
15
+ * LazyAdapterInterface that marks adapter lazy.
16
+ *
17
+ * @author Konstantin Myakshin <[email protected] >
18
+ */
19
+ interface LazyAdapterInterface extends AdapterInterface
20
+ {
21
+
22
+ }
Original file line number Diff line number Diff line change 12
12
namespace Pagerfanta ;
13
13
14
14
use Pagerfanta \Adapter \AdapterInterface ;
15
+ use Pagerfanta \Adapter \LazyAdapterInterface ;
15
16
use Pagerfanta \Exception \LogicException ;
16
17
use Pagerfanta \Exception \NotBooleanException ;
17
18
use Pagerfanta \Exception \NotIntegerMaxPerPageException ;
@@ -225,7 +226,9 @@ private function filterCurrentPage($currentPage)
225
226
{
226
227
$ currentPage = $ this ->toInteger ($ currentPage );
227
228
$ this ->checkCurrentPage ($ currentPage );
228
- $ currentPage = $ this ->filterOutOfRangeCurrentPage ($ currentPage );
229
+ if (!$ this ->adapter instanceof LazyAdapterInterface) {
230
+ $ currentPage = $ this ->filterOutOfRangeCurrentPage ($ currentPage );
231
+ }
229
232
230
233
return $ currentPage ;
231
234
}
@@ -316,7 +319,18 @@ private function getCurrentPageResultsFromAdapter()
316
319
$ offset = $ this ->calculateOffsetForCurrentPageResults ();
317
320
$ length = $ this ->getMaxPerPage ();
318
321
319
- return $ this ->adapter ->getSlice ($ offset , $ length );
322
+ $ slice = $ this ->adapter ->getSlice ($ offset , $ length );
323
+
324
+ if ($ this ->adapter instanceof LazyAdapterInterface) {
325
+ $ page = $ this ->filterOutOfRangeCurrentPage ($ this ->getCurrentPage ());
326
+ if ($ page != $ this ->getCurrentPage ()) {
327
+ $ this ->setCurrentPage ($ page );
328
+
329
+ return $ this ->getCurrentPageResultsFromAdapter ();
330
+ }
331
+ }
332
+
333
+ return $ slice ;
320
334
}
321
335
322
336
private function calculateOffsetForCurrentPageResults ()
You can’t perform that action at this time.
0 commit comments