-
Notifications
You must be signed in to change notification settings - Fork 0
/
RockCountries.module.php
42 lines (34 loc) · 1.03 KB
/
RockCountries.module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace ProcessWire;
use RockCountries\CountryArray;
function rockcountries(): RockCountries
{
return wire()->modules->get('RockCountries');
}
/**
* @author Bernhard Baumrock, 28.10.2024
* @license Licensed under MIT
* @link https://www.baumrock.com
*/
class RockCountries extends WireData implements Module
{
private $countries = [];
public function init(): void
{
require_once __DIR__ . '/CountryArray.php';
}
public function countries($language = 'en'): CountryArray
{
$key = strtolower($language);
if (array_key_exists($key, $this->countries)) return $this->countries[$key];
// load countries
/** @var array $countries */
$countries = wire()->files->render(__DIR__ . "/vendor/stefangabos/world_countries/data/countries/$key/world.php");
$countries = array_map(function ($country) {
return (new WireData())->setArray($country);
}, $countries);
$countries = (new CountryArray())->setArray($countries);
$this->countries[$key] = $countries;
return $countries;
}
}