User: add __toString() magic method

This commit is contained in:
Benjamin Renard 2023-02-25 14:49:06 +01:00
parent a4d2e3369c
commit 33fcd6a92c
2 changed files with 11 additions and 1 deletions

View file

@ -83,4 +83,14 @@ class User {
);
}
/**
* Magic method to allow pretty cast to string
* @return string
*/
public function __toString() {
if (isset($this -> name))
return sprintf('%s (%s)', $this -> name, $this -> username);
return $this -> namename;
}
}

View file

@ -163,7 +163,7 @@ class Log {
$_SERVER['REMOTE_ADDR'],
);
if (Auth::enabled())
$msg[] = (Auth::user()?Auth::user()->username:'anonymous');
$msg[] = (Auth::user()?Auth::user():'anonymous');
$msg[] = $level;
$msg[] = $message;
$msg = implode(' - ', $msg)."\n";