/usr/share/php/Nette/common/ArrayHash.php is in php-nette 2.1.0-1.
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 | <?php
/**
* This file is part of the Nette Framework (http://nette.org)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/
namespace Nette;
use Nette;
/**
* Provides objects to work as array.
*
* @author David Grudl
*/
class ArrayHash extends \stdClass implements \ArrayAccess, \Countable, \IteratorAggregate
{
/**
* @param array to wrap
* @param bool
* @return ArrayHash
*/
public static function from($arr, $recursive = TRUE)
{
$obj = new static;
foreach ($arr as $key => $value) {
if ($recursive && is_array($value)) {
$obj->$key = static::from($value, TRUE);
} else {
$obj->$key = $value;
}
}
return $obj;
}
/**
* Returns an iterator over all items.
* @return \RecursiveArrayIterator
*/
public function getIterator()
{
return new \RecursiveArrayIterator($this);
}
/**
* Returns items count.
* @return int
*/
public function count()
{
return count((array) $this);
}
/**
* Replaces or appends a item.
* @return void
*/
public function offsetSet($key, $value)
{
if (!is_scalar($key)) { // prevents NULL
throw new InvalidArgumentException("Key must be either a string or an integer, " . gettype($key) ." given.");
}
$this->$key = $value;
}
/**
* Returns a item.
* @return mixed
*/
public function offsetGet($key)
{
return $this->$key;
}
/**
* Determines whether a item exists.
* @return bool
*/
public function offsetExists($key)
{
return isset($this->$key);
}
/**
* Removes the element from this list.
* @return void
*/
public function offsetUnset($key)
{
unset($this->$key);
}
}
|