class User extends Entity
{
protected $attributes = [
'id' => NULL,
'username' => NULL,
'password' => NULL,
'role' => NULL,
'profile_image' => NULL,
'profile_views' => NULL,
'last_login' => NULL,
'about_me' => NULL,
'age' => NULL,
'gender' => NULL,
'occupation' => NULL,
'hometown' => NULL,
'country' => NULL,
'fav_shape' => NULL,
'fav_color' => NULL,
'created' => NULL,
'modified' => NULL,
];
protected $dates = [
'created',
'updated',
];
public function __construct (array $data = null)
{
parent::__construct($data);
}
/**
* Set* Methods
*/
public function __set(string $key, $value = null)
{
// if a set* method exists for this key use that method to insert this value
$method = 'set_' . $key;
if (method_exists($this, $method)) {
$this->$method($value);
} elseif (isset($this->attributes[$key])) {
$this->attributes[$key] = $value;
}
}
protected function set_password(string $value)
{
$this->attributes['password'] = password_hash($value, PASSWORD_BCRYPT);
}
protected function set_last_login(string $value)
{
$this->attributes['last_login'] = new DateTime($value);
}
/**
* Get* Methods
*/
public function __get(string $key)
{
// if a get* method exists for this key use that method to insert this value
if (method_exists($this, $key)) {
return $this->$key();
}
if (isset($this->$key)) {
return $this->$attributes[$key];
}
}
public function last_login($format = 'Y-m-d H:i:s')
{
return $this->attributes['last_login']->format($format);
}
}