1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | namespace FlexiPeeHP; |
||
4 | |||
5 | define('EASE_APPNAME', 'FlexiPeehUP'); |
||
6 | define('EASE_LOGGER', 'console|syslog'); |
||
7 | |||
8 | require_once '../testing/bootstrap.php'; |
||
9 | |||
10 | |||
11 | $outFile = 'Relations.php'; |
||
12 | $outJson = 'Relations.json'; |
||
13 | $ok = 0; |
||
14 | |||
15 | /** |
||
16 | * Obtain Relations for given evidence |
||
17 | * |
||
18 | * @param string $evidence |
||
19 | * @param FlexiBeeRO $syncer Class to read from FlexiBee |
||
20 | * @return array Relations structure |
||
21 | */ |
||
22 | function getEvidenceRelations($evidence, FlexiBeeRO $syncer) |
||
23 | { |
||
24 | $relations = []; |
||
25 | $flexinfo = $syncer->performRequest($evidence.'/relations.json'); |
||
26 | if (count($flexinfo) && array_key_exists('relations', $flexinfo)) { |
||
27 | if (isset($flexinfo['relations']['relation'])) { |
||
28 | foreach ($flexinfo['relations']['relation'] as $evidenceRelations) { |
||
29 | $relations[] = $evidenceRelations; |
||
30 | } |
||
31 | } else { |
||
32 | $syncer->addStatusMessage(sprintf('Missing relations for %s', |
||
33 | $evidence), 'warning'); |
||
34 | } |
||
35 | } |
||
36 | return $relations; |
||
37 | } |
||
38 | $evidenceRels = '<?php |
||
39 | /** |
||
40 | * FlexiPeeHP - Evidence Relations. |
||
41 | * |
||
42 | * @author Vítězslav Dvořák <[email protected]> |
||
43 | * @copyright (C) 2015-2017 Spoje.Net |
||
44 | */ |
||
45 | |||
46 | namespace FlexiPeeHP; |
||
47 | |||
48 | /** |
||
49 | * Evidence Relations |
||
50 | * |
||
51 | * @link https://demo.flexibee.eu/devdoc/relations Provádění akcí |
||
52 | */ |
||
53 | |||
54 | class Relations |
||
55 | { |
||
56 | '; |
||
57 | $statuser = new Status(); |
||
58 | $evidenceRels .= ' /** |
||
59 | * Source FlexiBee server version. |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | '; |
||
64 | $evidenceRels .= ' static public $version = \''.$statuser->getDataValue('version').'\'; |
||
65 | |||
66 | '; |
||
67 | |||
68 | |||
69 | $syncer = new FlexiBeeRO(); |
||
70 | $syncer->setObjectName('FlexiBee Evidence Relations'); |
||
71 | $syncer->addStatusMessage('Updating Evidences Relations'); |
||
72 | |||
73 | $relations = []; |
||
74 | |||
75 | $pos = 0; |
||
76 | foreach (EvidenceList::$name as $evidencePath => $evidenceName) { |
||
77 | $pos++; |
||
78 | $structure = getEvidenceRelations($evidencePath, $syncer); |
||
79 | |||
80 | $relations[$evidencePath] = $structure; |
||
81 | |||
82 | if (count($structure)) { |
||
83 | $evidenceRels .= ' /** |
||
84 | * Evidence '.$evidencePath.' ('.$evidenceName.') Relations. |
||
85 | * |
||
86 | * @var array |
||
87 | */ |
||
88 | '; |
||
89 | $evidenceRels .= ' static public $'.lcfirst(FlexiBeeRO::evidenceToClassName($evidencePath)).' = '.var_export($structure, |
||
90 | true).'; |
||
91 | '; |
||
92 | |||
93 | $syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': relations obtained', |
||
94 | 'success'); |
||
95 | $ok++; |
||
96 | } else { |
||
97 | $syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': obtaining relations problem', |
||
98 | 'error'); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | $evidenceRels .= '} |
||
103 | '; |
||
104 | |||
105 | $syncer->addStatusMessage('Updating of '.$ok.' Evidences Properties done', |
||
106 | 'success'); |
||
107 | file_put_contents($outFile, $evidenceRels); |
||
108 | |||
109 | file_put_contents($outJson, json_encode($relations)); |
||
110 | |||
111 |
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.