mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-06 06:57:25 +02:00
Added DataMapper files
This commit is contained in:
73
DataMapper/User.php
Normal file
73
DataMapper/User.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user