Monarobase\CountryList\CountryList::loadData PHP Method

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
    protected function loadData($locale, $source, $format)
    {
        if (!isset($this->dataCache[$locale][$source][$format])) {
            if (!in_array($source, $this->dataSources)) {
                throw new \InvalidArgumentException(sprintf('Unknown data source "%s". The available ones are: "%s"', $source, implode('", "', $this->dataSources)));
            }
            $file = sprintf('%s/%s/%s/country.' . $format, $this->dataDir, $source, $locale);
            if (!is_file($file)) {
                throw new \RuntimeException(sprintf('Unable to load the country data file "%s"', $file));
            }
            $this->dataCache[$locale][$source][$format] = $format == 'php' ? require $file : file_get_contents($file);
        }
        return $this->sortData($locale, $this->dataCache[$locale][$source][$format]);
    }