mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-10 16:04:57 +02:00
51 lines
828 B
PHP
51 lines
828 B
PHP
<?php
|
|
|
|
namespace DesignPatterns\Structural\DataMapper;
|
|
|
|
class User
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $username;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $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;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getUsername()
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getEmail()
|
|
{
|
|
return $this->email;
|
|
}
|
|
}
|