Last active
August 20, 2018 08:21
-
-
Save breadlesscode/aaaa0c6496781bc9f0c650d5ee889ca5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class AbstractDto | |
{ | |
/** | |
* here the dto stores all the object specific data | |
* | |
* @var \ArrayObject | |
*/ | |
protected $data; | |
/** | |
* this are all attributes that this DTO can have | |
* | |
* @var array | |
*/ | |
protected $attributes = []; | |
/** | |
* AbstractDto constructor. | |
*/ | |
public function __construct() | |
{ | |
$this->data = new \ArrayObject(); | |
} | |
/** | |
* @return \ArrayObject | |
*/ | |
public function toArray() | |
{ | |
return $this->data; | |
} | |
/** | |
* @param $name | |
* @return mixed|null | |
*/ | |
public function __get($name) | |
{ | |
if (!$this->data->offsetExists($name)) { | |
return null; | |
} | |
return $this->data[$name]; | |
} | |
/** | |
* @param $name | |
* @param $value | |
* @return bool | |
*/ | |
public function __set($name, $value) | |
{ | |
if (!in_array($name, $this->attributes)) { | |
return false; | |
} | |
$this->data[$name] = $value; | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment