Commit 3f7fff19 authored by Tino Goratsch's avatar Tino Goratsch

closes #57

- Updated `giggsey/locale` library to version 1.3 to take advantage of the new functionality for the localized country list
parent 8abd5e91
......@@ -6,6 +6,8 @@
namespace ACP3\Core\I18n;
use Giggsey\Locale\Locale;
class CountryList
{
/**
......@@ -16,6 +18,10 @@ class CountryList
* @var null|array
*/
private $countries = null;
/**
* @var null|array
*/
private $supportedLocales = null;
/**
* Country constructor.
......@@ -42,36 +48,33 @@ class CountryList
private function cacheWorldCountries()
{
$basePath = ACP3_ROOT_DIR . 'vendor/giggsey/locale/data/';
$supportedLocales = include $basePath . '_list.php';
$this->countries = [];
if ($this->isSupportedLocale($supportedLocales)) {
$paths = [
$basePath . $this->getTransformedLocale() . '.php',
$basePath . $this->translator->getShortIsoCode() . '.php'
];
foreach ($paths as $path) {
if (is_file($path)) {
$this->countries = include $path;
break;
}
}
asort($this->countries, SORT_STRING);
$locales = [
$this->getTransformedLocale(),
$this->translator->getShortIsoCode()
];
foreach ($locales as $locale) {
if ($this->isSupportedLocale($locale)) {
$this->countries = Locale::getAllCountriesForLocale($locale);
}
}
asort($this->countries, SORT_STRING);
}
/**
* @param array $supportedLocales
* @param string $locale
* @return bool
*/
private function isSupportedLocale(array $supportedLocales)
private function isSupportedLocale($locale)
{
$localeAndRegion = $this->getTransformedLocale();
if ($this->supportedLocales === null) {
$this->supportedLocales = Locale::getSupportedLocales();
}
return array_key_exists($localeAndRegion, $supportedLocales)
|| array_key_exists($this->translator->getShortIsoCode(), $supportedLocales);
return in_array($locale, $this->supportedLocales);
}
/**
......
......@@ -32,7 +32,7 @@ class CountryListTest extends \PHPUnit_Framework_TestCase
public function testValidLocale()
{
$this->translatorMock->expects($this->exactly(6))
$this->translatorMock->expects($this->exactly(3))
->method('getLocale')
->willReturn('en_US');
......
......@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [4.11.0] - 2017-04-07
## [Unreleased] - 2017-xx-xx
### Changed
- Updated `giggsey/locale` library to version 1.3 to take advantage of the new functionality for the localized country list
## [4.11.1] - 2017-04-07
### Fixed
- Fixed the required version of the minify library of the ACP3 core framework
......
......@@ -802,16 +802,16 @@
},
{
"name": "giggsey/locale",
"version": "1.2",
"version": "1.3",
"source": {
"type": "git",
"url": "https://github.com/giggsey/Locale.git",
"reference": "640911276e24729c276ea6206a4e0318474d24f5"
"reference": "e6eb1883c1452df7734a03fb183a2ec5175c16f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/giggsey/Locale/zipball/640911276e24729c276ea6206a4e0318474d24f5",
"reference": "640911276e24729c276ea6206a4e0318474d24f5",
"url": "https://api.github.com/repos/giggsey/Locale/zipball/e6eb1883c1452df7734a03fb183a2ec5175c16f2",
"reference": "e6eb1883c1452df7734a03fb183a2ec5175c16f2",
"shasum": ""
},
"require": {
......@@ -847,7 +847,7 @@
}
],
"description": "Locale functions required by libphonenumber-for-php",
"time": "2017-03-21T16:08:07+00:00"
"time": "2017-04-07T18:45:42+00:00"
},
{
"name": "google/recaptcha",
......@@ -2586,16 +2586,16 @@
},
{
"name": "friendsofphp/php-cs-fixer",
"version": "v2.2.0",
"version": "v2.2.1",
"source": {
"type": "git",
"url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git",
"reference": "d6f17423412d33df6b69c9aaf12037b91703533b"
"reference": "aff95e090fdaf57c20d32d7728b090f2015bfcef"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/d6f17423412d33df6b69c9aaf12037b91703533b",
"reference": "d6f17423412d33df6b69c9aaf12037b91703533b",
"url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/aff95e090fdaf57c20d32d7728b090f2015bfcef",
"reference": "aff95e090fdaf57c20d32d7728b090f2015bfcef",
"shasum": ""
},
"require": {
......@@ -2659,7 +2659,7 @@
}
],
"description": "A tool to automatically fix PHP code style",
"time": "2017-03-31T16:16:30+00:00"
"time": "2017-04-07T15:22:27+00:00"
},
{
"name": "guzzlehttp/guzzle",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment