Skip to content

Commit

Permalink
Merge pull request #8 from paulboenisch/master
Browse files Browse the repository at this point in the history
adding Kosovo to country list when iso switch is false
  • Loading branch information
sameer-shelavale authored Feb 12, 2019
2 parents d5faa8e + 1d9078d commit 1c9a4bf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/*
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Get simple key-value array by default it returns alpha2 => name pairs
$countries = CountriesArray::get();
```

Include non iso countries:
```
$countries = CountriesArray::iso(false)->get();
```

Get key values pairs

```
Expand Down
48 changes: 46 additions & 2 deletions src/CountriesArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,50 @@ class CountriesArray{
"ZW" => array( 'alpha2'=>'ZW', 'alpha3'=>'ZWE', 'num'=>'716', 'isd'=> '263', "name" => "Zimbabwe", "continent" => "Africa")
);

/**
* Non iso countries
* @var array
*/
public static $countries_non_iso = array(
"XK" => array( 'alpha2'=>'XK', 'alpha3'=>'KOS', 'num'=>'383', 'isd'=> '383', "name" => "Kosovo", "continent" => "Europe", ),
);

/**
* CountriesArray constructor.
* @param boolean $iso
* @author Paul Bönisch - <paul.boenisch@umwerk.net>
*/
public function __construct($iso)
{
if(!$iso){
self::$countries = array_merge(self::$countries, self::$countries_non_iso);
}
}

/**
* Returns countries array depending on iso flag
* @param bool $iso
* @return array
* @author Paul Bönisch - <paul.boenisch@umwerk.net>
*/
public static function getCountries($iso = true){
$result = self::$countries;
if(!$iso){
$result = array_merge($result, self::$countries_non_iso);
}

return $result;
}

/**
* Returns instance of ContriesArray with $iso property according to $value parameter
* @param $value
* @return CountriesArray
* @author Paul Bönisch - <paul.boenisch@umwerk.net>
*/
public static function iso($value){
return new CountriesArray($value);
}

/*
* function get()
Expand Down Expand Up @@ -379,15 +423,15 @@ public static function getFromContinent( $keyField = 'alpha2', $requestedField =
if ( $continent ) {
if ( $country['continent'] == $continent ) {
$result[ $country[ $keyField ] ] = $country[ $requestedField ];
}
}
} else {
$result[ $country[ $keyField ] ] = $country[ $requestedField ];
}
} else {
if ( $continent ) {
if ( $country['continent'] == $continent ) {
$result[] = $country[ $requestedField ];
}
}
} else {
$result[] = $country[ $requestedField ];
}
Expand Down

0 comments on commit 1c9a4bf

Please sign in to comment.