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\Record;
 4 
 5 use GeoIp2\Compat\JsonSerializable;
 6 
 7 abstract class AbstractRecord implements JsonSerializable
 8 {
 9     private $record;
10 
11     /**
12      * @ignore
13      */
14     public function __construct($record)
15     {
16         $this->record = isset($record) ? $record : array();
17     }
18 
19     /**
20      * @ignore
21      */
22     public function __get($attr)
23     {
24         // XXX - kind of ugly but greatly reduces boilerplate code
25         $key = $this->attributeToKey($attr);
26 
27         if ($this->__isset($attr)) {
28             return $this->record[$key];
29         } elseif ($this->validAttribute($attr)) {
30             if (preg_match('/^is_/', $key)) {
31                 return false;
32             } else {
33                 return null;
34             }
35         } else {
36             throw new \RuntimeException("Unknown attribute: $attr");
37         }
38     }
39 
40     public function __isset($attr)
41     {
42         return $this->validAttribute($attr) &&
43              isset($this->record[$this->attributeToKey($attr)]);
44     }
45 
46     private function attributeToKey($attr)
47     {
48         return strtolower(preg_replace('/([A-Z])/', '_\1', $attr));
49     }
50 
51     private function validAttribute($attr)
52     {
53         return in_array($attr, $this->validAttributes);
54     }
55 
56     public function jsonSerialize()
57     {
58         return $this->record;
59     }
60 }
61 
GeoIP2 PHP API v2.4.4 API documentation generated by ApiGen