GeoIP2 PHP API v2.4.4
  • Namespace
  • Class

Namespaces

  • GeoIp2
    • Database
    • Exception
    • Model
    • Record
    • WebService
  • MaxMind
    • Db
      • Reader
  • PHP

Classes

  • GeoIp2\Database\Reader
  • GeoIp2\Model\AnonymousIp
  • GeoIp2\Model\City
  • GeoIp2\Model\ConnectionType
  • GeoIp2\Model\Country
  • GeoIp2\Model\Domain
  • GeoIp2\Model\Enterprise
  • GeoIp2\Model\Insights
  • GeoIp2\Model\Isp
  • GeoIp2\Record\AbstractPlaceRecord
  • GeoIp2\Record\AbstractRecord
  • GeoIp2\Record\City
  • GeoIp2\Record\Continent
  • GeoIp2\Record\Country
  • GeoIp2\Record\Location
  • GeoIp2\Record\MaxMind
  • GeoIp2\Record\Postal
  • GeoIp2\Record\RepresentedCountry
  • GeoIp2\Record\Subdivision
  • GeoIp2\Record\Traits
  • GeoIp2\WebService\Client
  • MaxMind\Db\Reader
  • MaxMind\Db\Reader\Decoder
  • MaxMind\Db\Reader\Metadata
  • MaxMind\Db\Reader\Util

Interfaces

  • GeoIp2\ProviderInterface

Exceptions

  • BadFunctionCallException
  • BadMethodCallException
  • Exception
  • GeoIp2\Exception\AddressNotFoundException
  • GeoIp2\Exception\AuthenticationException
  • GeoIp2\Exception\GeoIp2Exception
  • GeoIp2\Exception\HttpException
  • GeoIp2\Exception\InvalidRequestException
  • GeoIp2\Exception\OutOfQueriesException
  • InvalidArgumentException
  • LogicException
  • MaxMind\Db\Reader\InvalidDatabaseException
  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-read \GeoIp2\Record\City $city City data for the requested IP
 13  * address.
 14  *
 15  * @property-read \GeoIp2\Record\Continent $continent Continent data for the
 16  * requested IP address.
 17  *
 18  * @property-read \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-read \GeoIp2\Record\Location $location Location data for the
 23  * requested IP address.
 24  *
 25  * @property-read \GeoIp2\Record\Postal $postal Postal data for the
 26  * requested IP address.
 27  *
 28  * @property-read \GeoIp2\Record\MaxMind $maxmind Data related to your MaxMind
 29  * account.
 30  *
 31  * @property-read \GeoIp2\Record\Country $registeredCountry Registered country
 32  * data for the requested IP address. This record represents the country
 33  * where the ISP has registered a given IP block and may differ from the
 34  * user's country.
 35  *
 36  * @property-read \GeoIp2\Record\RepresentedCountry $representedCountry
 37  * Represented country data for the requested IP address. The represented
 38  * country is used for things like military bases. It is only present when
 39  * the represented country differs from the country.
 40  *
 41  * @property-read array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
 42  * objects representing the country subdivisions for the requested IP
 43  * address. The number and type of subdivisions varies by country, but a
 44  * subdivision is typically a state, province, county, etc. Subdivisions
 45  * are ordered from most general (largest) to most specific (smallest).
 46  * If the response did not contain any subdivisions, this method returns
 47  * an empty array.
 48  *
 49  * @property-read \GeoIp2\Record\Subdivision $mostSpecificSubdivision An  object
 50  * representing the most specific subdivision returned. If the response
 51  * did not contain any subdivisions, this method returns an empty
 52  * {@link \GeoIp2\Record\Subdivision} object.
 53  *
 54  * @property-read \GeoIp2\Record\Traits $traits Data for the traits of the
 55  * requested IP address.
 56  */
 57 class City extends Country
 58 {
 59     /**
 60      * @ignore
 61      */
 62     protected $city;
 63     /**
 64      * @ignore
 65      */
 66     protected $location;
 67     /**
 68      * @ignore
 69      */
 70     protected $postal;
 71     /**
 72      * @ignore
 73      */
 74     protected $subdivisions = array();
 75 
 76     /**
 77      * @ignore
 78      */
 79     public function __construct($raw, $locales = array('en'))
 80     {
 81         parent::__construct($raw, $locales);
 82 
 83         $this->city = new \GeoIp2\Record\City($this->get('city'), $locales);
 84         $this->location = new \GeoIp2\Record\Location($this->get('location'));
 85         $this->postal = new \GeoIp2\Record\Postal($this->get('postal'));
 86 
 87         $this->createSubdivisions($raw, $locales);
 88     }
 89 
 90     private function createSubdivisions($raw, $locales)
 91     {
 92         if (!isset($raw['subdivisions'])) {
 93             return;
 94         }
 95 
 96         foreach ($raw['subdivisions'] as $sub) {
 97             array_push(
 98                 $this->subdivisions,
 99                 new \GeoIp2\Record\Subdivision($sub, $locales)
100             );
101         }
102     }
103 
104     /**
105      * @ignore
106      */
107     public function __get($attr)
108     {
109         if ($attr == 'mostSpecificSubdivision') {
110             return $this->$attr();
111         } else {
112             return parent::__get($attr);
113         }
114     }
115 
116     /**
117      * @ignore
118      */
119     public function __isset($attr)
120     {
121         if ($attr == 'mostSpecificSubdivision') {
122             // We always return a mostSpecificSubdivision, even if it is the
123             // empty subdivision
124             return true;
125         } else {
126             return parent::__isset($attr);
127         }
128     }
129 
130     private function mostSpecificSubdivision()
131     {
132         return empty($this->subdivisions) ?
133             new \GeoIp2\Record\Subdivision(array(), $this->locales) :
134             end($this->subdivisions);
135     }
136 }
137 
GeoIP2 PHP API v2.4.4 API documentation generated by ApiGen