1: <?php
2: /**
3: * Copyright 2007 Maintainable Software, LLC
4: * Copyright 2006-2012 Horde LLC (http://www.horde.org/)
5: *
6: * @author Mike Naberezny <mike@maintainable.com>
7: * @author Derek DeVries <derek@maintainable.com>
8: * @author Chuck Hagenbuch <chuck@horde.org>
9: * @license http://www.horde.org/licenses/bsd
10: * @category Horde
11: * @package View
12: * @subpackage Helper
13: */
14:
15: /**
16: * View helpers for URLs
17: *
18: * @author Mike Naberezny <mike@maintainable.com>
19: * @author Derek DeVries <derek@maintainable.com>
20: * @author Chuck Hagenbuch <chuck@horde.org>
21: * @license http://www.horde.org/licenses/bsd
22: * @category Horde
23: * @package View
24: * @subpackage Helper
25: */
26: class Horde_View_Helper_Text_Cycle
27: {
28: /**
29: * Array of values to cycle through
30: * @var array
31: */
32: private $_values;
33:
34: /**
35: * Construct a new cycler
36: *
37: * @param array $values Values to cycle through
38: */
39: public function __construct($values)
40: {
41: if (func_num_args() != 1 || !is_array($values)) {
42: throw new InvalidArgumentException();
43: }
44:
45: if (count($values) < 2) {
46: throw new InvalidArgumentException('must have at least two values');
47: }
48:
49: $this->_values = $values;
50: $this->reset();
51: }
52:
53: /**
54: * Returns the current element in the cycle
55: * and advance the cycle
56: *
57: * @return mixed Current element
58: */
59: public function __toString()
60: {
61: $value = next($this->_values);
62: return strval(($value !== false) ? $value : reset($this->_values));
63: }
64:
65: /**
66: * Reset the cycle
67: */
68: public function reset()
69: {
70: end($this->_values);
71: }
72:
73: /**
74: * Returns the values of this cycler.
75: *
76: * @return array
77: */
78: public function getValues()
79: {
80: return $this->_values;
81: }
82:
83: }
84: