Overview

Namespaces

  • GeoIp2
    • Database
    • Exception
    • Model
    • Record
    • WebService
  • PHP

Classes

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