1
|
|
|
<?php namespace Limoncello\Flute\Api; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015-2017 [email protected] |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use Limoncello\Flute\Contracts\Api\RelationshipPaginationStrategyInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @package Limoncello\Flute |
23
|
|
|
*/ |
24
|
|
|
class BasicRelationshipPaginationStrategy implements RelationshipPaginationStrategyInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var int |
28
|
|
|
*/ |
29
|
|
|
private $defaultPageSize; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param int $defaultPageSize |
33
|
|
|
*/ |
34
|
63 |
|
public function __construct(int $defaultPageSize) |
35
|
|
|
{ |
36
|
63 |
|
assert($defaultPageSize > 0); |
37
|
|
|
|
38
|
63 |
|
$this->defaultPageSize = $defaultPageSize; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritdoc |
43
|
|
|
*/ |
44
|
8 |
|
public function getParameters(string $rootClass, string $class, string $path, string $relationshipName): array |
45
|
|
|
{ |
46
|
|
|
// input parameters are ignored (same paging params for all) |
47
|
|
|
// feel free to change it in child classes |
48
|
8 |
|
assert($rootClass || $class || $path || $relationshipName); |
49
|
|
|
|
50
|
8 |
|
$offset = 0; |
51
|
|
|
|
52
|
8 |
|
return [$offset, $this->getDefaultPageSize()]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return int |
57
|
|
|
*/ |
58
|
8 |
|
public function getDefaultPageSize(): int |
59
|
|
|
{ |
60
|
8 |
|
return $this->defaultPageSize; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|