This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
236 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
/* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Romm\Formz\DataCollectors; | ||
|
||
use Konafets\TYPO3DebugBar\DataCollectors\BaseCollector; | ||
use Romm\Formz\Form\FormObject; | ||
use Romm\Formz\Form\FormObjectFactory; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Utility\DebuggerUtility; | ||
|
||
class FormzCollector extends BaseCollector | ||
{ | ||
/** | ||
* @var FormObject[] | ||
*/ | ||
private $formzInstances = []; | ||
|
||
/** | ||
* Called by the DebugBar when data needs to be collected | ||
* | ||
* @return array Collected data | ||
*/ | ||
function collect() | ||
{ | ||
$formzInstances = $this->getFormzInstances(); | ||
|
||
foreach ($formzInstances as $instance) { | ||
$debug .= DebuggerUtility::var_dump($instance, $instance->getName(),10,false,true, true); | ||
$forms[] = [ | ||
'name' => $instance->getName(), | ||
'params' => [ | ||
'Class Name' => $instance->getClassName(), | ||
'Fields' => $instance->getProperties(), | ||
'Hash' => $instance->getHash() | ||
] | ||
]; | ||
} | ||
|
||
$formsCount = \count($formzInstances); | ||
$output = [ | ||
'formsCount' => $formsCount, // Number of formz instance in the page | ||
'debug' => $debug, | ||
'status' => '<b>' . $formsCount . '</b> Formz instance(s) in this page', | ||
'forms' => $forms, | ||
'console' => '' // div for output console javascript | ||
]; | ||
|
||
return $output; | ||
} | ||
|
||
/** | ||
* @return FormObject[] | ||
*/ | ||
public function getFormzInstances() | ||
{ | ||
$formObjFactory = GeneralUtility::makeInstance(FormObjectFactory::class); | ||
|
||
foreach ($formObjFactory->getInstances() as $instance) { | ||
$this->formzInstances[$instance->getName()] = $instance; | ||
} | ||
|
||
return $this->formzInstances; | ||
} | ||
|
||
/** | ||
* Returns a hash where keys are control names and their values | ||
* an array of options as defined in {@see DebugBar\JavascriptRenderer::addControl()} | ||
* | ||
* @return array | ||
*/ | ||
function getWidgets() | ||
{ | ||
$name = $this->getName(); | ||
|
||
return [ | ||
(string) $name => [ | ||
'icon' => $name, | ||
'widget' => 'PhpDebugBar.Widgets.FormzWidget', | ||
'map' => $name, | ||
"default" => '[]', | ||
], | ||
"$name:badge" => [ | ||
'map' => 'formz.formsCount', | ||
'default' => 0, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Returns the unique name of the collector | ||
* | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return 'formz'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters