-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCompile.php
More file actions
94 lines (73 loc) · 2.08 KB
/
Compile.php
File metadata and controls
94 lines (73 loc) · 2.08 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Pirates\PapiInfo;
/**
* Used to compile data and pass it into other applications
*/
class Compile
{
protected $rootPath;
protected $dataFiles;
protected $logoFiles;
protected $flagFiles;
function __construct() {
$this->rootPath = __DIR__ . '/../';
$this->dataFiles = scandir($this->rootPath . '/data/');
$this->logoFiles = scandir($this->rootPath . '/logo/');
$this->officialLogoFiles = scandir($this->rootPath . '/logo/official/');
$this->flagFiles = scandir($this->rootPath . '/country-flag/');
}
/**
* Returns all party data (json parsed into PHP objects&arrays)
* @return array
*/
public function getAllData() {
$output = [];
foreach ($this->dataFiles as $filename) {
if (preg_match('/.+\.json$/i', $filename) === 1) {
$ppdata = file_get_contents(sprintf('%s/data/%s', $this->rootPath, $filename));
$ppdata = json_decode($ppdata);
$output[$ppdata->partyCode] = $ppdata;
}
}
return $output;
}
/**
* Returns compiled list of all National Flag images
* @return array
*/
public function getFlagFiles() {
$output = [];
foreach ($this->flagFiles as $filename) {
if (preg_match('/(.+)\.(png|jpg)$/i', $filename, $matches) === 1) {
$output[strtoupper($matches[1])] = sprintf('%s/country-flag/%s', $this->rootPath, $filename);
}
}
return $output;
}
/**
* Returns compiled list of all party logo images
* @return array
*/
public function getLogoFiles() {
$output = [];
foreach ($this->logoFiles as $filename) {
if (preg_match('/(.+)\.(png|jpg)$/i', $filename, $matches) === 1) {
$output[strtoupper($matches[1])] = sprintf('%s/logo/%s', $this->rootPath, $filename);
}
}
return $output;
}
/**
* Returns compiled list of all official party logo images
* @return array
*/
public function getOfficialLogoFiles() {
$output = [];
foreach ($this->officialLogoFiles as $filename) {
if (preg_match('/(.+)\.(svg)$/i', $filename, $matches) === 1) {
$output[strtoupper($matches[1])] = sprintf('%s/logo/official/%s', $this->rootPath, $filename);
}
}
return $output;
}
}