1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace InternationalInfo; |
4
|
|
|
|
5
|
|
|
class InternationalInfoManager |
6
|
|
|
{ |
7
|
|
|
protected array $instances = []; |
8
|
|
|
|
9
|
7 |
|
public function storageFile(string $name): string |
10
|
|
|
{ |
11
|
7 |
|
$file = config('international-info.storage_path') . '/' . $name; |
12
|
7 |
|
if (file_exists($file)) { |
13
|
1 |
|
return $file; |
14
|
|
|
} |
15
|
|
|
|
16
|
6 |
|
return __DIR__ . '/../storage/international-info/' . $name; |
17
|
|
|
} |
18
|
|
|
|
19
|
1 |
|
public function continent(): Continent |
20
|
|
|
{ |
21
|
1 |
|
if (!empty($this->instances[ __FUNCTION__ ])) { |
22
|
1 |
|
return $this->instances[ __FUNCTION__ ]; |
23
|
|
|
} |
24
|
|
|
|
25
|
1 |
|
return $this->instances[ __FUNCTION__ ] = new Continent(include($this->storageFile('continents.php'))); |
26
|
|
|
} |
27
|
|
|
|
28
|
2 |
|
public function country(): Country |
29
|
|
|
{ |
30
|
2 |
|
if (!empty($this->instances[ __FUNCTION__ ])) { |
31
|
1 |
|
return $this->instances[ __FUNCTION__ ]; |
32
|
|
|
} |
33
|
|
|
|
34
|
2 |
|
return $this->instances[ __FUNCTION__ ] = new Country(include($this->storageFile('countries.php'))); |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
public function localeData(): LocaleData |
38
|
|
|
{ |
39
|
1 |
|
if (!empty($this->instances[ __FUNCTION__ ])) { |
40
|
1 |
|
return $this->instances[ __FUNCTION__ ]; |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
return $this->instances[ __FUNCTION__ ] = new LocaleData(include($this->storageFile('locale-data.php'))); |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
public function phoneCode(): PhoneCode |
47
|
|
|
{ |
48
|
1 |
|
if (!empty($this->instances[ __FUNCTION__ ])) { |
49
|
1 |
|
return $this->instances[ __FUNCTION__ ]; |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
return $this->instances[ __FUNCTION__ ] = new PhoneCode(include($this->storageFile('phone-codes.php'))); |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
public function state(): State |
56
|
|
|
{ |
57
|
2 |
|
if (!empty($this->instances[ __FUNCTION__ ])) { |
58
|
1 |
|
return $this->instances[ __FUNCTION__ ]; |
59
|
|
|
} |
60
|
|
|
|
61
|
2 |
|
return $this->instances[ __FUNCTION__ ] = new State(include($this->storageFile('states.php'))); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|