createdAt = new \DateTime('now'); $this->lastActive = new \DateTime('now'); $this->id = $id; $this->l11n = new NullLocalization(); } /** * Get account id. * * @return int Account id * * @since 1.0.0 */ public function getId() : int { return $this->id; } /** * Get localization. * * @return Localization * * @since 1.0.0 */ public function getL11n() : Localization { return $this->l11n; } /** * Set localization. * * @param Localization $l11n Localization * * @return void * * @since 1.0.0 */ public function setL11n(Localization $l11n) /* : void */ { $this->l11n = $l11n; } /** * Get name. * * @return string * * @since 1.0.0 */ public function getName() : string { return $this->login; } /** * Get name1. * * @return string * * @since 1.0.0 */ public function getName1() : string { return $this->name1; } /** * Get name2. * * @return string * * @since 1.0.0 */ public function getName2() : string { return $this->name2; } /** * Get name3. * * @return string * * @since 1.0.0 */ public function getName3() : string { return $this->name3; } /** * Get email. * * @return string * * @since 1.0.0 */ public function getEmail() : string { return $this->email; } /** * Get status. * * AccountStatus * * @return int * * @since 1.0.0 */ public function getStatus() : int { return $this->status; } /** * Get type. * * AccountType * * @return int * * @since 1.0.0 */ public function getType() : int { return $this->type; } /** * Get last activity. * * @return \DateTime * * @since 1.0.0 */ public function getLastActive() : \DateTime { return $this->lastActive ?? $this->getCreatedAt(); } /** * Get created at. * * @return \DateTime * * @since 1.0.0 */ public function getCreatedAt() : \DateTime { return $this->createdAt ?? new \DateTime('NOW'); } /** * Generate password. * * @param string $password Password * * @return void * * @since 1.0.0 */ public function generatePassword(string $password) /* : void */ { $this->password = password_hash($password, PASSWORD_DEFAULT); } /** * Set name. * * @param string $name Name * * @return void * * @since 1.0.0 */ public function setName(string $name) /* : void */ { $this->login = $name; } /** * Set name1. * * @param string $name Name * * @return void * * @since 1.0.0 */ public function setName1(string $name) /* : void */ { $this->name1 = $name; } /** * Set name2. * * @param string $name Name * * @return void * * @since 1.0.0 */ public function setName2(string $name) /* : void */ { $this->name2 = $name; } /** * Set name3. * * @param string $name Name * * @return void * * @since 1.0.0 */ public function setName3(string $name) /* : void */ { $this->name3 = $name; } /** * Set email. * * @param string $email Email * * @return void * * @since 1.0.0 */ public function setEmail(string $email) /* : void */ { if (!Email::isValid($email)) { throw new \InvalidArgumentException(); } $this->email = mb_strtolower($email); } /** * Get status. * * @param int $status Status * * @return void * * @since 1.0.0 */ public function setStatus(int $status) /* : void */ { if (!AccountStatus::isValidValue($status)) { throw new \InvalidArgumentException(); } $this->status = $status; } /** * Get type. * * @param int $type Type * * @return void * * @since 1.0.0 */ public function setType(int $type) /* : void */ { if (!AccountType::isValidValue($type)) { throw new \InvalidArgumentException(); } $this->type = $type; } /** * Update last activity. * * @return void * * @since 1.0.0 */ public function updateLastActive() /* : void */ { $this->lastActive = new \DateTime('NOW'); } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'name' => [ $this->name1, $this->name2, $this->name3, ], 'email' => $this->email, 'login' => $this->login, 'groups' => $this->groups, 'permissions' => $this->permissions, 'type' => $this->type, 'status' => $this->status, ]; } /** * Get string representation. * * @return string * * @since 1.0.0 */ public function __toString() { return json_encode($this->toArray()); } /** * Json serialize. * * @return string * * @since 1.0.0 */ public function jsonSerialize() { return $this->toArray(); } }