3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ /** * Provides a property based interface to an array. * The data are read-only unless $allowModifications is set to true * on construction. * * Implements Countable, Iterator and ArrayAccess * to facilitate easy access to the data. */ class Config implements Countable, Iterator, ArrayAccess { /** * Whether modifications to configuration data are allowed. * * @var bool */ protected $allowModifications; /** * Number of elements in configuration data. * * @var int */ protected $count; /** * Data withing the configuration. * * @var array */ protected $data = array(); /** * Used when unsetting values during iteration to ensure we do not skip * the next element. * * @var bool */ protected $skipNextIteration; /** * Constructor. * * Data is read-only unless $allowModifications is set to true * on construction. * * @param array $array * @param bool $allowModifications */ public function __construct(array $array, $allowModifications = false) { $this->allowModifications = (bool) $allowModifications; foreach ($array as $key => $value) { if (is_array($value)) { $this->data[$key] = new static($value, $this->allowModifications); } else { $this->data[$key] = $value; } $this->count++; } } /** * Retrieve a value and return $default if there is no element set. * * @param string $name * @param mixed $default * @return mixed */ public function get($name, $default = null) { if (array_key_exists($name, $this->data)) { return $this->data[$name]; } return $default; } /** * Magic function so that $obj->value will work. * * @param string $name * @return mixed */ public function __get($name) { return $this->get($name); } /** * Set a value in the config. * * Only allow setting of a property if $allowModifications was set to true * on construction. Otherwise, throw an exception. * * @param string $name * @param mixed $value * @return void * @throws Exception\RuntimeException */ public function __set($name, $value) { if ($this->allowModifications) { if (is_array($value)) { $value = new static($value, true); } if (null === $name) { $this->data[] = $value; } else { $this->data[$name] = $value; } $this->count++; } else { throw new Exception\RuntimeException('Config is read only'); } } /** * Deep clone of this instance to ensure that nested Zend\Configs are also * cloned. * * @return void */ public function __clone() { $array = array(); foreach ($this->data as $key => $value) { if ($value instanceof self) { $array[$key] = clone $value; } else { $array[$key] = $value; } } $this->data = $array; } /** * Return an associative array of the stored data. * * @return array */ public function toArray() { $array = array(); $data = $this->data; /** @var self $value */ foreach ($data as $key => $value) { if ($value instanceof self) { $array[$key] = $value->toArray(); } else { $array[$key] = $value; } } return $array; } /** * isset() overloading * * @param string $name * @return bool */ public function __isset($name) { return isset($this->data[$name]); } /** * unset() overloading * * @param string $name * @return void * @throws Exception\InvalidArgumentException */ public function __unset($name) { if (!$this->allowModifications) { throw new Exception\InvalidArgumentException('Config is read only'); } elseif (isset($this->data[$name])) { unset($this->data[$name]); $this->count--; $this->skipNextIteration = true; } } /** * count(): defined by Countable interface. * * @see Countable::count() * @return int */ public function count() { return $this->count; } /** * current(): defined by Iterator interface. * * @see Iterator::current() * @return mixed */ public function current() { $this->skipNextIteration = false; return current($this->data); } /** * key(): defined by Iterator interface. * * @see Iterator::key() * @return mixed */ public function key() { return key($this->data); } /** * next(): defined by Iterator interface. * * @see Iterator::next() * @return void */ public function next() { if ($this->skipNextIteration) { $this->skipNextIteration = false; return; } next($this->data); } /** * rewind(): defined by Iterator interface. * * @see Iterator::rewind() * @return void */ public function rewind() { $this->skipNextIteration = false; reset($this->data); } /** * valid(): defined by Iterator interface. * * @see Iterator::valid() * @return bool */ public function valid() { return ($this->key() !== null); } /** * offsetExists(): defined by ArrayAccess interface. * * @see ArrayAccess::offsetExists() * @param mixed $offset * @return bool */ public function offsetExists($offset) { return $this->__isset($offset); } /** * offsetGet(): defined by ArrayAccess interface. * * @see ArrayAccess::offsetGet() * @param mixed $offset * @return mixed */ public function offsetGet($offset) { return $this->__get($offset); } /** * offsetSet(): defined by ArrayAccess interface. * * @see ArrayAccess::offsetSet() * @param mixed $offset * @param mixed $value * @return void */ public function offsetSet($offset, $value) { $this->__set($offset, $value); } /** * offsetUnset(): defined by ArrayAccess interface. * * @see ArrayAccess::offsetUnset() * @param mixed $offset * @return void */ public function offsetUnset($offset) { $this->__unset($offset); } /** * Merge another Config with this one. * * For duplicate keys, the following will be performed: * - Nested Configs will be recursively merged. * - Items in $merge with INTEGER keys will be appended. * - Items in $merge with STRING keys will overwrite current values. * * @param Config $merge * @return Config */ public function merge(Config $merge) { /** @var Config $value */ foreach ($merge as $key => $value) { if (array_key_exists($key, $this->data)) { if (is_int($key)) { $this->data[] = $value; } elseif ($value instanceof self && $this->data[$key] instanceof self) { $this->data[$key]->merge($value); } else { if ($value instanceof self) { $this->data[$key] = new static($value->toArray(), $this->allowModifications); } else { $this->data[$key] = $value; } } } else { if ($value instanceof self) { $this->data[$key] = new static($value->toArray(), $this->allowModifications); } else { $this->data[$key] = $value; } $this->count++; } } return $this; } /** * Prevent any more modifications being made to this instance. * * Useful after merge() has been used to merge multiple Config objects * into one object which should then not be modified again. * * @return void */ public function setReadOnly() { $this->allowModifications = false; /** @var Config $value */ foreach ($this->data as $value) { if ($value instanceof self) { $value->setReadOnly(); } } } /** * Returns whether this Config object is read only or not. * * @return bool */ public function isReadOnly() { return !$this->allowModifications; } } $obj = new Config( array( 'titulo' => 'CAWZ :: Central Admin Web Zone', 'dominio' => $_SERVER['HTTP_HOST'], 'urlActual' => $_SERVER['REQUEST_URI'], 'pagina' => basename($_SERVER['SCRIPT_NAME']), 'basePath' => dirname($_SERVER['DOCUMENT_ROOT']), 'clases' => dirname(dirname($_SERVER['DOCUMENT_ROOT'])) . '/libs', 'plantillas' => dirname($_SERVER['DOCUMENT_ROOT']) . '/plantillas/', 'traducciones' => dirname(dirname($_SERVER['DOCUMENT_ROOT'])) . '/idiomas', 'imagenes' => array( 'apartamentos' => array( 'path' => dirname($_SERVER['DOCUMENT_ROOT']) . '/www/apartamentos', 'sizes' => array('s' => '120x90', 'm' => '120x90', 'l' => '120x90'), ) ), 'idioma' => array( 'base' => 'es', 'locales' => array('es' => 'es_ES.UTF8', 'en' => 'en_US.UTF8') ), 'debug' => true ) );
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Config::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4l1Y8 on line 211 Deprecated: Return type of Config::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4l1Y8 on line 222 Deprecated: Return type of Config::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4l1Y8 on line 245 Deprecated: Return type of Config::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4l1Y8 on line 234 Deprecated: Return type of Config::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4l1Y8 on line 273 Deprecated: Return type of Config::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4l1Y8 on line 261 Deprecated: Return type of Config::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4l1Y8 on line 285 Deprecated: Return type of Config::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4l1Y8 on line 297 Deprecated: Return type of Config::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4l1Y8 on line 310 Deprecated: Return type of Config::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4l1Y8 on line 322 Warning: Undefined array key "HTTP_HOST" in /in/4l1Y8 on line 402 Warning: Undefined array key "REQUEST_URI" in /in/4l1Y8 on line 403

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
44.57 ms | 409 KiB | 8 Q