From 37eab5d49fdc8a946d108dfcc69f56c066d20a8a Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 28 Feb 2023 15:55:49 +0100 Subject: [PATCH] Auth\User: add __set() method --- src/Auth/User.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Auth/User.php b/src/Auth/User.php index 97f16f3..922cf4c 100644 --- a/src/Auth/User.php +++ b/src/Auth/User.php @@ -3,6 +3,7 @@ namespace EesyPHP\Auth; use EesyPHP\Log; +use function EesyPHP\ensure_is_array; class User { @@ -58,6 +59,28 @@ class User { return null; } + /** + * Magic method to set a dynamic property + * @param string $key The property + * @param mixed $value The value + * @return void + */ + public function __set($key, $value) { + switch ($key) { + case 'username': + $this -> username = strval($value); + break; + case 'backend': + $this -> backend = strval($value); + break; + case 'info': + $this -> info = ensure_is_array($value); + break; + default: + $this -> info[$key] = $value; + } + } + /** * Magic method to check if a dynamic property is set * @param string $key The property