1 | <?php |
||
17 | class Processor extends AbstractProcessor |
||
18 | { |
||
19 | use Macroable; |
||
20 | |||
21 | /** |
||
22 | * @var mixed |
||
23 | */ |
||
24 | protected $builder; |
||
25 | |||
26 | /** |
||
27 | * Get result. |
||
28 | * |
||
29 | * @param Query $query |
||
30 | * @param Collection|Model[]|object[] $rows |
||
31 | * @return mixed |
||
32 | */ |
||
33 | 2 | public function process(Query $query, $rows) |
|
38 | |||
39 | /** |
||
40 | * Return comparable value from a row. |
||
41 | * |
||
42 | * @param mixed $row |
||
43 | * @param string $column |
||
44 | * @return int|string |
||
45 | */ |
||
46 | protected function field($row, $column) |
||
55 | |||
56 | /** |
||
57 | * Extract pivot from a row. |
||
58 | * |
||
59 | * @param mixed $row |
||
60 | * @param string $column |
||
61 | * @param string $accessor |
||
62 | * @throws \Exception |
||
63 | * @return int|string |
||
64 | */ |
||
65 | protected function pivotField($row, $column, $accessor) |
||
73 | |||
74 | /** |
||
75 | * Extract pivot accessor from a relation. |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | protected function pivotAccessor() |
||
83 | |||
84 | /** |
||
85 | * Return the n-th element of collection. |
||
86 | * Must return null if not exists. |
||
87 | * |
||
88 | * @param Collection|Model[]|object[] $rows |
||
89 | * @param int $offset |
||
90 | * @return Model|object |
||
91 | */ |
||
92 | 2 | protected function offset($rows, $offset) |
|
96 | |||
97 | /** |
||
98 | * Slice rows, like PHP function array_slice(). |
||
99 | * |
||
100 | * @param Collection|Model[]|object[] $rows |
||
101 | * @param int $offset |
||
102 | * @param null|int $length |
||
103 | * @return Collection|Model[]|object[] |
||
104 | */ |
||
105 | protected function slice($rows, $offset, $length = null) |
||
109 | |||
110 | /** |
||
111 | * Count rows, like PHP function count(). |
||
112 | * |
||
113 | * @param Collection|Model[]|object[] $rows |
||
114 | * @return int |
||
115 | */ |
||
116 | 2 | protected function count($rows) |
|
120 | |||
121 | /** |
||
122 | * Reverse rows, like PHP function array_reverse(). |
||
123 | * |
||
124 | * @param Collection|Model[]|object[] $rows |
||
125 | * @return Collection|Model[]|object[] |
||
126 | */ |
||
127 | protected function reverse($rows) |
||
131 | |||
132 | /** |
||
133 | * Format result. |
||
134 | * |
||
135 | * @param Collection|Model[]|object[] $rows |
||
136 | * @param array $meta |
||
137 | * @param Query $query |
||
138 | * @return PaginationResult |
||
139 | */ |
||
140 | protected function defaultFormat($rows, array $meta, Query $query) |
||
144 | |||
145 | /** |
||
146 | * Drop table prefix on column name. |
||
147 | * |
||
148 | * @param string $column |
||
149 | * @return string |
||
150 | */ |
||
151 | protected static function dropTablePrefix(string $column) |
||
157 | } |
||
158 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: