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