Punic APIs
  • Namespace
  • Class
  • Tree
  • Todo

Namespaces

  • Punic
    • Exception

Classes

  • Calendar
  • Comparer
  • Currency
  • Data
  • Language
  • Misc
  • Number
  • Phone
  • Plural
  • Territory
  • Unit

Exceptions

  • Exception

Class Territory

Territory-related stuff.

Namespace: Punic
Located at Territory.php

Methods summary

public static string
# getName( string $territoryCode, string $locale = '' )

Retrieve the name of a territory (country, continent, ...).

Retrieve the name of a territory (country, continent, ...).

Parameters

$territoryCode
The territory code
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

string
Returns the localized territory name (returns $territoryCode if not found)
public static array
# getContinents( string $locale = '' )

Return the list of continents in the form of an array with key=ID, value=name.

Return the list of continents in the form of an array with key=ID, value=name.

Parameters

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

array
public static array
# getCountries( string $locale = '' )

Return the list of countries in the form of an array with key=ID, value=name.

Return the list of countries in the form of an array with key=ID, value=name.

Parameters

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

array
public static array
# getContinentsAndCountries( string $locale = '' )

Return a list of continents and relative countries. The resulting array is in the following form (JSON representation):

{
    "002": {
        "name": "Africa",
        "children": {
            "DZ": {"name": "Algeria"},
            "AO": {"name": "Angola"},
            ...
        }
    },
    "150": {
        "name": "Europe",
        "children": {
            "AL": {"name": "Albania"},
            "AD": {"name": "Andorra"},
            ...
        }
    }
    ...
}

The arrays are sorted by territory name.

Return a list of continents and relative countries. The resulting array is in the following form (JSON representation):

{ "002": { "name": "Africa", "children": { "DZ": {"name": "Algeria"}, "AO": {"name": "Angola"}, ... } }, "150": { "name": "Europe", "children": { "AL": {"name": "Albania"}, "AD": {"name": "Andorra"}, ... } } ...
}

The arrays are sorted by territory name.

Parameters

$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

array
public static array
# getList( string $levels = 'W', string $locale = '' )

Return a list of some specified territory, structured or not. $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 Punic\Territory::getContinents()). If one or more levels are specified, you'll get a structured list (like the one returned by Punic\Territory::getContinentsAndCountries()).

Return a list of some specified territory, structured or not. $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 Punic\Territory::getContinents()). If one or more levels are specified, you'll get a structured list (like the one returned by Punic\Territory::getContinentsAndCountries()).

Parameters

$levels
A string with one or more of the characters: 'W' (for world), 'C' (for continents), 'S' (for sub-continents), 'c' (for countries)
$locale
The locale to use. If empty we'll use the default locale set in \Punic\Data

Returns

array

Throws

Punic\Exception\BadArgumentType

See

http://www.unicode.org/cldr/charts/latest/supplemental/territory_containment_un_m_49.html
public static array
# getTerritoriesWithInfo( )

Return a list of territory identifiers for which we have some info (languages, population, literacy level, Gross Domestic Product).

Return a list of territory identifiers for which we have some info (languages, population, literacy level, Gross Domestic Product).

Returns

array
The list of territory IDs for which we have some info
public static array|null
# getLanguages( string $territoryCode, string $filterStatuses = '', string $onlyCodes = false )

Return the list of languages spoken in a territory.

Return the list of languages spoken in a territory.

Parameters

$territoryCode
The territory code
$filterStatuses

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

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

Returns

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)
public static number|null
# getPopulation( string $territoryCode )

Return the population of a specific territory.

Return the population of a specific territory.

Parameters

$territoryCode
The territory code

Returns

number|null
Return the size of the population of the specified territory (or null if $territoryCode is not valid or no data is available)
public static number|null
# getLiteracyLevel( string $territoryCode )

Return the literacy level for a specific territory, in %.

Return the literacy level for a specific territory, in %.

Parameters

$territoryCode
The territory code

Returns

number|null
Return the % of literacy lever of the specified territory (or null if $territoryCode is not valid or no data is available)
public static number|null
# getGrossDomesticProduct( string $territoryCode )

Return the GDP (Gross Domestic Product) for a specific territory, in US$.

Return the GDP (Gross Domestic Product) for a specific territory, in US$.

Parameters

$territoryCode
The territory code

Returns

number|null
Return the GDP of the specified territory (or null if $territoryCode is not valid or no data is available)
public static array
# getTerritoriesForLanguage( string $languageID, float $threshold = 0 )

Return a list of territory IDs where a specific language is spoken, sorted by the total number of people speaking that language.

Return a list of territory IDs where a specific language is spoken, sorted by the total number of people speaking that language.

Parameters

$languageID
The language identifier
$threshold
The minimum percentage (from 0 to 100) to consider a language as spoken in a Country

Returns

array
public static string
# getParentTerritoryCode( string $childTerritoryCode )

Return the code of the territory that contains a territory.

Return the code of the territory that contains a territory.

Parameters

$childTerritoryCode

Returns

string
return the parent territory code, or an empty string if $childTerritoryCode is the World (001) or if it's invalid
public static array
# getChildTerritoryCodes( string $parentTerritoryCode, boolean $expandSubGroups = false )

Retrieve the child territories of a parent territory.

Retrieve the child territories of a parent territory.

Parameters

$parentTerritoryCode
$expandSubGroups
set to true to expand the sub-groups, false to retrieve them

Returns

array
Return the list of territory codes that are children of $parentTerritoryCode (if $parentTerritoryCode is invalid you'll get an empty list)
Punic APIs API documentation generated by ApiGen