1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This program is free software: you can redistribute it and/or modify |
4
|
|
|
* it under the terms of the GNU General Public License as published by |
5
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
6
|
|
|
* (at your option) any later version. |
7
|
|
|
* |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11
|
|
|
* GNU General Public License for more details. |
12
|
|
|
* |
13
|
|
|
* You should have received a copy of the GNU General Public License |
14
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace Romm\Formz\DataCollectors; |
18
|
|
|
|
19
|
|
|
use Konafets\TYPO3DebugBar\DataCollectors\BaseCollector; |
20
|
|
|
use Romm\Formz\Form\FormObject; |
21
|
|
|
use Romm\Formz\Form\FormObjectFactory; |
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
23
|
|
|
use TYPO3\CMS\Extbase\Utility\DebuggerUtility; |
24
|
|
|
|
25
|
|
|
class FormzCollector extends BaseCollector |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var FormObject[] |
29
|
|
|
*/ |
30
|
|
|
private $formzInstances = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Called by the DebugBar when data needs to be collected |
34
|
|
|
* |
35
|
|
|
* @return array Collected data |
36
|
|
|
*/ |
37
|
|
|
function collect() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$formzInstances = $this->getFormzInstances(); |
40
|
|
|
|
41
|
|
|
foreach ($formzInstances as $instance) { |
42
|
|
|
$debug .= DebuggerUtility::var_dump($instance, $instance->getName(),10,false,true, true); |
|
|
|
|
43
|
|
|
$forms[] = [ |
|
|
|
|
44
|
|
|
'name' => $instance->getName(), |
45
|
|
|
'params' => [ |
46
|
|
|
'Class Name' => $instance->getClassName(), |
47
|
|
|
'Fields' => $instance->getProperties(), |
48
|
|
|
'Hash' => $instance->getHash() |
49
|
|
|
] |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$formsCount = \count($formzInstances); |
54
|
|
|
$output = [ |
55
|
|
|
'formsCount' => $formsCount, // Number of formz instance in the page |
56
|
|
|
'debug' => $debug, |
57
|
|
|
'status' => '<b>' . $formsCount . '</b> Formz instance(s) in this page', |
58
|
|
|
'forms' => $forms, |
|
|
|
|
59
|
|
|
'console' => '' // div for output console javascript |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
return $output; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return FormObject[] |
67
|
|
|
*/ |
68
|
|
|
public function getFormzInstances() |
69
|
|
|
{ |
70
|
|
|
$formObjFactory = GeneralUtility::makeInstance(FormObjectFactory::class); |
71
|
|
|
|
72
|
|
|
foreach ($formObjFactory->getInstances() as $instance) { |
73
|
|
|
$this->formzInstances[$instance->getName()] = $instance; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->formzInstances; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns a hash where keys are control names and their values |
81
|
|
|
* an array of options as defined in {@see DebugBar\JavascriptRenderer::addControl()} |
82
|
|
|
* |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
|
|
function getWidgets() |
86
|
|
|
{ |
87
|
|
|
$name = $this->getName(); |
|
|
|
|
88
|
|
|
|
89
|
|
|
return [ |
90
|
|
|
(string) $name => [ |
91
|
|
|
'icon' => $name, |
92
|
|
|
'widget' => 'PhpDebugBar.Widgets.FormzWidget', |
93
|
|
|
'map' => $name, |
94
|
|
|
"default" => '[]', |
95
|
|
|
], |
96
|
|
|
"$name:badge" => [ |
97
|
|
|
'map' => 'formz.formsCount', |
98
|
|
|
'default' => 0, |
99
|
|
|
], |
100
|
|
|
]; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Returns the unique name of the collector |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function getName() |
109
|
|
|
{ |
110
|
|
|
return 'formz'; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.