1<?php
2
3namespace GeoIp2\Model;
4
5/**
6 * @ignore
7 */
8abstract class AbstractModel implements \JsonSerializable
9{
10    protected $raw;
11
12    /**
13     * @ignore
14     *
15     * @param mixed $raw
16     */
17    public function __construct($raw)
18    {
19        $this->raw = $raw;
20    }
21
22    /**
23     * @ignore
24     *
25     * @param mixed $field
26     */
27    protected function get($field)
28    {
29        if (isset($this->raw[$field])) {
30            return $this->raw[$field];
31        }
32        if (preg_match('/^is_/', $field)) {
33            return false;
34        }
35
36        return null;
37    }
38
39    /**
40     * @ignore
41     *
42     * @param mixed $attr
43     */
44    public function __get($attr)
45    {
46        if ($attr !== 'instance' && property_exists($this, $attr)) {
47            return $this->$attr;
48        }
49
50        throw new \RuntimeException("Unknown attribute: $attr");
51    }
52
53    /**
54     * @ignore
55     *
56     * @param mixed $attr
57     */
58    public function __isset($attr)
59    {
60        return $attr !== 'instance' && isset($this->$attr);
61    }
62
63    public function jsonSerialize()
64    {
65        return $this->raw;
66    }
67}
68