Skip to content

Commit aadcf2d

Browse files
authored
Merge pull request #89 from gsteel/v3/docs
Update documentation for v3
2 parents e6c40f6 + 17830db commit aadcf2d

File tree

7 files changed

+371
-205
lines changed

7 files changed

+371
-205
lines changed

docs/book/v3/advanced.md

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
laminas-paginator ships with a plugin manager for adapters, `Laminas\Paginator\AdapterPluginManager`.
66
The plugin manager can be used to retrieve adapters.
7-
Since most adapters require constructor arguments, they may be passed as the second argument to the `get()` method in the same order they appear in the constructor.
7+
Since most adapters require constructor arguments, they may be passed as the second argument to the `build()` method in the same order they appear in the constructor.
88

99
### Examples
1010

@@ -15,42 +15,37 @@ use Laminas\Paginator\AdapterPluginManager;
1515
$pluginManager = new AdapterPluginManager();
1616

1717
// Get an array adapter for an array of items
18-
$arrayAdapter = $pluginManager->get(Adapter\ArrayAdapter::class, [$arrayOfItems]);
18+
$arrayAdapter = $pluginManager->build(Adapter\ArrayAdapter::class, [$arrayOfItems]);
1919

2020
// Get an Iterator adapter based on an iterator:
21-
$iteratorAdapter = $pluginManager->get(Adapter\Iterator::class, [$iterator]);
21+
$iteratorAdapter = $pluginManager->build(Adapter\Iterator::class, [$iterator]);
2222
```
2323

2424
## Custom data source adapters
2525

26-
At some point you may run across a data type that is not covered by the packaged
27-
adapters. In this case, you will need to write your own.
26+
At some point you may run across a data type that is not covered by the packaged adapters.
27+
In this case, you will need to write your own.
2828

29-
To do so, you must implement `Laminas\Paginator\Adapter\AdapterInterface`. There
30-
are two methods required to do this:
29+
To do so, you must implement `Laminas\Paginator\Adapter\AdapterInterface`.
30+
There are two methods required to do this:
3131

32-
- `count() : int`
33-
- `getItems(int $offset, int $itemCountPerPage) | array`
32+
- `count(): int`
33+
- `getItems(int $offset, int $itemCountPerPage): iterable`
3434

35-
Additionally, you'll typically implement a constructor that takes your data
36-
source as a parameter.
35+
Additionally, you'll typically implement a constructor that takes your data source as a parameter.
3736

38-
If you've ever used the SPL interface [Countable](http://php.net/Countable),
39-
you're familiar with `count()`. As used with laminas-paginator, this is the total
40-
number of items in the data collection; `Laminas\Paginator\Paginator::countAllItems`
41-
proxies to this method.
37+
If you've ever used the SPL interface [Countable](http://php.net/Countable), you're familiar with `count()`.
38+
As used with `laminas-paginator`, this is the total number of items in the data collection; `Laminas\Paginator\Paginator::countAllItems` proxies to this method.
4239

43-
When retrieving items for the current page, `Laminas\Paginator\Paginator` calls on
44-
your adapter's `getItems()` method, providing it with an offset and the number
45-
of items to display per page; your job is to return the appropriate slice of
46-
data. For an array, that would be:
40+
When retrieving items for the current page, `Laminas\Paginator\Paginator` calls on your adapter's `getItems()` method, providing it with an offset and the number of items to display per page;
41+
your job is to return the appropriate slice of data.
42+
For an array, that would be:
4743

4844
```php
4945
return array_slice($this->array, $offset, $itemCountPerPage);
5046
```
5147

52-
Take a look at the packaged adapters for ideas of how you might go about
53-
implementing your own.
48+
Take a look at the packaged adapters for ideas of how you might go about implementing your own.
5449

5550
### Registering Your Adapter with the Plugin Manager
5651

@@ -85,47 +80,8 @@ class SomeServiceFactory
8580
public function __invoke(ContainerInterface $container)
8681
{
8782
$paginators = $container->get(AdapterPluginManager::class);
88-
$paginator = new Paginator($paginators->get(YourCustomPaginatorAdapter::class));
83+
$paginator = new Paginator($paginators->build(YourCustomPaginatorAdapter::class, $someOptions));
8984
// ...
9085
}
9186
}
9287
```
93-
94-
## Custom scrolling styles
95-
96-
Creating your own scrolling style requires that you implement
97-
`Laminas\Paginator\ScrollingStyle\ScrollingStyleInterface`, which defines a single
98-
method:
99-
100-
```php
101-
getPages(Paginator $paginator, int $pageRange = null) : array
102-
```
103-
104-
This method should calculate a lower and upper bound for page numbers within the
105-
range of so-called "local" pages (that is, pages that are nearby the current
106-
page).
107-
108-
Unless it extends another scrolling style (see
109-
`Laminas\Paginator\ScrollingStyle\Elastic` for an example), your custom scrolling
110-
style will inevitably end with something similar to the following line of code:
111-
112-
```php
113-
return $paginator->getPagesInRange($lowerBound, $upperBound);
114-
```
115-
116-
There's nothing special about this call; it's merely a convenience method to
117-
check the validity of the lower and upper bound and return an array with the range
118-
to the paginator.
119-
120-
When you're ready to use your new scrolling style, you'll need to notif
121-
`Laminas\Paginator\Paginator`:
122-
123-
```php
124-
use My\Paginator\ScrollingStyle;
125-
use Laminas\Paginator\Paginator;
126-
use Laminas\ServiceManager\Factory\InvokableFactory;
127-
128-
$manager = Paginator::getScrollingStyleManager();
129-
$manager->setAlias('my-style', ScrollingStyle::class);
130-
$manager->setFactory(ScrollingStyle::class, InvokableFactory::class);
131-
```

docs/book/v3/application-integration/stand-alone.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
# Stand-Alone
22

3-
The paginator can also be used stand-alone, outside of a Mezzio or laminas-mvc
4-
application.
3+
The paginator can be used stand-alone, outside a Mezzio or laminas-mvc application.
54

65
The example uses the following directory structure:
76

87
```treeview
98
example-app/
109
|-- public/
1110
| `-- index.php
12-
|-- templates/
13-
| `-- pagination-control.phtml
1411
`-- vendor
1512
`-- …
1613
```

docs/book/v3/configuration.md

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,60 @@
11
# Configuration
22

3-
`Laminas\Paginator` has several configuration methods that can be called:
3+
`Laminas\Paginator` is designed to work with `laminas-servicemanager` as its dependency injection container.
44

5-
Method signature | Description
6-
------------------------------------------------------------ | -----------
7-
`setCurrentPageNumber(int $page) : void` | Sets the current page number (default 1).
8-
`setItemCountPerPage(int $count) : void` | Sets the maximum number of items to display on a page (default 10).
9-
`setPageRange(int $range) : void` | Sets the number of items to display in the pagination control (default 10). Note: Most of the time this number will be adhered to exactly, but scrolling styles do have the option of only using it as a guideline or starting value (e.g., Elastic).
5+
It is perfectly possible to use Paginator without using Laminas Service Manager as the DIC in your project, but some convenience will be sacrificed.
6+
7+
## Configuring Pagination Defaults
8+
9+
The following configuration would be returned as part of the `config` service returned from the DI container, so it would be inserted into a PHP file that is autoloaded during bootstrap, or in a `ConfigProvider` perhaps:
10+
11+
```php
12+
return [
13+
'paginator' => [
14+
'itemCountPerPage' => 10,
15+
'pageRange' => 10,
16+
'scrollingStyle' => 'Sliding',
17+
],
18+
];
19+
```
20+
21+
The above configures the default page size to 10, the default page range to 10 and uses the `Sliding` scrolling style by default.
22+
23+
## The Paginator Factory Service
24+
25+
In order for these defaults to apply to newly created paginators, you must use the `PaginatorFactory` service to delegate construction of your paginators:
26+
27+
### Create a Paginator by Providing a Concrete Adapter
28+
29+
```php
30+
use Laminas\Paginator\Adapter\ArrayAdapter;
31+
use Laminas\Paginator\PaginatorFactory;
32+
33+
$factory = $container->get(PaginatorFactory::class);
34+
$paginator = $factory->withAdapter(new ArrayAdapter([1, 2, 3]));
35+
// The paginator above will now be configured with the defaults you have specified.
36+
```
37+
38+
By using the `PaginatorFactory`, you can ensure consistent configuration of paginators across your application with a single place where these defaults can be changed, instead of hard-coding preferences into every call to `new Paginator(...)`.
39+
40+
The factory has 2 more methods for building paginators:
41+
42+
### Create a Paginator by Providing Configuration for an Adapter
43+
44+
```php
45+
use Laminas\Paginator\Adapter\ArrayAdapter;
46+
use Laminas\Paginator\PaginatorFactory;
47+
48+
$factory = $container->get(PaginatorFactory::class);
49+
$paginator = $factory->buildAdapter(ArrayAdapter::class, ['some', 'items', 'to', 'paginate']);
50+
```
51+
52+
### Create a Paginator with an Iterable
53+
54+
```php
55+
use Laminas\Paginator\Adapter\ArrayAdapter;
56+
use Laminas\Paginator\PaginatorFactory;
57+
58+
$factory = $container->get(PaginatorFactory::class);
59+
$paginator = $factory->withItems(['some', 'items', 'to', 'paginate']);
60+
```
-4.3 KB
Binary file not shown.

docs/book/v3/intro.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ The primary design goals of laminas-paginator are as follows:
77

88
- Paginate arbitrary data, not just relational databases.
99
- Fetch only the results that need to be displayed.
10-
- Do not force users to adhere to only one way of displaying data or rendering
11-
pagination controls.
12-
- Loosely couple to other Laminas components so that users who wish to
13-
use it independently of laminas-view, laminas-cache, etc. can do so.
10+
- Do not force users to adhere to only one way of displaying data or rendering pagination controls.
11+
- Remain uncoupled from framework dependencies

0 commit comments

Comments
 (0)