nur-sery/nur_src/b/authnz/InvalidUser.php

67 lines
1.2 KiB
PHP

<?php
namespace nur\b\authnz;
use nur\A;
class InvalidUser implements IAuthzUser {
/** @var self */
private static $instance;
static final function with(?string $username=null): self {
if ($username !== null) return new self($username);
if (self::$instance === null) self::$instance = new self();
return self::$instance;
}
function __construct(?string $username=null) {
$this->username = $username;
}
function isValid(): bool {
return false;
}
private $username;
function getUsername(): string {
$username = $this->username;
return $username !== null? $username: "INVALID";
}
function validatePassword(string $password): bool {
return false;
}
function getDisplayName(): ?string {
return $this->username;
}
function getShortName(): ?string {
return $this->username;
}
function getMail(): ?string {
return null;
}
function getRole(): ?string {
return null;
}
function isRole($roles): bool {
return $roles === null || in_array(self::ROLE_ANON, A::with($roles));
}
function isPerm($perm): bool {
return $perm === null;
}
function has($key): bool {
return false;
}
function get($key, $default=null) {
return $default;
}
}