1 | <?php |
||
12 | class ApiPaginationComponent extends Component |
||
13 | { |
||
14 | /** |
||
15 | * Default config. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $_defaultConfig = [ |
||
20 | 'key' => 'pagination', |
||
21 | 'aliases' => [], |
||
22 | 'visible' => [] |
||
23 | ]; |
||
24 | |||
25 | /** |
||
26 | * Holds the paging information array from the request. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $pagingInfo = []; |
||
31 | |||
32 | /** |
||
33 | * Injects the pagination info into the response if the current request is a |
||
34 | * JSON or XML request with pagination. |
||
35 | * |
||
36 | * @param \Cake\Event\Event $event The Controller.beforeRender event. |
||
37 | * @return void |
||
38 | */ |
||
39 | 18 | public function beforeRender(Event $event) |
|
40 | { |
||
41 | 18 | if (!$this->isPaginatedApiRequest()) { |
|
42 | 3 | return; |
|
43 | } |
||
44 | |||
45 | 15 | $subject = $event->getSubject(); |
|
46 | 15 | $this->pagingInfo = $this->request->getParam('paging')[$subject->getName()]; |
|
|
|||
47 | 15 | $config = $this->getConfig(); |
|
48 | |||
49 | 15 | if (!empty($config['aliases'])) { |
|
50 | 6 | $this->setAliases(); |
|
51 | 6 | } |
|
52 | |||
53 | 15 | if (!empty($config['visible'])) { |
|
54 | 6 | $this->setVisibility(); |
|
55 | 6 | } |
|
56 | |||
57 | 15 | $subject->set($config['key'], $this->pagingInfo); |
|
58 | 15 | $subject->viewVars['_serialize'][] = $config['key']; |
|
59 | 15 | } |
|
60 | |||
61 | /** |
||
62 | * Aliases the default pagination keys to the new keys that the user defines |
||
63 | * in the config. |
||
64 | * |
||
65 | * @return void |
||
66 | */ |
||
67 | 6 | protected function setAliases() |
|
74 | |||
75 | /** |
||
76 | * Removes any pagination keys that haven't been defined as visible in the |
||
77 | * config. |
||
78 | * |
||
79 | * @return void |
||
80 | */ |
||
81 | 6 | protected function setVisibility() |
|
90 | |||
91 | /** |
||
92 | * Checks whether the current request is a JSON or XML request with |
||
93 | * pagination. |
||
94 | * |
||
95 | * @return bool True if JSON or XML with paging, otherwise false. |
||
96 | */ |
||
97 | 18 | protected function isPaginatedApiRequest() |
|
107 | } |
||
108 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.