Download the PHP package lampager/lampager without Composer
On this page you can find all versions of the php package lampager/lampager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lampager/lampager
More information about lampager/lampager
Files in lampager/lampager
Package lampager
Short Description Rapid pagination without using OFFSET
License MIT
Informations about the package lampager
Lampager Core
The core package of Lampager
Requirements
- PHP:
^5.6 || ^7.0 || ^8.0
Installing
Usage
Basically you don't need to directly use this package. For example, if you use Laravel, install lampager/lampager-laravel.
However, you can manually use like this:
It will run the optimized query.
And you'll get
Question: How about Tuple Comparison?
With this feature, SQL statements should be simpler. However, according to SQL Feature Comparison, some RDBMS, such as SQLServer, do not support this syntax. Therefore, Lampager continuously uses redundant statements.
It is also useful for Doctrine 2 since its DQL lexer does not support the syntax and triggers parse errors.
Classes
Name | Type | Parent Class Implemented Interface |
Description |
---|---|---|---|
Lampager\Paginator |
Class | Fluent factory for building Query | |
Lampager\AbstractProcessor |
Abstract Class | Receive fetched records and format them | |
Lampager\PaginationResult |
Class | Processor wraps result with this by default | |
Lampager\ArrayProcessor |
Class | Lampager\AbstractProcessor |
Simple Processor implementation for pure PDO |
Lampager\ArrayCursor |
Class | Lampager\Contracts\Cursor |
Simple Cursor implementation for pure PDO Arrays are automatically wrapped with this |
Lampager\Query |
Class | SQL configuration container generated by Paginator | |
Lampager\Query\... | Class | Child components of Query | |
Lampager\Contracts\Cursor |
Interface | Indicates parameters for retrieving previous/next records | |
Lampager\Contracts\Formatter |
Interface | Formatter interface pluggable to Processor | |
Lampager\Concerns\HasProcessor |
Trait | Helper for extended Paginator providing convenient accessibility to Processor |
API
Paginator::orderBy()
Paginator::orderByDesc()
Paginator::clearOrderBy()
Add or clear cursor parameter name for ORDER BY
statement.
At least one parameter required.
IMPORTANT: The last key MUST be the primary key.
e.g. $paginator->orderBy('updated_at')->orderBy('id')
Arguments
(string)
$column
Table column name.(string)
$direction
"asc"
or"desc"
.
Paginator::limit()
Define the pagination limit.
Arguments
(int)
$limit
Positive integer.
Paginator::forward()
Paginator::backward()
Define the pagination direction.
Forward (Default)
Backward
IMPORTANT: You need previous cursor to retrieve more results.
Paginator::inclusive()
Paginator::exclusive()
Change the behavior of handling cursor.
Inclusive (Default)
Current cursor will be included in the current page.
Exclusive
Current cursor will not be included in the current page.
Paginator::unseekable()
Paginator::seekable()
Define that the pagination result should contain both of the next cursor and the previous cursor.
unseekable()
always requires one simpleSELECT
query. (Default)seekable()
may requireSELECT ... UNION ALL SELECT ...
query when the cursor parameters are not empty.
Unseekable (Default)
Seekable
Always when the current cursor parameters are empty
Paginator::fromArray()
Define options from an associative array.
Arguments
(array)
$options
Associative array that contains the following keys.(int)
limit(bool)
backward / forward(bool)
exclusive / inclusive(bool)
seekable / unseekable(string[][])
$orders
e.g.
Paginator::configure()
Generate Query corresponding to the current cursor.
Arguments
(mixed)
$cursor
An associative array that contains$column => $value
or an object that implements\Lampager\Contracts\Cursor
. It must be all-or-nothing.- For the initial page, omit this parameter or pass an empty array.
- For subsequent pages, pass all parameters. Partial parameters are not allowed.
AbstractProcessor::process()
Receive a pair of Query and fetched rows to analyze and format them.
Arguments
(Query)
$query(mixed)
$rows
Fetched records from database. Typically it should be an array or a Traversable.
Return Value
(mixed)
By default, an instance of \Lampager\PaginationResult
is returned. All fields are public.
e.g.
Note that
hasPrevious
/hasNext
will befalse
when there are no more results for the corresponding direction.- Either
hasPrevious
/hasNext
will benull
when$cursor
is empty orseekable()
is not be enabled.
PaginationResult::getIterator()
It can be directly traversed using foreach
thanks to the interface \IteratorAggregate
.
Return Value
(mixed)
ArrayIterator
instance that wraps records
.
AbstractProcessor::useFormatter()
AbstractProcessor::restoreFormatter()
Override or restore the formatter for the pagination result.
Callable Formatter Example
Class Formatter Example
AbstractProcessor::setDefaultFormatter()
AbstractProcessor::restoreDefaultFormatter()
Globally override or restore the formatter.