Overview

Namespaces

  • GeoIP2
    • Exception
    • Model
    • Record
    • WebService
  • PHP

Classes

  • City
  • CityIspOrg
  • Country
  • Omni
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace GeoIP2\Model;
  4: 
  5: /**
  6:  * This class provides a model for the data returned by the GeoIP2
  7:  * City end point.
  8:  *
  9:  * The only difference between the City, City/ISP/Org, and Omni model
 10:  * classes is which fields in each record may be populated. See
 11:  * http://dev.maxmind.com/geoip/geoip2/web-services more details.
 12:  *
 13:  * @property \GeoIP2\Record\City $city City data for the requested IP
 14:  * address.
 15:  *
 16:  * @property \GeoIP2\Record\Continent $continent Continent data for the
 17:  * requested IP address.
 18:  *
 19:  * @property \GeoIP2\Record\Country $country Country data for the requested
 20:  * IP address. This object represents the country where MaxMind believes the
 21:  * end user is located.
 22:  *
 23:  * @property \GeoIP2\Record\Location $location Location data for the
 24:  * requested IP address.
 25:  *
 26:  * @property \GeoIP2\Record\MaxMind $maxmind Data related to your MaxMind
 27:  * account.
 28:  *
 29:  * @property \GeoIP2\Record\Country $registeredCountry Registered country
 30:  * data for the requested IP address. This record represents the country
 31:  * where the ISP has registered a given IP block in and may differ from the
 32:  * user's country.
 33:  *
 34:  * @property \GeoIP2\Record\RepresentedCountry $representedCountry
 35:  * Represented country data for the requested IP address. The represented
 36:  * country is used for things like military bases or embassies. It is only
 37:  * present when the represented country differs from the country.
 38:  *
 39:  * @property array $subdivisions An array of {@link \GeoIP2\Record\Subdivision}
 40:  * objects representing the country subdivisions for the requested IP
 41:  * address. The number and type of subdivisions varies by country, but a
 42:  * subdivision is typically a state, province, county, etc. Subdivisions
 43:  * are ordered from most general (largest) to most specific (smallest).
 44:  * If the response did not contain any subdivisions, this method returns
 45:  * an empty array.
 46:  *
 47:  * @property \GeoIP2\Record\Subdivision $mostSpecificSubdivision An  object
 48:  * representing the most specific subdivision returned. If the response
 49:  * did not contain any subdivisions, this method returns an empty
 50:  * {@link \GeoIP2\Record\Subdivision} object.
 51:  *
 52:  * @property \GeoIP2\Record\Traits $traits Data for the traits of the
 53:  * requested IP address.
 54:  */
 55: class City extends Country
 56: {
 57:     /**
 58:      * @ignore
 59:      */
 60:     protected $city;
 61:     /**
 62:      * @ignore
 63:      */
 64:     protected $location;
 65:     /**
 66:      * @ignore
 67:      */
 68:     protected $postal;
 69:     /**
 70:      * @ignore
 71:      */
 72:     protected $subdivisions = array();
 73: 
 74:     /**
 75:      * @ignore
 76:      */
 77:     public function __construct($raw, $languages)
 78:     {
 79:         parent::__construct($raw, $languages);
 80: 
 81:         $this->city = new \GeoIP2\Record\City($this->get('city'), $languages);
 82:         $this->location = new \GeoIP2\Record\Location($this->get('location'));
 83:         $this->postal = new \GeoIP2\Record\Postal($this->get('postal'));
 84: 
 85:         $this->createSubdivisions($raw, $languages);
 86:     }
 87: 
 88:     private function createSubdivisions($raw, $languages)
 89:     {
 90:         if (!isset($raw['subdivisions'])) {
 91:             return;
 92:         }
 93: 
 94:         foreach ($raw['subdivisions'] as $sub) {
 95:             array_push(
 96:                 $this->subdivisions,
 97:                 new \GeoIP2\Record\Subdivision($sub, $languages)
 98:             );
 99:         }
100:     }
101: 
102:     /**
103:      * @ignore
104:      */
105:     public function __get($attr)
106:     {
107:         if ($attr == 'mostSpecificSubdivision') {
108:             return $this->$attr();
109:         } else {
110:             return parent::__get($attr);
111:         }
112:     }
113: 
114:     private function mostSpecificSubdivision()
115:     {
116:         return empty($this->subdivisions)?
117:             new \GeoIP2\Record\Subdivision(array(), $this->languages):
118:             end($this->subdivisions);
119:     }
120: }
121: 
API documentation generated by ApiGen 2.8.0