A library to assist with country detection and country codes
This library is compatible with PHP version 7.2, 7.3, 7.4, 8.0, 8.1, 8.2 and 8.3
This library has no dependencies.
Installation is simple using composer.
composer require kusabi/countriesOr simply add it to your composer.json file
{
"require": {
"kusabi/countries": "^1.0"
}
}This library follows PSR-1 & PSR-2 standards.
Before pushing any changes, please ensure the unit tests are all passing.
If possible, feel free to improve coverage in a separate commit.
vendor/bin/phpunitBefore pushing, please ensure you have run the code sniffer. Only run it using the lowest support PHP version (7.2)
vendor/bin/php-cs-fixer fixBefore pushing, please ensure you have run the static analyses tool.
vendor/bin/phanBefore pushing, please ensure you have checked the benchmarks and ensured that your code has not introduced any slowdowns.
Feel free to speed up existing code, in a separate commit.
Feel free to add more benchmarks for greater coverage, in a separate commit.
vendor/bin/phpbench run --report=speed
vendor/bin/phpbench run --report=speed --output=markdown
vendor/bin/phpbench run --report=speed --filter=benchNetFromTax --iterations=50 --revs=50000
vendor/bin/phpbench xdebug:profile
vendor/bin/phpbench xdebug:profile --gui$countries = new \Kusabi\Countries\Countries();
// Getting countries from the iterable class
$uk = $countries['gb'];
$uk = $countries['united kingdom'];
$uk = $countries->get('gbr')
$uk = $countries->getFromCallback(function (\Kusabi\Countries\Country $country) {
return $country->getPhone() === '44';
});
// Cycle through all countries
foreach ($countries as $country) {
echo $country->getName();
echo $country->getAlpha2();
echo $country->getAlpha3();
echo $country->getNumeric();
echo $country->getContinent();
echo $country->getCapital();
echo $country->getPhone();
echo $country->getTimezone();
echo $country->getAlternativeNames();
}