From 5e9d8b8edcbce757513267bb5ab6c2f56090b118 Mon Sep 17 00:00:00 2001 From: Sebastian Blank Date: Fri, 3 Feb 2023 08:01:40 +0100 Subject: [PATCH] Remove deprecated Pimcore\Config\Config (#14171) --- lib/Config/Config.php | 395 ------------------------------------------ 1 file changed, 395 deletions(-) delete mode 100644 lib/Config/Config.php diff --git a/lib/Config/Config.php b/lib/Config/Config.php deleted file mode 100644 index c58025a9e92..00000000000 --- a/lib/Config/Config.php +++ /dev/null @@ -1,395 +0,0 @@ -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; - } - } - } - - /** - * Retrieve a value and return $default if there is no element set. - * - * @param string $name - * @param mixed $default - * - * @return mixed - */ - public function get(string $name, mixed $default = null): mixed - { - 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(string $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. - * - * @throws Exception - */ - public function __set(?string $name, mixed $value): void - { - if ($this->allowModifications) { - if (is_array($value)) { - $value = new static($value, true); - } - - if (null === $name) { - $this->data[] = $value; - } else { - $this->data[$name] = $value; - } - } else { - throw new Exception('Config is read only'); - } - } - - /** - * Deep clone of this instance to ensure that nested Zend\Configs are also - * cloned. - * - * @return void - */ - public function __clone() - { - $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; - - 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(string $name) - { - return isset($this->data[$name]); - } - - /** - * unset() overloading - * - * @param string $name - * - * @return void - * - * @throws Exception - */ - public function __unset(string $name) - { - if (! $this->allowModifications) { - throw new Exception('Config is read only'); - } elseif (isset($this->data[$name])) { - unset($this->data[$name]); - $this->skipNextIteration = true; - } - } - - /** - * {@inheritdoc} - */ - public function count(): int - { - return count($this->data); - } - - /** - * {@inheritdoc} - */ - public function current(): mixed - { - $this->skipNextIteration = false; - - return current($this->data); - } - - /** - * {@inheritdoc} - */ - public function key(): string|int|null - { - return key($this->data); - } - - /** - * {@inheritdoc} - */ - public function next(): void - { - if ($this->skipNextIteration) { - $this->skipNextIteration = false; - - return; - } - - next($this->data); - } - - /** - * {@inheritdoc} - */ - public function rewind(): void - { - $this->skipNextIteration = false; - reset($this->data); - } - - /** - * {@inheritdoc} - */ - public function valid(): bool - { - return $this->key() !== null; - } - - /** - * {@inheritdoc} - */ - public function offsetExists($offset): bool - { - return $this->__isset($offset); - } - - /** - * {@inheritdoc} - */ - public function offsetGet($offset): mixed - { - return $this->__get($offset); - } - - /** - * {@inheritdoc} - */ - public function offsetSet($offset, $value): void - { - $this->__set($offset, $value); - } - - /** - * {@inheritdoc} - */ - public function offsetUnset($offset): void - { - $this->__unset($offset); - } - - /** - * @internal - * - * 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 $this - */ - public function merge(Config $merge): static - { - 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; - } - } - } - - return $this; - } - - /** - * @internal - * - * 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(): void - { - $this->allowModifications = false; - - /** @var Config $value */ - foreach ($this->data as $value) { - if ($value instanceof self) { - $value->setReadOnly(); - } - } - } - - /** - * @internal - * - * Returns whether this Config object is read only or not. - * - * @return bool - */ - public function isReadOnly(): bool - { - return ! $this->allowModifications; - } - - /** - * @return string|false - */ - public function __toString() - { - if (empty($this->data)) { - return ''; - } - - return json_encode($this->data, JSON_PRETTY_PRINT); - } -}