3 class CRM_Utils_OptionBag
implements ArrayAccess
, IteratorAggregate
, Countable
{
6 public function __construct($data = array()) {
13 public function getArray() {
18 * Retrieve a value from the bag
21 * @param string|null $type
22 * @param mixed $default
24 * @throws API_Exception
26 public function get($key, $type = NULL, $default = NULL) {
27 if (!array_key_exists($key, $this->data
)) {
31 return $this->data
[$key];
33 $r = CRM_Utils_Type
::validate($this->data
[$key], $type);
38 throw new \
API_Exception(ts("Could not find valid value for %1 (%2)", array(1 => $key, 2 => $type)));
42 public function has($key) {
43 return isset($this->data
[$key]);
47 * (PHP 5 >= 5.0.0)<br/>
48 * Whether a offset exists
49 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
50 * @param mixed $offset <p>
51 * An offset to check for.
53 * @return boolean true on success or false on failure.
56 * The return value will be casted to boolean if non-boolean was returned.
58 public function offsetExists($offset) {
59 return array_key_exists($offset, $this->data
);
63 * (PHP 5 >= 5.0.0)<br/>
65 * @link http://php.net/manual/en/arrayaccess.offsetget.php
66 * @param mixed $offset <p>
67 * The offset to retrieve.
69 * @return mixed Can return all value types.
71 public function offsetGet($offset) {
72 return $this->data
[$offset];
76 * (PHP 5 >= 5.0.0)<br/>
78 * @link http://php.net/manual/en/arrayaccess.offsetset.php
79 * @param mixed $offset <p>
80 * The offset to assign the value to.
82 * @param mixed $value <p>
87 public function offsetSet($offset, $value) {
88 $this->data
[$offset] = $value;
92 * (PHP 5 >= 5.0.0)<br/>
94 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
95 * @param mixed $offset <p>
96 * The offset to unset.
100 public function offsetUnset($offset) {
101 unset($this->data
[$offset]);
105 * (PHP 5 >= 5.0.0)<br/>
106 * Retrieve an external iterator
107 * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
108 * @return Traversable An instance of an object implementing <b>Iterator</b> or
111 public function getIterator() {
112 return new ArrayIterator($this->data
);
116 * (PHP 5 >= 5.1.0)<br/>
117 * Count elements of an object
118 * @link http://php.net/manual/en/countable.count.php
119 * @return int The custom count as an integer.
122 * The return value is cast to an integer.
124 public function count() {
125 return count($this->data
);