Overview

Packages

  • Jyxo_Beholder
  • Jyxo_Charset
  • Jyxo_Color
  • Jyxo_Css
  • Jyxo_ErrorHandling
  • Jyxo_FirePhp
  • Jyxo_Gettext
    • Parser
  • Jyxo_Html
  • Jyxo_Input
    • Chain
    • Filter
    • Validator
  • Jyxo_Mail
    • Email
    • Parser
    • Sender
  • Jyxo_Rpc
    • Json
    • Xml
  • Jyxo_Shell
  • Jyxo_SpamFilter
  • Jyxo_Spl
  • Jyxo_String
  • Jyxo_Svn
  • Jyxo_Time
  • Jyxo_Timer
  • Jyxo_Webdav
  • Jyxo_XmlReader
  • PHP

Classes

  • Jyxo_Svn_Client
  • Jyxo_Svn_Result

Exceptions

  • Jyxo_Svn_Exception
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * Jyxo PHP Library
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file license.txt.
 10:  * It is also available through the world-wide-web at this URL:
 11:  * https://github.com/jyxo/php/blob/master/license.txt
 12:  */
 13: 
 14: /**
 15:  * Container for parsed SVN binary output.
 16:  *
 17:  * Experimental.
 18:  *
 19:  * @category Jyxo
 20:  * @package Jyxo_Svn
 21:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
 22:  * @license https://github.com/jyxo/php/blob/master/license.txt
 23:  * @author Matěj Humpál
 24:  */
 25: class Jyxo_Svn_Result implements Countable, SeekableIterator
 26: {
 27: 
 28:     /**
 29:      * OK status.
 30:      *
 31:      * @var string
 32:      */
 33:     const OK = 'OK';
 34: 
 35:     /**
 36:      * KO status.
 37:      *
 38:      * @var string
 39:      */
 40:     const KO = 'KO';
 41: 
 42:     /**
 43:      * Added file flag.
 44:      *
 45:      * @var string
 46:      */
 47:     const ADD = 'A';
 48: 
 49:     /**
 50:      * Deleted file flag.
 51:      *
 52:      * @var string
 53:      */
 54:     const DELETE = 'D';
 55: 
 56:     /**
 57:      * Updated file flag.
 58:      *
 59:      * @var string
 60:      */
 61:     const UPDATE = 'U';
 62: 
 63:     /**
 64:      * Conflicted file flag.
 65:      *
 66:      * @var string
 67:      */
 68:     const CONFLICT = 'C';
 69: 
 70:     /**
 71:      * Modified file flag.
 72:      *
 73:      * @var string
 74:      */
 75:     const MODIFIED = 'M';
 76: 
 77:     /**
 78:      * Merged file flag.
 79:      *
 80:      * @var string
 81:      */
 82:     const MERGE = 'G';
 83: 
 84:     /**
 85:      * SVN:externals file flag.
 86:      *
 87:      * @var string
 88:      */
 89:     const EXTERNALS = 'X';
 90: 
 91:     /**
 92:      * Ignored file flag.
 93:      *
 94:      * @var string
 95:      */
 96:     const IGNORED = 'I';
 97: 
 98:     /**
 99:      * Locked file flag.
100:      *
101:      * @var string
102:      */
103:     const LOCKED = 'L';
104: 
105:     /**
106:      * Non-versioned file flag.
107:      *
108:      * @var string
109:      */
110:     const NOT_VERSIONED = '?';
111: 
112:     /**
113:      * Missing file flag.
114:      *
115:      * @var string
116:      */
117:     const MISSING = '!';
118: 
119:     /**
120:      * Flag meaning that the versioned object (file, directory, ...)
121:      * has been replaced with another kind of object.
122:      *
123:      * @var string
124:      */
125:     const DIR_FILE_SWITCH = '~';
126: 
127:     /**
128:      * History scheduled with commit flag.
129:      *
130:      * @var string
131:      */
132:     const SCHEDULED = '+';
133: 
134:     /**
135:      * Switched item flag.
136:      *
137:      * @var string
138:      */
139:     const SWITCHED = 'S';
140: 
141:     /**
142:      * Flag meaning that there is a newer version on the server.
143:      *
144:      * @var string
145:      */
146:     const NEW_VERSION_EXISTS = '*';
147: 
148:     /**
149:      * Status table.
150:      *
151:      * @var array
152:      */
153:     protected $statusTable = array(
154:         self::ADD => 'A',
155:         self::DELETE => 'D',
156:         self::UPDATE => 'U',
157:         self::CONFLICT => 'C',
158:         self::MODIFIED => 'M',
159:         self::MERGE => 'G',
160:         self::EXTERNALS => 'X',
161:         self::IGNORED => 'I',
162:         self::LOCKED => 'L',
163:         self::NOT_VERSIONED => '?',
164:         self::MISSING => '!',
165:         self::DIR_FILE_SWITCH => '',
166:         self::SCHEDULED => '+',
167:         self::SWITCHED => 'S',
168:         self::NEW_VERSION_EXISTS => '*',
169:     );
170: 
171:     /**
172:      * Action revision.
173:      *
174:      * @var integer
175:      */
176:     protected $revision;
177: 
178:     /**
179:      * Action error.
180:      *
181:      * @var string
182:      */
183:     protected $error = '';
184: 
185:     /**
186:      * Action status.
187:      *
188:      * @var string
189:      */
190:     protected $status;
191: 
192:     /**
193:      * Action items.
194:      *
195:      * @var array
196:      */
197:     protected $items = array();
198: 
199:     /**
200:      * Internal pointer.
201:      *
202:      * @var integer
203:      */
204:     protected $pointer = 0;
205: 
206:     /**
207:      * Constructor.
208:      *
209:      * @param string $action SVN action
210:      * @param string $input Action input
211:      * @param integer $returnCode SVN binary return code
212:      */
213:     public function __construct($action, $input, $returnCode = 1)
214:     {
215:         $this->items = $this->parse($action, $input);
216:         $this->status = $returnCode === 0 ? self::OK : self::KO;
217:         $this->error = $returnCode === 0 ? '' : $input;
218:     }
219: 
220:     /**
221:      * Parses SVN binary output according to the action.
222:      *
223:      * @param string $action SVN action
224:      * @param string $input SVN binary output
225:      * @return array
226:      */
227:     protected function parse($action, $input)
228:     {
229:         switch ($action) {
230:             case 'add':
231:             case 'status':
232:                 return $this->parseStatus($input);
233:             case 'commit':
234:                 return $this->parseCommit($input);
235:             case 'update':
236:                 return $this->parseUpdate($input);
237:             default:
238:                 // Do nothing
239:                 return array();
240:         }
241:     }
242: 
243:     /**
244:      * Parses SVN statis.
245:      *
246:      * @param string $input SVN binary output
247:      * @return array
248:      */
249:     protected function parseStatus($input)
250:     {
251:         $array = explode("\n", (string) $input);
252:         foreach ($array as $key => &$line) {
253: 
254:             $line = trim($line);
255: 
256:             if (empty($line)) {
257:                 unset($array[$key]);
258:                 continue;
259:             }
260: 
261:             $tmp = $line;
262:             $line = array();
263: 
264:             if ($tmp{0} !== ' ') {
265:                 $line['status'] = $tmp{0};
266:             }
267:             if ($tmp{1} !== ' ') {
268:                 $line['properties'] = $tmp{1};
269:             }
270:             if ($tmp{2} !== ' ') {
271:                 $line['lock'] = $tmp{2};
272:             }
273:             if ($tmp{3} !== ' ') {
274:                 $line['history'] = $tmp{3};
275:             }
276:             if ($tmp{4} !== ' ') {
277:                 $line['switch'] = $tmp{4};
278:             }
279:             $line['file'] = substr($tmp, 7);
280: 
281:         }
282:         return $array;
283:     }
284: 
285:     /**
286:      * Parses commit output and sets revision number.
287:      *
288:      * @param string $input SVN binary output
289:      * @return array
290:      */
291:     protected function parseCommit($input)
292:     {
293:         $array = explode("\n", (string) $input);
294:         foreach ($array as $key => &$line) {
295: 
296:             $line = trim($line);
297: 
298:             if (empty($line)) {
299:                 unset($array[$key]);
300:                 continue;
301:             }
302: 
303:             if (preg_match('/Committed revision ([0-9]+)\./i', $line, $matches)) {
304:                 $this->revision = (int) $matches[1];
305:                 unset($array[$key]);
306:                 continue;
307:             }
308: 
309:             if (!preg_match('/Sending.*/', $line)) {
310:                 unset($array[$key]);
311:                 continue;
312:             }
313: 
314:         }
315: 
316:         return $array;
317:     }
318: 
319:     /**
320:      * Parses update output.
321:      *
322:      * @param mixed $input SVN binary output
323:      * @return array
324:      */
325:     protected function parseUpdate($input)
326:     {
327:         $array = explode("\n", (string) $input);
328:         foreach ($array as $key => &$line) {
329: 
330:             $line = trim($line);
331: 
332:             if (empty($line)) {
333:                 unset($array[$key]);
334:                 continue;
335:             }
336: 
337:             if (preg_match('/At revision ([0-9]+)\./i', $line, $matches)) {
338:                 $this->revision = (int) $matches[1];
339:                 unset($array[$key]);
340:                 continue;
341:             }
342: 
343:         }
344: 
345:         return $array;
346:     }
347: 
348:     /**
349:      * Magic __get method.
350:      *
351:      * @param string $prop Property name
352:      * @return mixed
353:      */
354:     public function __get($prop)
355:     {
356:         return isset($this->$prop) ? $this->$prop : null;
357:     }
358: 
359:     /**
360:      * Moves the internal pointer to the given position.
361:      *
362:      * @param integer $position New pointer position
363:      * @return Jyxo_Svn_Result
364:      * @throws Jyxo_Svn_Exception On invalid position
365:      */
366:     public function seek($position)
367:     {
368:         $position = (int) $position;
369:         if ($position < 0 || $position > count($this->items)) {
370:             throw new Jyxo_Svn_Exception(sprintf('Illegal index %d', $position));
371:         }
372:         $this->pointer = $position;
373: 
374:         return $this;
375:     }
376: 
377:     /**
378:      * Returns an item on the actual pointer position.
379:      *
380:      * @return mixed
381:      */
382:     public function current()
383:     {
384:         if ($this->valid()) {
385:             return $this->items[$this->pointer];
386:         }
387: 
388:         return null;
389:     }
390: 
391:     /**
392:      * Advances internal pointer's position to the next item.
393:      *
394:      * @return boolean
395:      */
396:     public function next()
397:     {
398:         return ++$this->pointer < count($this->items);
399:     }
400: 
401:     /**
402:      * Moves the internal pointer to the beginning.
403:      *
404:      * @return Jyxo_Svn_Result
405:      */
406:     public function rewind()
407:     {
408:         $this->pointer = 0;
409: 
410:         return $this;
411:     }
412: 
413:     /**
414:      * Returns the current key value.
415:      *
416:      * @return null|string
417:      */
418:     public function key()
419:     {
420:         return $this->items[$this->pointer];
421:     }
422: 
423:     /**
424:      * Checks if the internal pointer is within correct boundaries.
425:      *
426:      * @return boolean
427:      */
428:     public function valid()
429:     {
430:         return $this->pointer < count($this->items);
431:     }
432: 
433:     /**
434:      * Returns item count.
435:      *
436:      * @return integer
437:      */
438:     public function count()
439:     {
440:         return count($this->items);
441:     }
442: }
443: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0