Use camel case for all trait attribute names

This commit is contained in:
Gregory Oschwald 2013-05-08 08:12:09 -07:00
parent fc3e67969d
commit 5bebdce6e8
10 changed files with 27 additions and 27 deletions

View File

@ -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");
}
}

View File

@ -5,7 +5,4 @@ namespace GeoIP2\Model;
class Omni extends CityISPOrg
{
public function __construct($raw, $language) {
}
}

View File

@ -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 {

View File

@ -4,5 +4,5 @@ namespace GeoIP2\Record;
class City extends AbstractPlaceRecord
{
protected $validAttribute = Array('confidence', 'geoname_id', 'names');
protected $validAttribute = Array('confidence', 'geonameId', 'names');
}

View File

@ -4,7 +4,7 @@ namespace GeoIP2\Record;
class Continent extends AbstractPlaceRecord
{
protected $validAttributes = Array('continent_code',
'geoname_id',
protected $validAttributes = Array('continentCode',
'geonameId',
'names');
}

View File

@ -6,7 +6,7 @@ class Country extends AbstractPlaceRecord
{
protected $validAttributes = Array('confidence',
'geoname_id',
'iso_code',
'names');
'geonameId',
'isoCode',
'names');
}

View File

@ -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');
}

View File

@ -5,8 +5,8 @@ namespace GeoIP2\Record;
class RepresentedCountry extends Country
{
protected $validAttributes = Array('confidence',
'geoname_id',
'iso_code',
'geonameId',
'isoCode',
'names',
'type');
}

View File

@ -5,7 +5,7 @@ namespace GeoIP2\Record;
class Subdivision extends AbstractPlaceRecord
{
protected $validAttributes = Array('confidence',
'geoname_id',
'iso_code',
'geonameId',
'isoCode',
'names');
}

View File

@ -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');
}