Added most of the attributes for the City model

This commit is contained in:
Gregory Oschwald 2013-05-07 15:36:20 -07:00
parent 01bf8c2d7c
commit 45228dfad4
3 changed files with 53 additions and 18 deletions

View File

@ -5,15 +5,31 @@ namespace GeoIP2\Model;
class City extends Country
{
//XXX use properties
public $city;
public $location;
public $postal;
public $subdivisions;
private $city;
private $location;
private $postal;
private $subdivisions = Array();
public function __construct($raw, $language)
public function __construct($raw, $languages)
{
$this->city = new \GeoIP2\Record\City($this->get('city'), $languages);
$this->location = new \GeoIP2\Record\Location($this->get('location'));
$this->postal = new \GeoIP2\Record\Postal($this->get('postal'));
parent::__construct($raw, $language);
$this->createSubdivisions($raw, $languages);
parent::__construct($raw, $languages);
}
private function createSubdivisions($raw, $languages) {
if(!isset($raw['subdivisions'])) return;
foreach ($raw['subdivisions'] as $sub) {
array_push($this->subdivisions,
new \GeoIP2\Record\Subdivision($sub, $languages));
}
}
}

View File

@ -4,25 +4,36 @@ namespace GeoIP2\Model;
class Country
{
// XXX - use __get__
public $continent;
public $country;
public $registeredCountry;
public $representedCountry;
public $traits;
public $raw;
private $continent;
private $country;
private $registeredCountry;
private $representedCountry;
private $traits;
private $raw;
public function __construct($raw, $languages) {
$this->raw = $raw;
$this->continent = new \GeoIP2\Record\Continent($this->get('continent'), $languages);
$this->country = new \GeoIP2\Record\Country($this->get('country'), $languages);
$this->registeredCountry = new \GeoIP2\Record\Country($this->get('registered_country'), $languages);
$this->representedCountry = new \GeoIP2\Record\RepresentedCountry($this->get('represented_country'), $languages);
$this->continent = new \GeoIP2\Record\Continent($this->get('continent'),
$languages);
$this->country = new \GeoIP2\Record\Country($this->get('country'),
$languages);
$this->registeredCountry =
new \GeoIP2\Record\Country($this->get('registered_country'), $languages);
$this->representedCountry =
new \GeoIP2\Record\RepresentedCountry($this->get('represented_country'),
$languages);
$this->traits = new \GeoIP2\Record\Traits($this->get('traits'));
}
private function get($field) {
protected function get($field) {
return isset($this->raw[$field]) ? $this->raw[$field] : Array();
}
public function __get ($var)
{
if ($var != "instance" && isset($this->$var)) return $this->$var;
throw new RuntimeException("Unknown attribute: $attr");
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace GeoIP2\Record;
class Postal extends AbstractRecord
{
}