| 1 | <?php  | 
            ||
| 7 | class Item implements IItem  | 
            ||
| 8 | {
 | 
            ||
| 9 | protected $url = '';  | 
            ||
| 10 | |||
| 11 | protected $title = null;  | 
            ||
| 12 | |||
| 13 | protected $description = null;  | 
            ||
| 14 | |||
| 15 | 7 | public function __construct(array $data)  | 
            |
| 19 | |||
| 20 | |||
| 21 | 7 | protected function fromArray(array $data)  | 
            |
| 22 |     {
 | 
            ||
| 23 | 7 |         foreach($data as $key => $value) {
 | 
            |
| 24 | 6 |             if (!property_exists($this, $key)) {
 | 
            |
| 25 | 1 |                 throw new InvalidArgumentException("Invalid search result item property: {$key}");
 | 
            |
| 26 | }  | 
            ||
| 27 | |||
| 28 | 5 | $validatorMethod = 'validate' . ucfirst($key);  | 
            |
| 29 | 5 |             if (method_exists($this, $validatorMethod)) {
 | 
            |
| 30 | 5 |                 $this->{$validatorMethod}($value);
 | 
            |
| 31 | }  | 
            ||
| 32 | |||
| 33 | 4 |             $this->{$key} = $value;
 | 
            |
| 34 | }  | 
            ||
| 35 | 5 | }  | 
            |
| 36 | |||
| 37 | |||
| 38 | 1 | public function toArray()  | 
            |
| 46 | |||
| 47 | |||
| 48 | |||
| 49 | 5 | protected function validateUrl($url)  | 
            |
| 55 | |||
| 56 | |||
| 57 | 1 | public function __toString()  | 
            |
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | }  | 
            ||
| 65 |