|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
namespace FlexiPeeHP; |
|
4
|
|
|
|
|
5
|
|
|
require_once '../testing/bootstrap.php'; |
|
6
|
|
|
|
|
7
|
|
|
define('EASE_APPNAME', 'FlexiPeehUP'); |
|
8
|
|
|
define('EASE_LOGGER', 'console|syslog'); |
|
9
|
|
|
|
|
10
|
|
|
$outFile = 'Formats.php'; |
|
11
|
|
|
$ok = 0; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Obtain Formats for given evidence |
|
15
|
|
|
* |
|
16
|
|
|
* @param string $evidence |
|
17
|
|
|
* @param FlexiBeeRO $syncer Class to read from FlexiBee |
|
18
|
|
|
* @return array Formats structure |
|
19
|
|
|
*/ |
|
20
|
|
|
function getEvidenceFormats($evidence, FlexiBeeRO $syncer) |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
$syncer->setEvidence($evidence); |
|
24
|
|
|
$flexinfo = $syncer->getColumnsFromFlexibee(['id'], ['limit' => 1]); |
|
25
|
|
|
if (is_array($flexinfo) && array_key_exists('id', $flexinfo[0])) { |
|
26
|
|
|
$id = is_numeric($flexinfo[0]['id']) ? intval($flexinfo[0]['id']) : $flexinfo[0]['id']; |
|
27
|
|
|
|
|
28
|
|
|
foreach (FlexiBeeRO::$formats as $cancode => $candidate) { |
|
29
|
|
|
$syncer->setFormat($candidate['suffix']); |
|
30
|
|
|
$syncer->loadFromFlexiBee($id); |
|
31
|
|
|
if ($syncer->lastResponseCode == 200) { |
|
32
|
|
|
$formats[$cancode] = $candidate['suffix']; |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
} else { |
|
36
|
|
|
$syncer->addStatusMessage(sprintf('Missing formats for %s', $evidence), |
|
37
|
|
|
'warning'); |
|
38
|
|
|
$formats = ['HTML' => 'html', 'XML' => 'xml', 'JSON' => 'json', 'CSV' => 'csv']; |
|
39
|
|
|
} |
|
40
|
|
|
return $formats; |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
$evidenceFormats = '<?php |
|
43
|
|
|
/** |
|
44
|
|
|
* FlexiPeeHP - Evidence Formats. |
|
45
|
|
|
* |
|
46
|
|
|
* @author Vítězslav Dvořák <[email protected]> |
|
47
|
|
|
* @copyright (C) 2015-2017 Spoje.Net |
|
48
|
|
|
*/ |
|
49
|
|
|
namespace FlexiPeeHP; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Evidence Formats |
|
53
|
|
|
* |
|
54
|
|
|
* @link https://demo.flexibee.eu/devdoc/formats Provádění akcí |
|
55
|
|
|
*/ |
|
56
|
|
|
class Formats |
|
57
|
|
|
{ |
|
58
|
|
|
'; |
|
59
|
|
|
$statuser = new Status(); |
|
60
|
|
|
$evidenceFormats .= ' /** |
|
61
|
|
|
* Source FlexiBee server version. |
|
62
|
|
|
* |
|
63
|
|
|
* @var string |
|
64
|
|
|
*/ |
|
65
|
|
|
'; |
|
66
|
|
|
$evidenceFormats .= ' static public $version = \''.$statuser->getDataValue('version').'\'; |
|
67
|
|
|
|
|
68
|
|
|
'; |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$syncer = new FlexiBeeRO(); |
|
72
|
|
|
$syncer->addStatusMessage('Updating Evidences Formats'); |
|
73
|
|
|
|
|
74
|
|
|
$pos = 0; |
|
75
|
|
View Code Duplication |
foreach (EvidenceList::$name as $evidencePath => $evidenceName) { |
|
|
|
|
|
|
76
|
|
|
$pos++; |
|
77
|
|
|
$structure = getEvidenceFormats($evidencePath, $syncer); |
|
78
|
|
|
if (count($structure)) { |
|
79
|
|
|
$evidenceFormats .= ' /** |
|
80
|
|
|
* Evidence '.$evidencePath.' ('.$evidenceName.') Formats. |
|
81
|
|
|
* |
|
82
|
|
|
* @var array |
|
83
|
|
|
*/ |
|
84
|
|
|
'; |
|
85
|
|
|
$evidenceFormats .= ' static public $'.lcfirst(FlexiBeeRO::evidenceToClassName($evidencePath)).' = '.var_export($structure, |
|
86
|
|
|
true).'; |
|
87
|
|
|
'; |
|
88
|
|
|
|
|
89
|
|
|
$syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': formats: '.implode(',', |
|
90
|
|
|
$structure).' obtained', 'success'); |
|
91
|
|
|
$ok++; |
|
92
|
|
|
} else { |
|
93
|
|
|
$syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': obtaining formats problem', |
|
94
|
|
|
'error'); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$evidenceFormats .= '} |
|
99
|
|
|
'; |
|
100
|
|
|
|
|
101
|
|
|
$syncer->addStatusMessage('Updating of '.$ok.' Evidences Formats done', |
|
102
|
|
|
'success'); |
|
103
|
|
|
file_put_contents($outFile, $evidenceFormats); |
|
104
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.