mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-26 09:40:15 +02:00
38 lines
736 B
PHP
38 lines
736 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Structural\DataMapper;
|
|
|
|
class User
|
|
{
|
|
private string $username;
|
|
private string $email;
|
|
|
|
public static function fromState(array $state): User
|
|
{
|
|
// validate state before accessing keys!
|
|
|
|
return new self(
|
|
$state['username'],
|
|
$state['email']
|
|
);
|
|
}
|
|
|
|
public function __construct(string $username, string $email)
|
|
{
|
|
// validate parameters before setting them!
|
|
|
|
$this->username = $username;
|
|
$this->email = $email;
|
|
}
|
|
|
|
public function getUsername(): string
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
public function getEmail(): string
|
|
{
|
|
return $this->email;
|
|
}
|
|
}
|