Add support for named records. Create all the objects for Country model
This commit is contained in:
		
							parent
							
								
									531e11f3e2
								
							
						
					
					
						commit
						01bf8c2d7c
					
				@ -7,14 +7,22 @@ class Country
 | 
			
		||||
  // XXX - use __get__
 | 
			
		||||
  public $continent;
 | 
			
		||||
  public $country;
 | 
			
		||||
  public $registered_country;
 | 
			
		||||
  public $represented_country;
 | 
			
		||||
  public $registeredCountry;
 | 
			
		||||
  public $representedCountry;
 | 
			
		||||
  public $traits;
 | 
			
		||||
  public $raw;
 | 
			
		||||
 | 
			
		||||
  public function __construct($raw, $language) {
 | 
			
		||||
    $this->country = new \GeoIP2\Record\Country($raw['country']);
 | 
			
		||||
 | 
			
		||||
  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->traits = new \GeoIP2\Record\Traits($this->get('traits'));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private function get($field) {
 | 
			
		||||
    return isset($this->raw[$field]) ? $this->raw[$field] : Array();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,4 +5,17 @@ namespace GeoIP2\Record;
 | 
			
		||||
class Country extends AbstractPlaceRecord
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  private $languages;
 | 
			
		||||
 | 
			
		||||
  public function __construct($record, $languages){
 | 
			
		||||
    $this->languages = $languages;
 | 
			
		||||
    parent::__construct($record);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public function name() {
 | 
			
		||||
    foreach($this->languages as $language) {
 | 
			
		||||
      if (isset($this->names[$language])) return $this->names[$language];
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -16,14 +16,14 @@ class Client
 | 
			
		||||
 | 
			
		||||
  private $user_id;
 | 
			
		||||
  private $license_key;
 | 
			
		||||
  private $language;
 | 
			
		||||
  private $languages;
 | 
			
		||||
  private $base_uri = 'https://geoip.maxmind.com/geoip/v2.0';
 | 
			
		||||
 | 
			
		||||
  public function __construct($user_id, $license_key, $language='en')
 | 
			
		||||
  public function __construct($user_id, $license_key, $languages=array('en'))
 | 
			
		||||
  {
 | 
			
		||||
    $this->user_id = $user_id;
 | 
			
		||||
    $this->license_key = $license_key;
 | 
			
		||||
    $this->language = $language;
 | 
			
		||||
    $this->languages = $languages;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public function city($ip_address = 'me')
 | 
			
		||||
@ -62,7 +62,7 @@ class Client
 | 
			
		||||
    if ($response->isSuccessful()) {
 | 
			
		||||
      $body = $this->handleSuccess($response, $uri);
 | 
			
		||||
      $class = "GeoIP2\\Model\\" . $class;
 | 
			
		||||
      return new $class($body, $this->language);
 | 
			
		||||
      return new $class($body, $this->languages);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user