mirror of
https://github.com/igorsimdyanov/php8.git
synced 2025-08-16 17:36:48 +00:00
Глава 34: черновик главы
This commit is contained in:
39
exceptions/user_own_exceptions.php
Normal file
39
exceptions/user_own_exceptions.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require_once 'attribute_exception.php';
|
||||
require_once 'password_exception.php';
|
||||
|
||||
class User
|
||||
{
|
||||
public function __construct(
|
||||
private string $email,
|
||||
private string $password,
|
||||
private ?string $first_name = null,
|
||||
private ?string $last_name = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function __get(string $index) : ?string
|
||||
{
|
||||
if($index == 'password') {
|
||||
throw new PasswordException;
|
||||
}
|
||||
if (isset($this->$index)) {
|
||||
return $this->$index;
|
||||
} else {
|
||||
throw new AttributeException($index);
|
||||
}
|
||||
}
|
||||
public function __set(string $index, string $value) : void
|
||||
{
|
||||
if (isset($this->$index)) {
|
||||
$this->$index = $value;
|
||||
}
|
||||
else {
|
||||
throw new AttributeException($index);
|
||||
}
|
||||
}
|
||||
public function isPasswordCorrect($password)
|
||||
{
|
||||
return $this->password == $password;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user