|
|
|
@ -4,25 +4,53 @@ namespace App\Data;
|
|
|
|
|
|
|
|
|
|
use http\Exception\InvalidArgumentException;
|
|
|
|
|
|
|
|
|
|
const PHONE_NUMBER_REGEXP = "\\+[0-9]+";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base class of a user account.
|
|
|
|
|
* Contains the private information that we don't want
|
|
|
|
|
* to share to other users, or non-needed public information
|
|
|
|
|
*/
|
|
|
|
|
class Account {
|
|
|
|
|
/**
|
|
|
|
|
* @var string $email account's mail address
|
|
|
|
|
*/
|
|
|
|
|
private string $email;
|
|
|
|
|
/**
|
|
|
|
|
* @var string account's phone number.
|
|
|
|
|
* its format is specified by the {@link PHONE_NUMBER_REGEXP} constant
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
private string $phoneNumber;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var AccountUser account's public and shared information
|
|
|
|
|
*/
|
|
|
|
|
private AccountUser $user;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array account's teams
|
|
|
|
|
*/
|
|
|
|
|
private array $teams;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int account's unique identifier
|
|
|
|
|
*/
|
|
|
|
|
private int $id;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $email
|
|
|
|
|
* @param string $phoneNumber
|
|
|
|
|
* @param AccountUser $user
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(string $email, string $phoneNumber, AccountUser $user, array $teams) {
|
|
|
|
|
public function __construct(string $email, string $phoneNumber, AccountUser $user, array $teams, int $id) {
|
|
|
|
|
$this->email = $email;
|
|
|
|
|
$this->phoneNumber = $phoneNumber;
|
|
|
|
|
$this->user = $user;
|
|
|
|
|
$this->teams = $teams;
|
|
|
|
|
$this->id = $id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
@ -51,11 +79,21 @@ class Account {
|
|
|
|
|
* @param string $phoneNumber
|
|
|
|
|
*/
|
|
|
|
|
public function setPhoneNumber(string $phoneNumber): void {
|
|
|
|
|
if (!filter_var($phoneNumber, FILTER_VALIDATE_REGEXP, "\\+[0-9]+")) {
|
|
|
|
|
if (!filter_var($phoneNumber, FILTER_VALIDATE_REGEXP, PHONE_NUMBER_REGEXP)) {
|
|
|
|
|
throw new InvalidArgumentException("Invalid phone number");
|
|
|
|
|
}
|
|
|
|
|
$this->phoneNumber = $phoneNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getId(): int {
|
|
|
|
|
return $this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTeams(): array {
|
|
|
|
|
return $this->teams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getUser(): AccountUser {
|
|
|
|
|
return $this->user;
|
|
|
|
|
}
|
|
|
|
|
}
|