1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* The MIT License (MIT) |
6
|
|
|
* |
7
|
|
|
* Copyright (c) 2015 Daniel Popiniuc |
8
|
|
|
* |
9
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
10
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
11
|
|
|
* in the Software without restriction, including without limitation the rights |
12
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
14
|
|
|
* furnished to do so, subject to the following conditions: |
15
|
|
|
* |
16
|
|
|
* The above copyright notice and this permission notice shall be included in all |
17
|
|
|
* copies or substantial portions of the Software. |
18
|
|
|
* |
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
25
|
|
|
* SOFTWARE. |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
namespace danielgp\info_compare; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Description of compare |
33
|
|
|
* |
34
|
|
|
* @author Transformer- |
35
|
|
|
*/ |
36
|
|
|
class Compare |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
use \danielgp\common_lib\CommonCode, |
40
|
|
|
\danielgp\info_compare\ConfigurationCompare, |
41
|
|
|
\danielgp\info_compare\OutputFormBuilder, |
42
|
|
|
\danielgp\info_compare\CompareTable; |
43
|
|
|
|
44
|
|
|
private $config; |
45
|
|
|
private $localConfiguration; |
46
|
|
|
private $serverConfiguration; |
47
|
|
|
|
48
|
|
|
public function __construct() |
49
|
|
|
{ |
50
|
|
|
$this->getConfiguration(); |
51
|
|
|
echo $this->setHeaderHtml(); |
52
|
|
|
$rqst = new \Symfony\Component\HttpFoundation\Request; |
53
|
|
|
$superGlobals = $rqst->createFromGlobals(); |
54
|
|
|
$this->prepareForOutputForm(['SuperGlobals' => $superGlobals]); |
55
|
|
|
if (!is_null($superGlobals->get('Label'))) { |
56
|
|
|
$this->processInfos(['sGlobals' => $superGlobals]); |
57
|
|
|
echo $this->setFormCurlInfos(['SuperGlobals' => $superGlobals]); |
58
|
|
|
echo $this->setFormInfos(['SuperGlobals' => $superGlobals]); |
59
|
|
|
} |
60
|
|
|
echo $this->setFooterHtml(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function getConfiguration() |
64
|
|
|
{ |
65
|
|
|
$strdConfig = $this->configuredDeployedInformators(); |
66
|
|
|
foreach ($strdConfig['informators'] as $key => $value) { |
67
|
|
|
$this->config['Servers'][] = [ |
68
|
|
|
'name' => $key, |
69
|
|
|
'url' => $value, |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
$haystack = array_keys($strdConfig['informators']); |
73
|
|
|
$this->config['Defaults']['Label'] = $strdConfig['default']['label']; |
74
|
|
|
$this->config['Defaults']['localConfig'] = array_search($strdConfig['default']['source'], $haystack); |
75
|
|
|
$this->config['Defaults']['serverConfig'] = array_search($strdConfig['default']['target'], $haystack); |
76
|
|
|
$this->config['Defaults']['displayOnlyDifferent'] = $strdConfig['default']['typeOfResults']; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function prepareForOutputForm($inArray) |
80
|
|
|
{ |
81
|
|
|
$urlToGetLbl = $this->config['Servers'][$this->config['Defaults']['localConfig']]['url'] |
82
|
|
|
. '?Label=---' . urlencode(' List of known labels'); |
83
|
|
|
$knownLabels = $this->getContentFromUrlThroughCurlAsArrayIfJson($urlToGetLbl)['response']; |
84
|
|
|
echo $this->setOutputForm([ |
85
|
|
|
'Defaults' => $this->config['Defaults'], |
86
|
|
|
'KnownLabels' => $knownLabels, |
87
|
|
|
'Servers' => $this->config['Servers'], |
88
|
|
|
'SuperGlobals' => $inArray['SuperGlobals'], |
89
|
|
|
]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
private function processInfos($inArray) |
93
|
|
|
{ |
94
|
|
|
$this->localConfiguration = ['response' => '', 'info' => '']; |
95
|
|
|
$this->serverConfiguration = ['response' => '', 'info' => '']; |
96
|
|
|
if (!is_null($inArray['sGlobals']->get('localConfig')) && !is_null($inArray['sGlobals']->get('serverConfig'))) { |
97
|
|
|
$urlArguments = '?Label=' . urlencode($inArray['sGlobals']->get('Label')); |
98
|
|
|
$source = $this->config['Servers'][$inArray['sGlobals']->get('localConfig')]['url'] |
99
|
|
|
. $urlArguments; |
100
|
|
|
$this->localConfiguration = $this->getContentFromUrlThroughCurlAsArrayIfJson($source); |
101
|
|
|
$destination = $this->config['Servers'][$inArray['sGlobals']->get('serverConfig')]['url'] |
102
|
|
|
. $urlArguments; |
103
|
|
|
$this->serverConfiguration = $this->getContentFromUrlThroughCurlAsArrayIfJson($destination); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
private function setFooterHtml() |
108
|
|
|
{ |
109
|
|
|
$footerToInject = [ |
110
|
|
|
'</div><!-- from main Tabber -->', |
111
|
|
|
'<div class="resetOnly author">© 2015 Daniel Popiniuc</div>', |
112
|
|
|
'<hr/><div class="disclaimer">The developer cannot be liable of any data input or results, ', |
113
|
|
|
'included but not limited to any implication of these (anywhere and whomever there might be these)!', |
114
|
|
|
'</div>', |
115
|
|
|
]; |
116
|
|
|
return $this->setFooterCommon($footerToInject); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
private function setFormCurlInfos($inArray) |
120
|
|
|
{ |
121
|
|
|
return '<div class="tabbertab" id="tabCurl" title="CURL infos">' |
122
|
|
|
. $this->displayTableFromMultiLevelArray([ |
123
|
|
|
'source' => $this->localConfiguration['info'], |
124
|
|
|
'destination' => $this->serverConfiguration['info'], |
125
|
|
|
'Servers' => $this->config['Servers'], |
126
|
|
|
'SuperGlobals' => $inArray['SuperGlobals'], |
127
|
|
|
]) |
128
|
|
|
. '</div><!--from tabCurl-->'; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
private function setFormInfos($inArray) |
132
|
|
|
{ |
133
|
|
|
return '<div class="tabbertab' |
134
|
|
|
. (is_null($inArray['SuperGlobals']->get('Label')) ? '' : ' tabbertabdefault') |
135
|
|
|
. '" id="tabConfigs" title="Informations">' |
136
|
|
|
. $this->displayTableFromMultiLevelArray([ |
137
|
|
|
'source' => $this->localConfiguration['response'], |
138
|
|
|
'destination' => $this->serverConfiguration['response'], |
139
|
|
|
'Servers' => $this->config['Servers'], |
140
|
|
|
'SuperGlobals' => $inArray['SuperGlobals'], |
141
|
|
|
]) |
142
|
|
|
. '</div><!--from tabConfigs-->'; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
private function setHeaderHtml() |
146
|
|
|
{ |
147
|
|
|
return $this->setHeaderCommon([ |
148
|
|
|
'lang' => 'en-US', |
149
|
|
|
'title' => $this->configuredApplicationName(), |
150
|
|
|
'css' => 'css/main.css', |
151
|
|
|
'javascript' => 'js/tabber.min.js', |
152
|
|
|
]) |
153
|
|
|
. $this->setJavascriptContent('document.write(\'<style type="text/css">' |
154
|
|
|
. '.tabber{display:none;}</style>\');') |
155
|
|
|
. '<h1>' . $this->configuredApplicationName() . '</h1>' |
156
|
|
|
. '<div class="tabber" id="tab">'; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|