mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°8796 - Add PHP code style validation in iTop and extensions - format whole code base
This commit is contained in:
@@ -31,7 +31,7 @@ use CoreException;
|
||||
*/
|
||||
abstract class FormManager
|
||||
{
|
||||
/** @var \Combodo\iTop\Form\Form $oForm */
|
||||
/** @var \Combodo\iTop\Form\Form $oForm */
|
||||
protected $oForm;
|
||||
/** @var \Combodo\iTop\Renderer\FormRenderer $oRenderer */
|
||||
protected $oRenderer;
|
||||
@@ -45,26 +45,22 @@ abstract class FormManager
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
static function FromJSON($sJson)
|
||||
public static function FromJSON($sJson)
|
||||
{
|
||||
// Overload in child class when needed
|
||||
if (is_array($sJson))
|
||||
{
|
||||
if (is_array($sJson)) {
|
||||
$aJson = $sJson;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$aJson = json_decode($sJson, true);
|
||||
}
|
||||
|
||||
$oFormManager = new static();
|
||||
|
||||
$sFormRendererClass = $aJson['formrenderer_class'];
|
||||
// N°7455 - Ensure form renderer class extends FormRenderer
|
||||
if (false === is_a($sFormRendererClass, FormRenderer::class, true))
|
||||
{
|
||||
throw new CoreException('Form renderer class must extend '.FormRenderer::class);
|
||||
}
|
||||
// N°7455 - Ensure form renderer class extends FormRenderer
|
||||
if (false === is_a($sFormRendererClass, FormRenderer::class, true)) {
|
||||
throw new CoreException('Form renderer class must extend '.FormRenderer::class);
|
||||
}
|
||||
|
||||
/** @var \Combodo\iTop\Renderer\FormRenderer $oFormRenderer */
|
||||
$oFormRenderer = new $sFormRendererClass();
|
||||
@@ -147,13 +143,13 @@ abstract class FormManager
|
||||
public function ToJSON()
|
||||
{
|
||||
// Overload in child class when needed
|
||||
return array(
|
||||
return [
|
||||
'id' => $this->oForm->GetId(),
|
||||
'transaction_id' => $this->oForm->GetTransactionId(),
|
||||
'formmanager_class' => $this->GetClass(),
|
||||
'formrenderer_class' => get_class($this->GetRenderer()),
|
||||
'formrenderer_endpoint' => $this->GetRenderer()->GetEndpoint()
|
||||
);
|
||||
'formrenderer_endpoint' => $this->GetRenderer()->GetEndpoint(),
|
||||
];
|
||||
}
|
||||
|
||||
abstract public function Build();
|
||||
@@ -174,14 +170,14 @@ abstract class FormManager
|
||||
*/
|
||||
public function OnSubmit($aArgs = null)
|
||||
{
|
||||
$aData = array(
|
||||
$aData = [
|
||||
'valid' => true,
|
||||
'messages' => array(
|
||||
'success' => array(),
|
||||
'warnings' => array(), // Not used as of today, just to show that the structure is ready for change like this.
|
||||
'error' => array(),
|
||||
),
|
||||
);
|
||||
'messages' => [
|
||||
'success' => [],
|
||||
'warnings' => [], // Not used as of today, just to show that the structure is ready for change like this.
|
||||
'error' => [],
|
||||
],
|
||||
];
|
||||
|
||||
$this->CheckTransaction($aData);
|
||||
|
||||
@@ -198,7 +194,7 @@ abstract class FormManager
|
||||
$isTransactionValid = \utils::IsTransactionValid($this->oForm->GetTransactionId(), false); //The transaction token is kept in order to preserve BC with ajax forms (the second call would fail if the token is deleted). (The GC will take care of cleaning the token for us later on)
|
||||
if (!$isTransactionValid) {
|
||||
$aData['messages']['error'] += [
|
||||
'_main' => [\Dict::S('UI:Error:InvalidToken')] //This message is generic, if you override this method you should use a more precise message. @see \Combodo\iTop\Portal\Form\ObjectFormManager::CheckTransaction
|
||||
'_main' => [\Dict::S('UI:Error:InvalidToken')], //This message is generic, if you override this method you should use a more precise message. @see \Combodo\iTop\Portal\Form\ObjectFormManager::CheckTransaction
|
||||
];
|
||||
$aData['valid'] = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user