Auth\User: add __set() method

This commit is contained in:
Benjamin Renard 2023-02-28 15:55:49 +01:00
parent b9a5a60dc9
commit 37eab5d49f
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -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