| @@ -1,0 +1,28 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +declare(strict_types=1); | |
| 4 | + | |
| 5 | +namespace Metricool\Http\Metricool\DTOs; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * DTO class to store arrays into an object | |
| 9 | + * Dynamically access properties through magic method. | |
| 10 | + * You can define an accessor with (for example) getCountryAttribute() | |
| 11 | + * $dto->country will call the getCountryAttribute accessor method | |
| 12 | + */ | |
| 13 | +abstract class DTO | |
| 14 | +{ | |
| 15 | + /** | |
| 16 | + * @return null|mixed | |
| 17 | + */ | |
| 18 | + public function __get(string $key) | |
| 19 | + { | |
| 20 | + $method = 'get' . ucfirst($key) . 'Attribute'; | |
| 21 | + | |
| 22 | + if (method_exists($this, $method)) { | |
| 23 | + return $this->$method(); | |
| 24 | + } | |
| 25 | + | |
| 26 | + return null; | |
| 27 | + } | |
| 28 | +} | |