From c41f1d5066a67379c72aae7179e7a000aa573beb Mon Sep 17 00:00:00 2001 From: neopheus Date: Sun, 25 Feb 2024 19:45:00 +0100 Subject: [PATCH] Compatibility Php 8.2 --- src/PrintNode/EntityDynamic.php | 48 ++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/PrintNode/EntityDynamic.php b/src/PrintNode/EntityDynamic.php index de83486..12b915b 100644 --- a/src/PrintNode/EntityDynamic.php +++ b/src/PrintNode/EntityDynamic.php @@ -4,76 +4,80 @@ abstract class EntityDynamic extends Entity { - /** * Reference to the client * @var Client */ - protected static $protectedProperties = array( + protected static $protectedProperties = [ 'client', - ); + ]; + + /** + * Dynamic Properties + * @var array + */ + protected $dynamicProperties = []; /** * Set property on entity + * * @param mixed $propertyName * @param mixed $value * @return void */ public function __set($propertyName, $value) { - - if (\in_array($propertyName, self::$protectedProperties)) { + if (in_array($propertyName, self::$protectedProperties)) { throw new \PrintNode\Exception\InvalidArgumentException($propertyName . ' is a protected property.'); } - $this->$propertyName = $value; + $this->dynamicProperties[$propertyName] = $value; + } + /** + * Get a dynamic property + * + * @param mixed $propertyName + * @return mixed|null + */ + public function __get($propertyName) + { + return $this->dynamicProperties[$propertyName] ?? null; } /** * Maps a json object to this entity - * + * * @param string $json The JSON to map to this entity * @return string */ public function mapValuesFromJson($json) { - foreach ($json as $key => $value) { - $this->$key = $value; + $this->__set($key, $value); } return true; - } /** * Implements the jsonSerialize method - * + * * @return string */ #[\ReturnTypeWillChange] public function jsonSerialize() { + $json = []; - $refClass = new \ReflectionClass($this); - - $properties = get_object_vars($this); - - $json = array(); - - foreach ($properties as $property => $value) { - + foreach ($this->dynamicProperties as $property => $value) { if (in_array($property, self::$protectedProperties)) { continue; } $json[$property] = $value; - } return $json; - } - }