mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-17 22:47:10 +02:00
73 lines
1.4 KiB
PHP
73 lines
1.4 KiB
PHP
<?php
|
|
|
|
class User
|
|
{
|
|
protected $userId;
|
|
protected $username;
|
|
protected $email;
|
|
|
|
public function __construct(array $options = null)
|
|
{
|
|
if (is_array($options)) {
|
|
$this->setOptions($options);
|
|
}
|
|
}
|
|
|
|
public function __set($name, $value)
|
|
{
|
|
$method = 'set' . $name;
|
|
if (('mapper' == $name) || !method_exists($this, $method)) {
|
|
throw new Exception('Invalid Offer property');
|
|
}
|
|
$this->$method($value);
|
|
}
|
|
|
|
public function __get($name)
|
|
{
|
|
$method = 'get' . $name;
|
|
if (('mapper' == $name) || !method_exists($this, $method)) {
|
|
throw new Exception('Invalid Offer property');
|
|
}
|
|
return $this->$method();
|
|
}
|
|
|
|
public function setOptions(array $options)
|
|
{
|
|
$methods = get_class_methods($this);
|
|
|
|
foreach ($options as $key => $value) {
|
|
$method = 'set' . ucfirst($key);
|
|
|
|
if (in_array($method, $methods)) {
|
|
$this->$method($value);
|
|
|
|
}
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
public function getUserId() {
|
|
return $this->userId;
|
|
}
|
|
|
|
public function setUserID($userId) {
|
|
$this->userId = $userId;
|
|
}
|
|
|
|
public function getUsername() {
|
|
return $this->username;
|
|
}
|
|
|
|
public function setUsername($username) {
|
|
$this->username = $username;
|
|
}
|
|
|
|
public function getEmail() {
|
|
return $this->email;
|
|
}
|
|
|
|
public function setEmail($email) {
|
|
$this->email = $email;
|
|
}
|
|
|
|
} |