From 5bebdce6e88d8c39f82f568893e50a8746a201ad Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 8 May 2013 08:12:09 -0700 Subject: [PATCH] Use camel case for all trait attribute names --- src/GeoIP2/Model/Country.php | 2 +- src/GeoIP2/Model/Omni.php | 3 --- src/GeoIP2/Record/AbstractRecord.php | 7 +++++-- src/GeoIP2/Record/City.php | 2 +- src/GeoIP2/Record/Continent.php | 4 ++-- src/GeoIP2/Record/Country.php | 6 +++--- src/GeoIP2/Record/Location.php | 10 +++++----- src/GeoIP2/Record/RepresentedCountry.php | 4 ++-- src/GeoIP2/Record/Subdivision.php | 4 ++-- src/GeoIP2/Record/Traits.php | 12 ++++++------ 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/GeoIP2/Model/Country.php b/src/GeoIP2/Model/Country.php index 4854af0..41548ac 100644 --- a/src/GeoIP2/Model/Country.php +++ b/src/GeoIP2/Model/Country.php @@ -34,6 +34,6 @@ class Country { if ($var != "instance" && isset($this->$var)) return $this->$var; - throw new RuntimeException("Unknown attribute: $attr"); + throw new \RuntimeException("Unknown attribute: $attr"); } } diff --git a/src/GeoIP2/Model/Omni.php b/src/GeoIP2/Model/Omni.php index b48062b..629611b 100644 --- a/src/GeoIP2/Model/Omni.php +++ b/src/GeoIP2/Model/Omni.php @@ -5,7 +5,4 @@ namespace GeoIP2\Model; class Omni extends CityISPOrg { - public function __construct($raw, $language) { - - } } diff --git a/src/GeoIP2/Record/AbstractRecord.php b/src/GeoIP2/Record/AbstractRecord.php index e1aae72..75679af 100644 --- a/src/GeoIP2/Record/AbstractRecord.php +++ b/src/GeoIP2/Record/AbstractRecord.php @@ -12,8 +12,11 @@ abstract class AbstractRecord public function __get($attr) { $valid = in_array($attr, $this->validAttributes); - if ($valid && isset($this->record[$attr])){ - return $this->record[$attr]; + // XXX - kind of ugly but greatly reduces boilerplate code + $key = strtolower(preg_replace('/([A-Z])/', '_\1', $attr)); + + if ($valid && isset($this->record[$key])){ + return $this->record[$key]; } elseif ($valid) { return null; } else { diff --git a/src/GeoIP2/Record/City.php b/src/GeoIP2/Record/City.php index fe000ec..4606fb7 100644 --- a/src/GeoIP2/Record/City.php +++ b/src/GeoIP2/Record/City.php @@ -4,5 +4,5 @@ namespace GeoIP2\Record; class City extends AbstractPlaceRecord { - protected $validAttribute = Array('confidence', 'geoname_id', 'names'); + protected $validAttribute = Array('confidence', 'geonameId', 'names'); } \ No newline at end of file diff --git a/src/GeoIP2/Record/Continent.php b/src/GeoIP2/Record/Continent.php index 7a1967b..e69166f 100644 --- a/src/GeoIP2/Record/Continent.php +++ b/src/GeoIP2/Record/Continent.php @@ -4,7 +4,7 @@ namespace GeoIP2\Record; class Continent extends AbstractPlaceRecord { - protected $validAttributes = Array('continent_code', - 'geoname_id', + protected $validAttributes = Array('continentCode', + 'geonameId', 'names'); } \ No newline at end of file diff --git a/src/GeoIP2/Record/Country.php b/src/GeoIP2/Record/Country.php index 7af965a..424f2ec 100644 --- a/src/GeoIP2/Record/Country.php +++ b/src/GeoIP2/Record/Country.php @@ -6,7 +6,7 @@ class Country extends AbstractPlaceRecord { protected $validAttributes = Array('confidence', - 'geoname_id', - 'iso_code', - 'names'); + 'geonameId', + 'isoCode', + 'names'); } \ No newline at end of file diff --git a/src/GeoIP2/Record/Location.php b/src/GeoIP2/Record/Location.php index 208ce0e..3f76af7 100644 --- a/src/GeoIP2/Record/Location.php +++ b/src/GeoIP2/Record/Location.php @@ -4,11 +4,11 @@ namespace GeoIP2\Record; class Location extends AbstractRecord { - protected $validAttributes = Array('accuracy_radius', + protected $validAttributes = Array('accuracyRadius', 'latitude', 'longitude', - 'metro_code', - 'postal_code', - 'postal_confidence', - 'time_zone'); + 'metroCode', + 'postalCode', + 'postalConfidence', + 'timeZone'); } \ No newline at end of file diff --git a/src/GeoIP2/Record/RepresentedCountry.php b/src/GeoIP2/Record/RepresentedCountry.php index 9368d84..93d8bef 100644 --- a/src/GeoIP2/Record/RepresentedCountry.php +++ b/src/GeoIP2/Record/RepresentedCountry.php @@ -5,8 +5,8 @@ namespace GeoIP2\Record; class RepresentedCountry extends Country { protected $validAttributes = Array('confidence', - 'geoname_id', - 'iso_code', + 'geonameId', + 'isoCode', 'names', 'type'); } \ No newline at end of file diff --git a/src/GeoIP2/Record/Subdivision.php b/src/GeoIP2/Record/Subdivision.php index dbe5301..581b5a8 100644 --- a/src/GeoIP2/Record/Subdivision.php +++ b/src/GeoIP2/Record/Subdivision.php @@ -5,7 +5,7 @@ namespace GeoIP2\Record; class Subdivision extends AbstractPlaceRecord { protected $validAttributes = Array('confidence', - 'geoname_id', - 'iso_code', + 'geonameId', + 'isoCode', 'names'); } \ No newline at end of file diff --git a/src/GeoIP2/Record/Traits.php b/src/GeoIP2/Record/Traits.php index 6aac032..52816c3 100644 --- a/src/GeoIP2/Record/Traits.php +++ b/src/GeoIP2/Record/Traits.php @@ -4,14 +4,14 @@ namespace GeoIP2\Record; class Traits extends AbstractRecord { - protected $validAttributes = Array('autonomous_system_number', - 'autonomous_system_organization', + protected $validAttributes = Array('autonomousSystemNumber', + 'autonomousSystemOrganization', 'domain', - 'is_anonymous_proxy', - 'is_satellite_provider', + 'isAnonymousProxy', + 'isSatelliteProvider', 'isp', - 'ip_address', + 'ipAddress', 'organization', - 'user_type'); + 'userType'); } \ No newline at end of file