Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorMatthieu Napoli <matthieu@mnapoli.fr>2014-12-31 03:57:34 +0300
committerMatthieu Napoli <matthieu@mnapoli.fr>2015-01-09 00:13:30 +0300
commit6245e0f77046614391a03ba18b2bc530d9b1b1a7 (patch)
tree9ac35162a87f5af593eb99bda9ea9d313ff48cf2 /core
parent8f342d0fb3f5661cb7fc1cafeabf93684ac478f8 (diff)
Created data provider classes in a new Intl component
Less code in `Piwik\Common`, less static classes, more isolated components.
Diffstat (limited to 'core')
-rw-r--r--core/Common.php49
-rw-r--r--core/Intl/Data/Provider/LanguageDataProvider.php45
-rw-r--r--core/Intl/Data/Provider/RegionDataProvider.php49
3 files changed, 121 insertions, 22 deletions
diff --git a/core/Common.php b/core/Common.php
index ac913d97ea..dcadaa2d49 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -9,6 +9,9 @@
namespace Piwik;
use Exception;
+use Piwik\Container\StaticContainer;
+use Piwik\Intl\Data\Provider\LanguageDataProvider;
+use Piwik\Intl\Data\Provider\RegionDataProvider;
use Piwik\Plugins\UserCountry\LocationProvider\DefaultProvider;
use Piwik\Tracker;
use Piwik\Tracker\Cache as TrackerCache;
@@ -750,13 +753,15 @@ class Common
* @see core/DataFiles/Countries.php
*
* @return array Array of 3 letter continent codes
+ *
+ * @deprecated Use Piwik\Intl\Data\Provider\RegionDataProvider instead.
+ * @see \Piwik\Intl\Data\Provider\RegionDataProvider::getContinentList()
*/
public static function getContinentsList()
{
- require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php';
-
- $continentsList = $GLOBALS['Piwik_ContinentList'];
- return $continentsList;
+ /** @var RegionDataProvider $dataProvider */
+ $dataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider');
+ return $dataProvider->getContinentList();
}
/**
@@ -766,19 +771,15 @@ class Common
*
* @param bool $includeInternalCodes
* @return array Array of (2 letter ISO codes => 3 letter continent code)
+ *
+ * @deprecated Use Piwik\Intl\Data\Provider\RegionDataProvider instead.
+ * @see \Piwik\Intl\Data\Provider\RegionDataProvider::getCountryList()
*/
public static function getCountriesList($includeInternalCodes = false)
{
- require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php';
-
- $countriesList = $GLOBALS['Piwik_CountryList'];
- $extras = $GLOBALS['Piwik_CountryList_Extras'];
-
- if ($includeInternalCodes) {
- return array_merge($countriesList, $extras);
- }
-
- return $countriesList;
+ /** @var RegionDataProvider $dataProvider */
+ $dataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider');
+ return $dataProvider->getCountryList($includeInternalCodes);
}
/**
@@ -789,13 +790,15 @@ class Common
* @return array Array of two letter ISO codes mapped with their associated language names (in English). E.g.
* `array('en' => 'English', 'ja' => 'Japanese')`.
* @api
+ *
+ * @deprecated Use Piwik\Intl\Data\Provider\LanguageDataProvider instead.
+ * @see \Piwik\Intl\Data\Provider\LanguageDataProvider::getLanguageList()
*/
public static function getLanguagesList()
{
- require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Languages.php';
-
- $languagesList = $GLOBALS['Piwik_LanguageList'];
- return $languagesList;
+ /** @var LanguageDataProvider $dataProvider */
+ $dataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\LanguageDataProvider');
+ return $dataProvider->getLanguageList();
}
/**
@@ -806,13 +809,15 @@ class Common
* @return array Array of two letter ISO language codes mapped with two letter ISO country codes:
* `array('fr' => 'fr') // French => France`
* @api
+ *
+ * @deprecated Use Piwik\Intl\Data\Provider\LanguageDataProvider instead.
+ * @see \Piwik\Intl\Data\Provider\LanguageDataProvider::getLanguageToCountryList()
*/
public static function getLanguageToCountryList()
{
- require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/LanguageToCountry.php';
-
- $languagesList = $GLOBALS['Piwik_LanguageToCountry'];
- return $languagesList;
+ /** @var LanguageDataProvider $dataProvider */
+ $dataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\LanguageDataProvider');
+ return $dataProvider->getLanguageToCountryList();
}
/**
diff --git a/core/Intl/Data/Provider/LanguageDataProvider.php b/core/Intl/Data/Provider/LanguageDataProvider.php
new file mode 100644
index 0000000000..8369d8b1a7
--- /dev/null
+++ b/core/Intl/Data/Provider/LanguageDataProvider.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Intl\Data\Provider;
+
+/**
+ * Provides language data.
+ */
+class LanguageDataProvider
+{
+ /**
+ * Returns the list of valid language codes.
+ *
+ * @return string[] Array of 2 letter ISO code => language name (in english).
+ * E.g. `array('en' => 'English', 'ja' => 'Japanese')`.
+ * @api
+ */
+ public static function getLanguageList()
+ {
+ require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Languages.php';
+
+ $languagesList = $GLOBALS['Piwik_LanguageList'];
+ return $languagesList;
+ }
+
+ /**
+ * Returns the list of language to country mappings.
+ *
+ * @return string[] Array of 2 letter ISO language code => 2 letter ISO country code.
+ * E.g. `array('fr' => 'fr') // French => France`.
+ * @api
+ */
+ public static function getLanguageToCountryList()
+ {
+ require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/LanguageToCountry.php';
+
+ $languagesList = $GLOBALS['Piwik_LanguageToCountry'];
+ return $languagesList;
+ }
+}
diff --git a/core/Intl/Data/Provider/RegionDataProvider.php b/core/Intl/Data/Provider/RegionDataProvider.php
new file mode 100644
index 0000000000..b47aa4ab9c
--- /dev/null
+++ b/core/Intl/Data/Provider/RegionDataProvider.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Intl\Data\Provider;
+
+/**
+ * Provides region related data (continents, countries, etc.).
+ */
+class RegionDataProvider
+{
+ /**
+ * Returns the list of continent codes.
+ *
+ * @return string[] Array of 3 letter continent codes
+ * @api
+ */
+ public function getContinentList()
+ {
+ require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php';
+
+ return $GLOBALS['Piwik_ContinentList'];
+ }
+
+ /**
+ * Returns the list of valid country codes.
+ *
+ * @param bool $includeInternalCodes
+ * @return string[] Array of 2 letter country ISO codes => 3 letter continent code
+ * @api
+ */
+ public static function getCountryList($includeInternalCodes = false)
+ {
+ require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php';
+
+ $countriesList = $GLOBALS['Piwik_CountryList'];
+ $extras = $GLOBALS['Piwik_CountryList_Extras'];
+
+ if ($includeInternalCodes) {
+ return array_merge($countriesList, $extras);
+ }
+
+ return $countriesList;
+ }
+}