1 | <?php |
||
24 | abstract class CollectionDto implements Dto |
||
25 | { |
||
26 | /** |
||
27 | * @Assert\Valid |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $elements; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $totalItems; |
||
37 | |||
38 | /** |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $currentPage; |
||
42 | |||
43 | /** |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $itemsPerPage; |
||
47 | |||
48 | /** |
||
49 | * @param array $elements |
||
50 | * @param int $totalItems |
||
51 | * @param int $currentPage |
||
52 | * @param int $itemsPerPage |
||
53 | * @param array $filterOptions |
||
54 | */ |
||
55 | public function __construct(array $elements, $totalItems, $currentPage, $itemsPerPage, $filterOptions = array()) |
||
63 | |||
64 | /** |
||
65 | * @param array $data |
||
66 | * @return static |
||
67 | */ |
||
68 | public static function fromData(array $data) |
||
88 | |||
89 | /** |
||
90 | * Load the element in the collection based on the data given |
||
91 | * |
||
92 | * @param array $item |
||
93 | * @return mixed |
||
94 | */ |
||
95 | protected static function createElementFromData(array $item) |
||
101 | |||
102 | /** |
||
103 | * @return int |
||
104 | */ |
||
105 | public function getCurrentPage() |
||
109 | |||
110 | /** |
||
111 | * @return array |
||
112 | */ |
||
113 | public function getElements() |
||
117 | |||
118 | /** |
||
119 | * @return array|null |
||
120 | */ |
||
121 | public function getFilterOption($key) |
||
128 | |||
129 | /** |
||
130 | * @return mixed|null |
||
131 | * @throws LogicException When there is more than 1 element present. |
||
132 | */ |
||
133 | public function getOnlyElement() |
||
145 | |||
146 | /** |
||
147 | * @return int |
||
148 | */ |
||
149 | public function getItemsPerPage() |
||
153 | |||
154 | /** |
||
155 | * @return int |
||
156 | */ |
||
157 | public function getTotalItems() |
||
161 | } |
||
162 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: