PHP Class Punic\Territory

Exibir arquivo Open project: punic/punic Class Usage Examples

Public Methods

Method Description
getChildTerritoryCodes ( string $parentTerritoryCode, boolean $expandSubGroups = false ) : array Retrieve the child territories of a parent territory.
getContinents ( string $locale = '' ) : array Return the list of continents in the form of an array with key=ID, value=name.
getContinentsAndCountries ( string $locale = '' ) : array Return a list of continents and relative countries. The resulting array is in the following form (JSON representation): ```json { "002": { "name": "Africa", "children": { "DZ": {"name": "Algeria"}, "AO": {"name": "Angola"}, .
getCountries ( string $locale = '' ) : array Return the list of countries in the form of an array with key=ID, value=name.
getGrossDomesticProduct ( string $territoryCode ) : number | null Return the GDP (Gross Domestic Product) for a specific territory, in US$.
getLanguages ( string $territoryCode, string $filterStatuses = '', string $onlyCodes = false ) : array | null Return the list of languages spoken in a territory.
getList ( string $levels = 'W', string $locale = '' ) : array Return a list of some specified territory, structured or not.
getLiteracyLevel ( string $territoryCode ) : number | null Return the literacy level for a specific territory, in %.
getName ( string $territoryCode, string $locale = '' ) : string Retrieve the name of a territory (country, continent, .
getParentTerritoryCode ( string $childTerritoryCode ) : string Return the code of the territory that contains a territory.
getPopulation ( string $territoryCode ) : number | null Return the population of a specific territory.
getTerritoriesForLanguage ( string $languageID, float $threshold ) : array Return a list of territory IDs where a specific language is spoken, sorted by the total number of people speaking that language.
getTerritoriesWithInfo ( ) : array Return a list of territory identifiers for which we have some info (languages, population, literacy level, Gross Domestic Product).

Protected Methods

Method Description
fillStructure ( $data, $id, $level )
filterStructure ( $parent, $levels )
finalizeWithNames ( $data, $list, $flatList )
getStructure ( )
getTerritoryInfo ( $territoryCode )
sort ( $list )

Method Details

fillStructure() protected static method

protected static fillStructure ( $data, $id, $level )

filterStructure() protected static method

protected static filterStructure ( $parent, $levels )

finalizeWithNames() protected static method

protected static finalizeWithNames ( $data, $list, $flatList )

getChildTerritoryCodes() public static method

Retrieve the child territories of a parent territory.
public static getChildTerritoryCodes ( string $parentTerritoryCode, boolean $expandSubGroups = false ) : array
$parentTerritoryCode string
$expandSubGroups boolean Set to true to expand the sub-groups, false to retrieve them.
return array Return the list of territory codes that are children of $parentTerritoryCode (if $parentTerritoryCode is invalid you'll get an empty list)

getContinents() public static method

Return the list of continents in the form of an array with key=ID, value=name.
public static getContinents ( string $locale = '' ) : array
$locale string The locale to use. If empty we'll use the default locale set in \Punic\Data
return array

getContinentsAndCountries() public static method

.. } }, "150": { "name": "Europe", "children": { "AL": {"name": "Albania"}, "AD": {"name": "Andorra"}, ... } } ... } ``` The arrays are sorted by territory name.
public static getContinentsAndCountries ( string $locale = '' ) : array
$locale string The locale to use. If empty we'll use the default locale set in \Punic\Data
return array

getCountries() public static method

Return the list of countries in the form of an array with key=ID, value=name.
public static getCountries ( string $locale = '' ) : array
$locale string The locale to use. If empty we'll use the default locale set in \Punic\Data
return array

getGrossDomesticProduct() public static method

Return the GDP (Gross Domestic Product) for a specific territory, in US$.
public static getGrossDomesticProduct ( string $territoryCode ) : number | null
$territoryCode string The territory code
return number | null Return the GDP of the specified territory (or null if $territoryCode is not valid or no data is available)

getLanguages() public static method

Return the list of languages spoken in a territory.
public static getLanguages ( string $territoryCode, string $filterStatuses = '', string $onlyCodes = false ) : array | null
$territoryCode string The territory code
$filterStatuses string Filter language status.
  • If empty no filter will be applied
  • 'o' to include official languages
  • 'r' to include official regional languages
  • 'f' to include de facto official languages
  • 'm' to include official minority languages
  • 'u' to include unofficial or unknown languages
$onlyCodes string Set to true to retrieve only the language codes. If set to false (default) you'll receive a list of arrays with these keys:
  • string id: the language identifier
  • string status: 'o' for official; 'r' for official regional; 'f' for de facto official; 'm' for official minority; 'u' for unofficial or unknown
  • number population: the amount of people speaking the language (%)
  • number|null writing: the amount of people able to write (%). May be null if no data is available
return array | null Return the languages spoken in the specified territory, as described by the $onlyCodes parameter (or null if $territoryCode is not valid or no data is available)

getList() public static method

$levels control which data you want to retrieve. It can be one or more of the following values:
  • 'W': world
  • 'C': continents
  • 'S': sub-continents
  • 'c': countries
If only one level is specified you'll get a flat list (like the one returned by {@link getContinents}). If one or more levels are specified, you'll get a structured list (like the one returned by {@link getContinentsAndCountries}).
public static getList ( string $levels = 'W', string $locale = '' ) : array
$levels string A string with one or more of the characters: 'W' (for world), 'C' (for continents), 'S' (for sub-continents), 'c' (for countries)
$locale string The locale to use. If empty we'll use the default locale set in \Punic\Data
return array

getLiteracyLevel() public static method

Return the literacy level for a specific territory, in %.
public static getLiteracyLevel ( string $territoryCode ) : number | null
$territoryCode string The territory code
return number | null Return the % of literacy lever of the specified territory (or null if $territoryCode is not valid or no data is available)

getName() public static method

..).
public static getName ( string $territoryCode, string $locale = '' ) : string
$territoryCode string The territory code
$locale string The locale to use. If empty we'll use the default locale set in \Punic\Data
return string Returns the localized territory name (returns $territoryCode if not found)

getParentTerritoryCode() public static method

Return the code of the territory that contains a territory.
public static getParentTerritoryCode ( string $childTerritoryCode ) : string
$childTerritoryCode string
return string Return the parent territory code, or an empty string if $childTerritoryCode is the World (001) or if it's invalid.

getPopulation() public static method

Return the population of a specific territory.
public static getPopulation ( string $territoryCode ) : number | null
$territoryCode string The territory code
return number | null Return the size of the population of the specified territory (or null if $territoryCode is not valid or no data is available)

getStructure() protected static method

protected static getStructure ( )

getTerritoriesForLanguage() public static method

Return a list of territory IDs where a specific language is spoken, sorted by the total number of people speaking that language.
public static getTerritoriesForLanguage ( string $languageID, float $threshold ) : array
$languageID string The language identifier
$threshold float The minimum percentage (from 0 to 100) to consider a language as spoken in a Country
return array

getTerritoriesWithInfo() public static method

Return a list of territory identifiers for which we have some info (languages, population, literacy level, Gross Domestic Product).
public static getTerritoriesWithInfo ( ) : array
return array The list of territory IDs for which we have some info

getTerritoryInfo() protected static method

protected static getTerritoryInfo ( $territoryCode )

sort() protected static method

protected static sort ( $list )