Auth\User: implement array access interface

This commit is contained in:
Benjamin Renard 2024-09-13 18:26:23 +02:00
parent df4cc74fea
commit b33a3e8205
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -7,7 +7,7 @@ use EesyPHP\Log;
use function EesyPHP\ensure_is_array; use function EesyPHP\ensure_is_array;
use function EesyPHP\vardump; use function EesyPHP\vardump;
class User { class User implements \ArrayAccess {
/** /**
* Username * Username
@ -108,6 +108,51 @@ class User {
} }
} }
/**
* ArrayAccess interface
*/
#[\ReturnTypeWillChange]
/**
* Magic method to check if an dynamic property exist when object is used as an array
* @param string $offset The property
* @return bool
*/
public function offsetExists($offset) {
return $this -> __isset($offset);
}
#[\ReturnTypeWillChange]
/**
* Magic method to get a dynamic property when object is used as an array
* @param string $offset The property
* @return mixed
*/
public function offsetGet($offset){
return $this -> __get($offset);
}
#[\ReturnTypeWillChange]
/**
* Magic method to set a dynamic property when object is used as an array
* @param string $offset The property
* @param mixed $value The value
* @return void
*/
public function offsetSet($offset, $value) {
$this -> __set($offset, $value);
}
#[\ReturnTypeWillChange]
/**
* Magic method to unset (=set as null) a dynamic property when object is used as an array
* @param string $offset The property
* @return void
*/
public function offsetUnset($offset) {
$this -> __set($offset, null);
}
/** /**
* Check user password * Check user password
* @param string $password * @param string $password