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