- md5
- 40e3e096de1fd366dd62cc8eaf2b098f
- sha1
- 7a41ff013ae3fdc1cee59b89806be5a677cbcbc3
- sha256
- 6d2d278196ed359fd1e898a259f9dee5d20179c41b520cb9f3f9a98a3c785b4b
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Proxy;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Object read-only proxy class.
* The class provides read-only feature for Object, including its children.
*
* @since 5.0.0
*/
class ObjectReadOnlyProxy extends ObjectProxy implements ReadOnlyProxyInterface
{
/**
* Implementing reading from object
*
* @param mixed $key The key name to read
*
* @return mixed
*
* @since 5.0.0
*/
public function __get($key): mixed
{
$value = $this->data->$key ?? null;
// Ensure that the child also is a read-only
if (\is_scalar($value) || $value === null) {
return $value;
} elseif (\is_object($value)) {
$value = new static($value);
} elseif (\is_array($value)) {
$value = new ArrayReadOnlyProxy($value);
}
return $value;
}
/**
* Implementing writing to object
*
* @param mixed $key The key name to write
* @param mixed $value The value to write
*
* @return void
*
* @throws \RuntimeException
*
* @since 5.0.0
*/
public function __set($key, $value): void
{
throw new \RuntimeException(sprintf('ObjectReadOnlyProxy: trying to modify read-only element, by key "%s"', $key));
}
/**
* Implementation of Iterator interface
*
* @return mixed
*
* @since 5.0.0
*/
public function current(): mixed
{
$value = $this->iterator->current();
// Ensure that the child also is a read-only
if (\is_scalar($value) || $value === null) {
return $value;
} elseif (\is_object($value)) {
$value = new static($value);
} elseif (\is_array($value)) {
$value = new ArrayReadOnlyProxy($value);
}
return $value;
}
}
The same content is in 2 releases, Joomla 5.0.0-alpha4 to 5.0.0-beta1. See them all, or every version of this file.