PHP Class Monarobase\CountryList\CountryList

Author: Monarobase ([email protected])
显示文件 Open project: monarobase/country-list

Protected Properties

Property Type Description
$dataCache array Cached data.
$dataDir string Path to the directory containing countries data.
$dataSources array Available data sources.

Public Methods

Method Description
__construct ( string | null $dataDir = null ) Constructor.
getDataDir ( ) : string
getList ( string $locale = 'en', string $format = 'php', string $source = 'cldr' ) : array Returns a list of countries.
getOne ( string $countryCode, string $locale = 'en', string $source = 'cldr' ) : string Returns one country.
has ( string $countryCode, string $locale = 'en', string $source = 'cldr' ) : boolean Indicates whether or not a given $countryCode matches a country.
setList ( string $locale, string $source, array $data ) : CountryList

Protected Methods

Method Description
loadData ( string $locale, string $source, string $format ) : array A lazy-loader that loads data from a PHP file if it is not stored in memory yet.
sortData ( string $locale, array $data ) : array Sorts the data array for a given locale, using the locale translations.

Method Details

__construct() public method

Constructor.
public __construct ( string | null $dataDir = null )
$dataDir string | null Path to the directory containing countries data

getDataDir() public method

public getDataDir ( ) : string
return string The country data directory.

getList() public method

Returns a list of countries.
public getList ( string $locale = 'en', string $format = 'php', string $source = 'cldr' ) : array
$locale string The locale (default: en)
$format string The format (default: php)
$source string Data source: "icu" or "cldr"
return array

getOne() public method

Returns one country.
public getOne ( string $countryCode, string $locale = 'en', string $source = 'cldr' ) : string
$countryCode string The country
$locale string The locale (default: en)
$source string Data source: "icu" or "cldr"
return string

has() public method

Indicates whether or not a given $countryCode matches a country.
public has ( string $countryCode, string $locale = 'en', string $source = 'cldr' ) : boolean
$countryCode string A 2-letter country code
$locale string The locale (default: en)
$source string Data source: "icu" or "cldr"
return boolean true if a match was found, false otherwise

loadData() protected method

A lazy-loader that loads data from a PHP file if it is not stored in memory yet.
protected loadData ( string $locale, string $source, string $format ) : array
$locale string The locale
$source string Data source
$format string The format (default: php)
return array An array (list) with country

setList() public method

public setList ( string $locale, string $source, array $data ) : CountryList
$locale string The locale
$source string Data source
$data array An array (list) with country data
return CountryList The instance of CountryList to enable fluent interface

sortData() protected method

It is UTF-8 aware if the Collator class is available (requires the intl extension).
protected sortData ( string $locale, array $data ) : array
$locale string The locale whose collation rules should be used.
$data array Array of strings to sort.
return array The $data array, sorted.

Property Details

$dataCache protected_oe property

Cached data.
protected array $dataCache
return array

$dataDir protected_oe property

Path to the directory containing countries data.
protected string $dataDir
return string

$dataSources protected_oe property

Available data sources.
protected array $dataSources
return array