1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Damax\Common\Pagerfanta; |
||
6 | |||
7 | use Pagerfanta\Adapter\AdapterInterface; |
||
8 | use Traversable; |
||
9 | |||
10 | final class CallableDecoratorAdapter implements AdapterInterface |
||
11 | { |
||
12 | private $adapter; |
||
13 | private $callback; |
||
14 | |||
15 | public function __construct(AdapterInterface $adapter, callable $callback) |
||
16 | { |
||
17 | $this->adapter = $adapter; |
||
18 | $this->callback = $callback; |
||
19 | } |
||
20 | |||
21 | public function getNbResults(): int |
||
22 | { |
||
23 | return $this->adapter->getNbResults(); |
||
24 | } |
||
25 | |||
26 | public function getSlice($offset, $length): array |
||
27 | { |
||
28 | $items = $this->adapter->getSlice($offset, $length); |
||
29 | $items = $items instanceof Traversable ? iterator_to_array($items, false) : $items; |
||
30 | |||
31 | return array_values(array_map($this->callback, $items)); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
32 | } |
||
33 | } |
||
34 |