2016-09-22 21:04:16 +02:00

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;
}
}