/usr/share/php/Horde/Support/Array.php is in php-horde-support 2.2.0-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | <?php
/**
* Copyright 2007-2017 Horde LLC (http://www.horde.org/)
*
* @todo - Incorporate stuff from Horde_Array?
* - http://docs.python.org/lib/typesmapping.html
*
* @category Horde
* @package Support
* @license http://www.horde.org/licenses/bsd
*/
class Horde_Support_Array implements ArrayAccess, Countable, IteratorAggregate
{
/**
* Array variables
*/
protected $_array = array();
/**
*/
public function __construct($vars = array())
{
if (is_array($vars)) {
$this->update($vars);
}
}
/**
*/
public function get($key, $default = null)
{
return isset($this->_array[$key]) ? $this->_array[$key] : $default;
}
/**
* Gets the value at $offset. If no value exists at that offset, or the
* value $offset is NULL, then $default is set as the value of $offset.
*
* @param string $offset Offset to retrieve and set if unset
* @param string $default Default value if $offset does not exist
*
* @return mixed Value at $offset or $default
*/
public function getOrSet($offset, $default = null)
{
$value = $this->offsetGet($offset);
if (is_null($value)) {
$this->offsetSet($offset, $value = $default);
}
return $value;
}
/**
* Gets the value at $offset and deletes it from the array. If no value
* exists at $offset, or the value at $offset is null, then $default
* will be returned.
*
* @param string $offset Offset to pop
* @param string $default Default value
*
* @return mixed Value at $offset or $default
*/
public function pop($offset, $default = null)
{
$value = $this->offsetGet($offset);
$this->offsetUnset($offset);
return isset($value) ? $value : $default;
}
/**
* Update the array with the key/value pairs from $array
*
* @param array $array Key/value pairs to set/change in the array.
*/
public function update($array)
{
if (!is_array($array) && !$array instanceof Traversable) {
throw new InvalidArgumentException('expected array or traversable, got ' . gettype($array));
}
foreach ($array as $key => $val) {
$this->offsetSet($key, $val);
}
}
/**
* Get the keys in the array
*
* @return array
*/
public function getKeys()
{
return array_keys($this->_array);
}
/**
* Get the values in the array
*
* @return array
*/
public function getValues()
{
return array_values($this->_array);
}
/**
* Clear out the array
*/
public function clear()
{
$this->_array = array();
}
/**
*/
public function __get($key)
{
return $this->get($key);
}
/**
*/
public function __set($key, $value)
{
$this->_array[$key] = $value;
}
/**
* Checks the existance of $key in this array
*/
public function __isset($key)
{
return array_key_exists($key, $this->_array);
}
/**
* Removes $key from this array
*/
public function __unset($key)
{
unset($this->_array[$key]);
}
/**
* Count the number of elements
*
* @return integer
*/
public function count()
{
return count($this->_array);
}
/**
*/
public function getIterator()
{
return new ArrayIterator($this->_array);
}
/**
* Gets the value of $offset in this array
*
* @see __get()
*/
public function offsetGet($offset)
{
return $this->__get($offset);
}
/**
* Sets the value of $offset to $value
*
* @see __set()
*/
public function offsetSet($offset, $value)
{
return $this->__set($offset, $value);
}
/**
* Checks the existence of $offset in this array
*
* @see __isset()
*/
public function offsetExists($offset)
{
return $this->__isset($offset);
}
/**
* Removes $offset from this array
*
* @see __unset()
*/
public function offsetUnset($offset)
{
return $this->__unset($offset);
}
}
|