1 | <?php |
||
28 | class LogRange implements \ArrayAccess, \Countable, \Iterator |
||
29 | { |
||
30 | /** |
||
31 | * @var \GitElephant\Repository |
||
32 | */ |
||
33 | private $repository; |
||
34 | |||
35 | /** |
||
36 | * the commits related to this log |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | private $rangeCommits = array(); |
||
41 | |||
42 | /** |
||
43 | * the cursor position |
||
44 | * |
||
45 | * @var int |
||
46 | */ |
||
47 | private $position = 0; |
||
48 | |||
49 | /** |
||
50 | * Class constructor |
||
51 | * |
||
52 | * @param \GitElephant\Repository $repository repo |
||
53 | * @param string $refStart starting reference (excluded from the range) |
||
54 | * @param string $refEnd ending reference |
||
55 | * @param null $path path |
||
56 | * @param int $limit limit |
||
57 | * @param null $offset offset |
||
58 | * @param boolean $firstParent first parent |
||
59 | * |
||
60 | * @throws \RuntimeException |
||
61 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
62 | */ |
||
63 | 6 | public function __construct( |
|
75 | |||
76 | /** |
||
77 | * get the commit properties from command |
||
78 | * |
||
79 | * @param string $refStart treeish reference |
||
80 | * @param string $refEnd treeish reference |
||
81 | * @param string $path path |
||
82 | * @param int $limit limit |
||
83 | * @param string $offset offset |
||
84 | * @param boolean $firstParent first parent |
||
85 | * |
||
86 | * @throws \RuntimeException |
||
87 | * @throws \Symfony\Component\Process\Exception\LogicException |
||
88 | * @throws \Symfony\Component\Process\Exception\InvalidArgumentException |
||
89 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
90 | * @see ShowCommand::commitInfo |
||
91 | */ |
||
92 | 6 | private function createFromCommand($refStart, $refEnd, $path, $limit, $offset, $firstParent) |
|
102 | |||
103 | 6 | private function parseOutputLines($outputLines) |
|
104 | { |
||
105 | 6 | $commitLines = null; |
|
106 | 6 | $this->rangeCommits = array(); |
|
107 | 6 | foreach ($outputLines as $line) { |
|
108 | 6 | if (preg_match('/^commit (\w+)$/', $line) > 0) { |
|
109 | 6 | if (null !== $commitLines) { |
|
110 | 6 | $this->rangeCommits[] = Commit::createFromOutputLines($this->getRepository(), $commitLines); |
|
111 | 6 | } |
|
112 | 6 | $commitLines = array(); |
|
113 | 6 | } |
|
114 | 6 | $commitLines[] = $line; |
|
115 | 6 | } |
|
116 | 6 | if (null !== $commitLines && count($commitLines) > 0) { |
|
117 | 6 | $this->rangeCommits[] = Commit::createFromOutputLines($this->getRepository(), $commitLines); |
|
118 | 6 | } |
|
119 | 6 | } |
|
120 | |||
121 | /** |
||
122 | * Get array representation |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | 1 | public function toArray() |
|
130 | |||
131 | /** |
||
132 | * Get the first commit |
||
133 | * |
||
134 | * @return Commit|null |
||
135 | */ |
||
136 | 1 | public function first() |
|
140 | |||
141 | /** |
||
142 | * Get the last commit |
||
143 | * |
||
144 | * @return Commit|null |
||
145 | */ |
||
146 | 1 | public function last() |
|
150 | |||
151 | /** |
||
152 | * Get commit at index |
||
153 | * |
||
154 | * @param int $index the commit index |
||
155 | * |
||
156 | * @return Commit|null |
||
157 | */ |
||
158 | 1 | public function index($index) |
|
162 | |||
163 | /** |
||
164 | * ArrayAccess interface |
||
165 | * |
||
166 | * @param int $offset offset |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | 1 | public function offsetExists($offset) |
|
174 | |||
175 | /** |
||
176 | * ArrayAccess interface |
||
177 | * |
||
178 | * @param int $offset offset |
||
179 | * |
||
180 | * @return Commit|null |
||
181 | */ |
||
182 | 2 | public function offsetGet($offset) |
|
186 | |||
187 | /** |
||
188 | * ArrayAccess interface |
||
189 | * |
||
190 | * @param int $offset offset |
||
191 | * @param mixed $value value |
||
192 | * |
||
193 | * @throws \RuntimeException |
||
194 | */ |
||
195 | 1 | public function offsetSet($offset, $value) |
|
199 | |||
200 | /** |
||
201 | * ArrayAccess interface |
||
202 | * |
||
203 | * @param int $offset offset |
||
204 | * |
||
205 | * @throws \RuntimeException |
||
206 | */ |
||
207 | 1 | public function offsetUnset($offset) |
|
211 | |||
212 | /** |
||
213 | * Countable interface |
||
214 | * |
||
215 | * @return int|void |
||
216 | */ |
||
217 | 1 | public function count() |
|
221 | |||
222 | /** |
||
223 | * Iterator interface |
||
224 | * |
||
225 | * @return Commit|null |
||
226 | */ |
||
227 | 1 | public function current() |
|
231 | |||
232 | /** |
||
233 | * Iterator interface |
||
234 | */ |
||
235 | 1 | public function next() |
|
239 | |||
240 | /** |
||
241 | * Iterator interface |
||
242 | * |
||
243 | * @return int |
||
244 | */ |
||
245 | 1 | public function key() |
|
249 | |||
250 | /** |
||
251 | * Iterator interface |
||
252 | * |
||
253 | * @return bool |
||
254 | */ |
||
255 | 1 | public function valid() |
|
259 | |||
260 | /** |
||
261 | * Iterator interface |
||
262 | */ |
||
263 | 1 | public function rewind() |
|
267 | |||
268 | /** |
||
269 | * Repository setter |
||
270 | * |
||
271 | * @param \GitElephant\Repository $repository the repository variable |
||
272 | */ |
||
273 | 1 | public function setRepository($repository) |
|
277 | |||
278 | /** |
||
279 | * Repository getter |
||
280 | * |
||
281 | * @return \GitElephant\Repository |
||
282 | */ |
||
283 | 6 | public function getRepository() |
|
287 | } |
||
288 |