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;
}