Punic\Territory::getList PHP Метод

getList() публичный статический Метод

$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
Результат array
    public static function getList($levels = 'W', $locale = '')
    {
        static $levelMap = array('W' => 0, 'C' => 1, 'S' => 2, 'c' => 3);
        $decodedLevels = array();
        $n = is_string($levels) ? strlen($levels) : 0;
        if ($n > 0) {
            for ($i = 0; $i < $n; ++$i) {
                $l = substr($levels, $i, 1);
                if (!isset($levelMap[$l])) {
                    $decodedLevels = array();
                    break;
                }
                if (!in_array($levelMap[$l], $decodedLevels, true)) {
                    $decodedLevels[] = $levelMap[$l];
                }
            }
        }
        if (count($decodedLevels) === 0) {
            throw new \Punic\Exception\BadArgumentType($levels, "list of territory kinds: it should be a list of one or more of the codes '" . implode("', '", array_keys($levelMap)) . "'");
        }
        $struct = self::filterStructure(self::getStructure(), $decodedLevels, 0);
        $flatList = count($decodedLevels) > 1 ? false : true;
        $finalized = self::finalizeWithNames(Data::get('territories', $locale), $struct, $flatList);
        if ($flatList) {
            $sorter = new \Punic\Comparer();
            $sorter->sort($finalized, true);
        } else {
            $finalized = static::sort($finalized);
        }
        return $finalized;
    }