Auth\User: implement array access interface
This commit is contained in:
parent
df4cc74fea
commit
b33a3e8205
1 changed files with 46 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue