|
| 1 | +# Migrating from Version 2 to Version 3 |
| 2 | + |
| 3 | +Version 3 of Laminas Paginator contains several backward incompatible changes. |
| 4 | + |
| 5 | +## New Features |
| 6 | + |
| 7 | +### Laminas Service Manager v4 Support |
| 8 | + |
| 9 | +`laminas-paginator` new requires `laminas-servicemanager` version 4, therefore allowing `psr/container` 2.0 installation. |
| 10 | + |
| 11 | +### Re-worked, Optional Caching with `psr/cache` |
| 12 | + |
| 13 | +With the [removal of caching](#caching) from the paginator itself, it is now possible to decorate adapters as needed with the `CachingAdapter`: |
| 14 | + |
| 15 | +```php |
| 16 | +use Laminas\Paginator\Adapter\ArrayAdapter; |
| 17 | +use Laminas\Paginator\Adapter\CachingAdapter; |
| 18 | +use Laminas\Paginator\Paginator; |
| 19 | + |
| 20 | +$paginator = new Paginator( |
| 21 | + new CachingAdapter( |
| 22 | + new ArrayAdapter($someData), |
| 23 | + 'my-unique-prefix', |
| 24 | + $someCacheItemPoolInterface, |
| 25 | + ), |
| 26 | +); |
| 27 | +``` |
| 28 | + |
| 29 | +[Further Documentation](../caching.md) |
| 30 | + |
| 31 | +## Bug Fixes & General Improvements |
| 32 | + |
| 33 | +- Native parameter, property and return types have been added throughout the code base |
| 34 | +- It is now possible to paginate associative arrays, or any type of iterable with string keys. Type inference for keys and values is retained. |
| 35 | +- Type inference has been drastically improved for a more convenient developer experience. We strongly suggest usage of Psalm or PHPStan to benefit from these improvements. |
| 36 | + |
| 37 | +## Feature Removal |
| 38 | + |
| 39 | +### Caching |
| 40 | + |
| 41 | +The caching features of the main Paginator class have been removed. |
| 42 | +This means the following constants and methods of `Laminas\Paginator\Paginator` no longer exist: |
| 43 | + |
| 44 | +- `CACHE_TAG_PREFIX` constant |
| 45 | +- `setCache()` |
| 46 | +- `setCacheEnabled()` |
| 47 | +- `clearPageItemCache()` |
| 48 | +- `getPageItemCache()` |
| 49 | +- `cacheEnabled()` |
| 50 | + |
| 51 | +### `laminas-view` integration |
| 52 | + |
| 53 | +`Laminas\Paginator\Paginator` was unnecessarily, tightly coupled to Laminas View. |
| 54 | +Because paginator is conceptually independent of a specific templating implementation, expect stand-alone integrations in the future. |
| 55 | +The removal of Laminas view integration resulted in the following changes to `Laminas\Paginator\Paginator`: |
| 56 | + |
| 57 | +- `Laminas\Paginator\Paginator` no longer implements the `Stringable` interface |
| 58 | +- The following methods have been removed: |
| 59 | + - `__toString()` |
| 60 | + - `getView()` |
| 61 | + - `setView()` |
| 62 | + - `render()` |
| 63 | + |
| 64 | +### Removal of Un-documented Filtering Feature |
| 65 | + |
| 66 | +Previously, paginator allowed users to provide a `Laminas\Filter\FilterInterface` that would be used to filter/mutate the result set returned by adapters. |
| 67 | +This feature has been removed. |
| 68 | +It is unlikely the feature was widely used, and it had questionable merit because it would break the guarantees that a page of 10 items, would indeed contain 10 items. |
| 69 | + |
| 70 | +The following methods have been removed from `Laminas\Paginator\Paginator`: |
| 71 | + |
| 72 | +- `getFilter()` |
| 73 | +- `setFilter()` |
| 74 | + |
| 75 | +### Removal of the `ScrollingStylePluginManager` |
| 76 | + |
| 77 | +Generally speaking, scrolling styles are relatively simple computations. |
| 78 | +They can easily be "newed" when required. |
| 79 | +You can still refer to them by 'name', for example _'Sliding'_. |
| 80 | + |
| 81 | +Along with the plugin manger, a number of static methods associated with scrolling styles were removed from `Laminas\Paginator\Paginator`: |
| 82 | + |
| 83 | +- `getDefaultScrollingStyle()` |
| 84 | +- `setDefaultScrollingStyle()` |
| 85 | +- `getDefaultItemCountPerPage()` |
| 86 | +- `setDefaultItemCountPerPage()` |
| 87 | +- `setScrollingStylePluginManager()` |
| 88 | +- `getScrollingStylePluginManager()` |
| 89 | + |
| 90 | +### Json encoding of Paginator Result Sets |
| 91 | + |
| 92 | +The method `Laminas\Paginator\Paginator::toJson()` has been removed. |
| 93 | +It is not a paginators concern to encode the paged items to any format. |
| 94 | +If you relied on this functionality, it can be reproduced by encoding the current items yourself with `json_encode`, for example: |
| 95 | + |
| 96 | +```php |
| 97 | +$json = json_encode($paginator->getCurrentItems()); |
| 98 | +``` |
| 99 | + |
| 100 | +### Removal of "Global Config" via Static Properties |
| 101 | + |
| 102 | +The method `Laminas\Paginator\Paginator::setGlobalConfig()` has been removed. |
| 103 | +To create pagers with consistent and centralised configuration defaults, use the [newly introduced `PaginatorFactory`](../configuration.md#the-paginator-factory-service). |
| 104 | + |
| 105 | +### Removal of Unused Exception Types |
| 106 | + |
| 107 | +The following exceptions no longer exist: |
| 108 | + |
| 109 | +- `Laminas\Paginator\Adapter\Exception\RuntimeException` |
| 110 | +- `Laminas\Paginator\Adapter\Exception\UnexpectedValueException` |
| 111 | +- `Laminas\Paginator\Exception\UnexpectedValueException` |
| 112 | + |
| 113 | +### Laminas MVC Module Manager Support |
| 114 | + |
| 115 | +The `Module` class has been removed. |
| 116 | +It is possible to use the shipped `ConfigProvider` to ensure that the library is correctly configured for use with the application Service Manager. |
| 117 | + |
| 118 | +### Removal of the `Factory` class |
| 119 | + |
| 120 | +The class `Laminas\Paginator\Factory` has been removed. |
| 121 | +Its conceptual functionality is replaced with the `Laminas\Paginator\PaginatorFactory` class which is [documented in detail here](../configuration.md#the-paginator-factory-service). |
0 commit comments