city = new \GeoIp2\Record\City($this->get('city'), $locales); $this->location = new \GeoIp2\Record\Location($this->get('location')); $this->postal = new \GeoIp2\Record\Postal($this->get('postal')); $this->createSubdivisions($raw, $locales); } private function createSubdivisions($raw, $locales) { if (!isset($raw['subdivisions'])) { return; } foreach ($raw['subdivisions'] as $sub) { array_push( $this->subdivisions, new \GeoIp2\Record\Subdivision($sub, $locales) ); } } /** * @ignore * * @param mixed $attr */ public function __get($attr) { if ($attr === 'mostSpecificSubdivision') { return $this->$attr(); } return parent::__get($attr); } /** * @ignore * * @param mixed $attr */ public function __isset($attr) { if ($attr === 'mostSpecificSubdivision') { // We always return a mostSpecificSubdivision, even if it is the // empty subdivision return true; } return parent::__isset($attr); } private function mostSpecificSubdivision() { return empty($this->subdivisions) ? new \GeoIp2\Record\Subdivision([], $this->locales) : end($this->subdivisions); } }