1 | <?php |
||
32 | class Log implements \ArrayAccess, \Countable, \Iterator |
||
33 | { |
||
34 | /** |
||
35 | * @var \GitElephant\Repository |
||
36 | */ |
||
37 | private $repository; |
||
38 | |||
39 | /** |
||
40 | * the commits related to this log |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | private $commits = []; |
||
45 | |||
46 | /** |
||
47 | * the cursor position |
||
48 | * |
||
49 | * @var int |
||
50 | */ |
||
51 | private $position = 0; |
||
52 | |||
53 | /** |
||
54 | * static method to generate standalone log |
||
55 | * |
||
56 | * @param \GitElephant\Repository $repository repo |
||
57 | * @param array $outputLines output lines from command.log |
||
58 | * |
||
59 | * @return \GitElephant\Objects\Log |
||
60 | */ |
||
61 | 1 | public static function createFromOutputLines(Repository $repository, array $outputLines) |
|
68 | |||
69 | /** |
||
70 | * Class constructor |
||
71 | * |
||
72 | * @param Repository $repository |
||
73 | * @param string $ref |
||
74 | * @param string|null $path |
||
75 | * @param int $limit |
||
76 | * @param int|null $offset |
||
77 | * @param bool $firstParent |
||
78 | */ |
||
79 | 19 | public function __construct( |
|
91 | |||
92 | /** |
||
93 | * get the commit properties from command |
||
94 | * |
||
95 | * @param string $ref treeish reference |
||
96 | * @param string $path path |
||
97 | * @param int $limit limit |
||
98 | * @param string $offset offset |
||
99 | * @param boolean $firstParent first parent |
||
100 | * |
||
101 | * @throws \RuntimeException |
||
102 | * @throws \Symfony\Component\Process\Exception\LogicException |
||
103 | * @throws \Symfony\Component\Process\Exception\InvalidArgumentException |
||
104 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
105 | * @see ShowCommand::commitInfo |
||
106 | */ |
||
107 | 19 | private function createFromCommand($ref, $path = null, int $limit, int $offset = null, bool $firstParent = false) |
|
119 | |||
120 | 19 | private function parseOutputLines(array $outputLines) |
|
129 | |||
130 | /** |
||
131 | * Get array representation |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | 1 | public function toArray() |
|
139 | |||
140 | /** |
||
141 | * Get the first commit |
||
142 | * |
||
143 | * @return Commit|null |
||
144 | */ |
||
145 | public function first() |
||
149 | |||
150 | /** |
||
151 | * Get the last commit |
||
152 | * |
||
153 | * @return Commit|null |
||
154 | */ |
||
155 | 3 | public function last() |
|
159 | |||
160 | /** |
||
161 | * Get commit at index |
||
162 | * |
||
163 | * @param int $index the commit index |
||
164 | * |
||
165 | * @return Commit|null |
||
166 | */ |
||
167 | 1 | public function index(int $index) |
|
171 | |||
172 | /** |
||
173 | * ArrayAccess interface |
||
174 | * |
||
175 | * @param int $offset offset |
||
176 | * |
||
177 | * @return bool |
||
178 | */ |
||
179 | public function offsetExists($offset) |
||
183 | |||
184 | /** |
||
185 | * ArrayAccess interface |
||
186 | * |
||
187 | * @param int $offset offset |
||
188 | * |
||
189 | * @return Commit|null |
||
190 | */ |
||
191 | 14 | public function offsetGet($offset) |
|
195 | |||
196 | /** |
||
197 | * ArrayAccess interface |
||
198 | * |
||
199 | * @param int $offset offset |
||
200 | * @param mixed $value value |
||
201 | * |
||
202 | * @throws \RuntimeException |
||
203 | */ |
||
204 | public function offsetSet($offset, $value) |
||
208 | |||
209 | /** |
||
210 | * ArrayAccess interface |
||
211 | * |
||
212 | * @param int $offset offset |
||
213 | * |
||
214 | * @throws \RuntimeException |
||
215 | */ |
||
216 | public function offsetUnset($offset) |
||
220 | |||
221 | /** |
||
222 | * Countable interface |
||
223 | * |
||
224 | * @return int |
||
225 | */ |
||
226 | 8 | public function count() |
|
230 | |||
231 | /** |
||
232 | * Iterator interface |
||
233 | * |
||
234 | * @return Commit|null |
||
235 | */ |
||
236 | public function current() |
||
240 | |||
241 | /** |
||
242 | * Iterator interface |
||
243 | */ |
||
244 | public function next() |
||
248 | |||
249 | /** |
||
250 | * Iterator interface |
||
251 | * |
||
252 | * @return int |
||
253 | */ |
||
254 | public function key() |
||
258 | |||
259 | /** |
||
260 | * Iterator interface |
||
261 | * |
||
262 | * @return bool |
||
263 | */ |
||
264 | public function valid() |
||
268 | |||
269 | /** |
||
270 | * Iterator interface |
||
271 | */ |
||
272 | public function rewind() |
||
276 | |||
277 | /** |
||
278 | * Repository setter |
||
279 | * |
||
280 | * @param \GitElephant\Repository $repository the repository variable |
||
281 | */ |
||
282 | public function setRepository(Repository $repository) |
||
286 | |||
287 | /** |
||
288 | * Repository getter |
||
289 | * |
||
290 | * @return \GitElephant\Repository |
||
291 | */ |
||
292 | 19 | public function getRepository() |
|
296 | } |
||
297 |