Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DataSet implements DataSetInterface
- {
- private $object;
- private function __construct($object)
- {
- $this->object = $object;
- }
- public static function fromObject($object)
- {
- return new self($object);
- }
- public function getAttributeValue(string $attribute)
- {
- if (!$this->hasAttribute($attribute)) {
- throw new MissingAttributeException('$attribute is missing');
- }
- return get_object_vars($this->object)[$attribute];
- }
- public function hasAttribute(string $attribute): bool
- {
- return array_key_exists($attribute, get_object_vars($this->object));
- }
- }
- class Post
- {
- public string $title;
- public string $description;
- }
- $dataSet = DataSet::fromObject(new Post());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement