mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 00:58:48 +02:00
N°8772 - Removed RawFormat and OUTPUT_VALUE
This commit is contained in:
@@ -525,7 +525,7 @@ return array(
|
||||
'Combodo\\iTop\\Forms\\IO\\Format\\BooleanIOFormat' => $baseDir . '/sources/Forms/IO/Format/BooleanIOFormat.php',
|
||||
'Combodo\\iTop\\Forms\\IO\\Format\\ClassIOFormat' => $baseDir . '/sources/Forms/IO/Format/ClassIOFormat.php',
|
||||
'Combodo\\iTop\\Forms\\IO\\Format\\NumberIOFormat' => $baseDir . '/sources/Forms/IO/Format/NumberIOFormat.php',
|
||||
'Combodo\\iTop\\Forms\\IO\\Format\\RawFormat' => $baseDir . '/sources/Forms/IO/Format/RawFormat.php',
|
||||
'Combodo\\iTop\\Forms\\IO\\Format\\StringIOFormat' => $baseDir . '/sources/Forms/IO/Format/StringIOFormat.php',
|
||||
'Combodo\\iTop\\Forms\\Register\\IORegister' => $baseDir . '/sources/Forms/Register/IORegister.php',
|
||||
'Combodo\\iTop\\Forms\\Register\\Option' => $baseDir . '/sources/Forms/Register/Option.php',
|
||||
'Combodo\\iTop\\Forms\\Register\\OptionsRegister' => $baseDir . '/sources/Forms/Register/OptionsRegister.php',
|
||||
|
||||
@@ -906,7 +906,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
|
||||
'Combodo\\iTop\\Forms\\IO\\Format\\BooleanIOFormat' => __DIR__ . '/../..' . '/sources/Forms/IO/Format/BooleanIOFormat.php',
|
||||
'Combodo\\iTop\\Forms\\IO\\Format\\ClassIOFormat' => __DIR__ . '/../..' . '/sources/Forms/IO/Format/ClassIOFormat.php',
|
||||
'Combodo\\iTop\\Forms\\IO\\Format\\NumberIOFormat' => __DIR__ . '/../..' . '/sources/Forms/IO/Format/NumberIOFormat.php',
|
||||
'Combodo\\iTop\\Forms\\IO\\Format\\RawFormat' => __DIR__ . '/../..' . '/sources/Forms/IO/Format/RawFormat.php',
|
||||
'Combodo\\iTop\\Forms\\IO\\Format\\StringIOFormat' => __DIR__ . '/../..' . '/sources/Forms/IO/Format/StringIOFormat.php',
|
||||
'Combodo\\iTop\\Forms\\Register\\IORegister' => __DIR__ . '/../..' . '/sources/Forms/Register/IORegister.php',
|
||||
'Combodo\\iTop\\Forms\\Register\\Option' => __DIR__ . '/../..' . '/sources/Forms/Register/Option.php',
|
||||
'Combodo\\iTop\\Forms\\Register\\OptionsRegister' => __DIR__ . '/../..' . '/sources/Forms/Register/OptionsRegister.php',
|
||||
|
||||
@@ -11,7 +11,6 @@ use Combodo\iTop\Forms\Block\Base\FormBlock;
|
||||
use Combodo\iTop\Forms\IFormBlock;
|
||||
use Combodo\iTop\Forms\IO\AbstractFormIO;
|
||||
use Combodo\iTop\Forms\IO\Converter\AbstractConverter;
|
||||
use Combodo\iTop\Forms\IO\Format\RawFormat;
|
||||
use Combodo\iTop\Forms\IO\FormInput;
|
||||
use Combodo\iTop\Forms\IO\FormOutput;
|
||||
use Combodo\iTop\Forms\Register\IORegister;
|
||||
@@ -27,7 +26,6 @@ use Combodo\iTop\Forms\Register\OptionsRegister;
|
||||
abstract class AbstractFormBlock implements IFormBlock
|
||||
{
|
||||
// Outputs
|
||||
public const OUTPUT_VALUE = 'value';
|
||||
|
||||
/** @var null|FormBlock */
|
||||
private ?FormBlock $oParent = null;
|
||||
@@ -393,7 +391,6 @@ abstract class AbstractFormBlock implements IFormBlock
|
||||
*/
|
||||
protected function RegisterIO(IORegister $oIORegister): void
|
||||
{
|
||||
$oIORegister->AddOutput(self::OUTPUT_VALUE, RawFormat::class);
|
||||
}
|
||||
|
||||
protected function AfterIORegistered(IORegister $oIORegister): void
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
namespace Combodo\iTop\Forms\Block\Base;
|
||||
|
||||
use Combodo\iTop\Forms\Block\AbstractTypeFormBlock;
|
||||
use Combodo\iTop\Forms\IO\Converter\StringToBooleanConverter;
|
||||
use Combodo\iTop\Forms\IO\Format\BooleanIOFormat;
|
||||
use Combodo\iTop\Forms\Register\IORegister;
|
||||
use Combodo\iTop\Forms\Register\OptionsRegister;
|
||||
@@ -40,6 +39,6 @@ class CheckboxFormBlock extends AbstractTypeFormBlock
|
||||
protected function RegisterIO(IORegister $oIORegister): void
|
||||
{
|
||||
parent::RegisterIO($oIORegister);
|
||||
$oIORegister->AddOutput(self::OUTPUT_CHECKED, BooleanIOFormat::class, new StringToBooleanConverter());
|
||||
$oIORegister->AddOutput(self::OUTPUT_CHECKED, BooleanIOFormat::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Combodo\iTop\Forms\Block\Base;
|
||||
use Combodo\iTop\Forms\Block\AbstractTypeFormBlock;
|
||||
use Combodo\iTop\Forms\FormType\Base\ChoiceFormType;
|
||||
use Combodo\iTop\Forms\IO\Converter\ChoiceValueToLabelConverter;
|
||||
use Combodo\iTop\Forms\IO\Format\RawFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\StringIOFormat;
|
||||
use Combodo\iTop\Forms\Register\IORegister;
|
||||
|
||||
/**
|
||||
@@ -21,6 +21,7 @@ class ChoiceFormBlock extends AbstractTypeFormBlock
|
||||
{
|
||||
// Outputs
|
||||
public const OUTPUT_LABEL = 'label';
|
||||
public const OUTPUT_CODE = 'code';
|
||||
|
||||
/** @inheritdoc */
|
||||
public function GetFormType(): string
|
||||
@@ -32,6 +33,7 @@ class ChoiceFormBlock extends AbstractTypeFormBlock
|
||||
protected function RegisterIO(IORegister $oIORegister): void
|
||||
{
|
||||
parent::RegisterIO($oIORegister);
|
||||
$oIORegister->AddOutput(self::OUTPUT_LABEL, RawFormat::class, new ChoiceValueToLabelConverter($this));
|
||||
$oIORegister->AddOutput(self::OUTPUT_LABEL, StringIOFormat::class, new ChoiceValueToLabelConverter($this));
|
||||
$oIORegister->AddOutput(self::OUTPUT_CODE, StringIOFormat::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
|
||||
use Combodo\iTop\Forms\Block\FormBlockException;
|
||||
use Combodo\iTop\Forms\IO\Format\AttributeIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\ClassIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\RawFormat;
|
||||
use Combodo\iTop\Forms\Register\IORegister;
|
||||
use Combodo\iTop\Forms\Register\OptionsRegister;
|
||||
use Exception;
|
||||
@@ -46,7 +45,7 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock
|
||||
parent::RegisterIO($oIORegister);
|
||||
$oIORegister->AddInput(self::INPUT_CLASS_NAME, ClassIOFormat::class);
|
||||
$oIORegister->AddInput(self::INPUT_ATTRIBUTE, AttributeIOFormat::class);
|
||||
$oIORegister->AddOutput(self::OUTPUT_VALUE, RawFormat::class);
|
||||
$oIORegister->AddOutput(self::OUTPUT_VALUE, AttributeIOFormat::class);
|
||||
}
|
||||
|
||||
/** @inheritdoc
|
||||
|
||||
@@ -10,7 +10,6 @@ namespace Combodo\iTop\Forms\Block\Expression;
|
||||
use Combodo\iTop\Forms\Block\AbstractFormBlock;
|
||||
use Combodo\iTop\Forms\Block\FormBlockException;
|
||||
use Combodo\iTop\Forms\IO\Format\BooleanIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\RawFormat;
|
||||
use Combodo\iTop\Forms\Register\IORegister;
|
||||
use Expression;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
@@ -69,7 +68,6 @@ class ExpressionFormBlock extends AbstractFormBlock
|
||||
$bResult = boolval($result);
|
||||
$this->GetOutput(self::OUTPUT_RESULT)->SetValue($sEventType, new BooleanIOFormat($bResult));
|
||||
$this->GetOutput(self::OUTPUT_RESULT_INVERT)->SetValue($sEventType, new BooleanIOFormat(!$bResult));
|
||||
$this->GetOutput(self::OUTPUT_VALUE)->SetValue($sEventType, new RawFormat($result));
|
||||
} catch (\Exception $e) {
|
||||
throw new FormBlockException('Compute expression '.json_encode($sExpression).' block issue', 0, $e);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
namespace Combodo\iTop\Forms\IO\Converter;
|
||||
|
||||
use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
|
||||
use Combodo\iTop\Forms\IO\Format\RawFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\AttributeIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\StringIOFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -23,14 +24,17 @@ class ChoiceValueToLabelConverter extends AbstractConverter
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function Convert(mixed $oData): ?RawFormat
|
||||
public function Convert(mixed $oData): ?StringIOFormat
|
||||
{
|
||||
if (is_null($oData) || is_array($oData)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$aOptions = array_flip($this->oChoiceBlock->GetOption('choices'));
|
||||
if (!array_key_exists($oData, $aOptions) || is_null($aOptions[$oData]) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new RawFormat($aOptions[$oData]);
|
||||
return new StringIOFormat($aOptions[$oData]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class FormBinding
|
||||
// Check IOFormat validity
|
||||
$sSourceDataType = $oSourceIO->GetDataType();
|
||||
$sDestinationDataType = $oDestinationIO->GetDataType();
|
||||
if (!$sSourceDataType::IsCompatible($sDestinationDataType)) {
|
||||
if ($sSourceDataType !== $sDestinationDataType) {
|
||||
throw new FormBlockIOException('binding '.json_encode($sSourceDataType).' to '.json_encode($sDestinationDataType).' is not supported');
|
||||
}
|
||||
$this->oDestinationIO = $oDestinationIO;
|
||||
|
||||
@@ -12,6 +12,4 @@ use JsonSerializable;
|
||||
abstract class AbstractIOFormat implements JsonSerializable
|
||||
{
|
||||
abstract public function jsonSerialize(): mixed;
|
||||
|
||||
abstract public static function IsCompatible(string $sOtherFormatClass): bool;
|
||||
}
|
||||
|
||||
@@ -21,9 +21,4 @@ class AttributeIOFormat extends AbstractIOFormat
|
||||
{
|
||||
return $this->sAttributeName;
|
||||
}
|
||||
|
||||
public static function IsCompatible(string $sOtherFormatClass): bool
|
||||
{
|
||||
return is_a($sOtherFormatClass, AttributeIOFormat::class, true) || is_a($sOtherFormatClass, RawFormat::class, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,4 @@ class BooleanIOFormat extends AbstractIOFormat
|
||||
{
|
||||
return $this->bValue;
|
||||
}
|
||||
|
||||
public static function IsCompatible(string $sOtherFormatClass): bool
|
||||
{
|
||||
return is_a($sOtherFormatClass, BooleanIOFormat::class, true) || is_a($sOtherFormatClass, RawFormat::class, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,4 @@ class ClassIOFormat extends AbstractIOFormat
|
||||
{
|
||||
return $this->sClassName;
|
||||
}
|
||||
|
||||
public static function IsCompatible(string $sOtherFormatClass): bool
|
||||
{
|
||||
return is_a($sOtherFormatClass, ClassIOFormat::class, true) || is_a($sOtherFormatClass, RawFormat::class, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,4 @@ class NumberIOFormat extends AbstractIOFormat
|
||||
{
|
||||
return strval($this->oValue);
|
||||
}
|
||||
|
||||
public static function IsCompatible(string $sOtherFormatClass): bool
|
||||
{
|
||||
return is_a($sOtherFormatClass, NumberIOFormat::class, true) || is_a($sOtherFormatClass, RawFormat::class, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2025 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Forms\IO\Format;
|
||||
|
||||
class RawFormat extends AbstractIOFormat
|
||||
class StringIOFormat extends AbstractIOFormat
|
||||
{
|
||||
public string $sValue;
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
*/
|
||||
public function __construct(string $sValue)
|
||||
{
|
||||
$this->sValue = $sValue;
|
||||
@@ -20,9 +27,4 @@ class RawFormat extends AbstractIOFormat
|
||||
{
|
||||
return $this->sValue;
|
||||
}
|
||||
|
||||
public static function IsCompatible(string $sOtherFormatClass): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace Combodo\iTop\Test\UnitTest\sources\Forms;
|
||||
|
||||
use Combodo\iTop\Forms\Block\AbstractFormBlock;
|
||||
use Combodo\iTop\Forms\Block\Base\FormBlock;
|
||||
use Combodo\iTop\Forms\IO\Format\RawFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\StringIOFormat;
|
||||
use Combodo\iTop\Forms\IO\FormInput;
|
||||
use Combodo\iTop\Forms\IO\FormOutput;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
@@ -21,14 +21,14 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
abstract class AbstractFormsTest extends ItopDataTestCase
|
||||
{
|
||||
public function GivenInput(string $sName, string $sType = RawFormat::class): FormInput
|
||||
public function GivenInput(string $sName, string $sType = StringIOFormat::class): FormInput
|
||||
{
|
||||
$oBlock = $this->GivenFormBlock($sName.'_block');
|
||||
|
||||
return new FormInput($sName.'_input', $sType, $oBlock);
|
||||
}
|
||||
|
||||
public function GivenOutput(string $sName, string $sType = RawFormat::class): FormOutput
|
||||
public function GivenOutput(string $sName, string $sType = StringIOFormat::class): FormOutput
|
||||
{
|
||||
$oBlock = $this->GivenFormBlock($sName.'_block');
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2025 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\sources\Forms\IO\Converter;
|
||||
|
||||
use Combodo\iTop\Forms\IO\Converter\StringToBooleanConverter;
|
||||
use Combodo\iTop\Test\UnitTest\sources\Forms\AbstractFormsTest;
|
||||
|
||||
class TestStringToBooleanConverter extends AbstractFormsTest
|
||||
{
|
||||
public function testConvertingStringToBooleanIsOK()
|
||||
{
|
||||
$oConverter = new StringToBooleanConverter();
|
||||
$oIOFormat = $oConverter->Convert('1');
|
||||
|
||||
$this->assertTrue($oIOFormat->IsTrue());
|
||||
|
||||
//$oIOFormat = $oConverter->Convert(null);
|
||||
//$this->assertFalse($oIOFormat->IsFalse());
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ use Combodo\iTop\Forms\IO\Format\AttributeIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\BooleanIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\ClassIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\NumberIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\RawFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\StringIOFormat;
|
||||
use Combodo\iTop\Forms\IO\FormBinding;
|
||||
use Combodo\iTop\Forms\IO\FormBlockIOException;
|
||||
use Combodo\iTop\Test\UnitTest\sources\Forms\AbstractFormsTest;
|
||||
@@ -178,18 +178,27 @@ class FormBindingTest extends AbstractFormsTest
|
||||
'Attribute -> Boolean' => [AttributeIOFormat::class, BooleanIOFormat::class],
|
||||
'Attribute -> Class' => [AttributeIOFormat::class, ClassIOFormat::class],
|
||||
'Attribute -> Number' => [AttributeIOFormat::class, NumberIOFormat::class],
|
||||
'Attribute -> String' => [AttributeIOFormat::class, StringIOFormat::class],
|
||||
|
||||
'Boolean => Attribute' => [BooleanIOFormat::class, AttributeIOFormat::class],
|
||||
'Boolean => Class' => [BooleanIOFormat::class, ClassIOFormat::class],
|
||||
'Boolean => Number' => [BooleanIOFormat::class, NumberIOFormat::class],
|
||||
'Boolean -> String' => [BooleanIOFormat::class, StringIOFormat::class],
|
||||
|
||||
'Class => Attribute' => [ClassIOFormat::class, AttributeIOFormat::class],
|
||||
'Class => Boolean' => [ClassIOFormat::class, BooleanIOFormat::class],
|
||||
'Class => Number' => [ClassIOFormat::class, NumberIOFormat::class],
|
||||
'Class -> String' => [ClassIOFormat::class, StringIOFormat::class],
|
||||
|
||||
'Number => Attribute' => [NumberIOFormat::class, AttributeIOFormat::class],
|
||||
'Number => Class' => [NumberIOFormat::class, ClassIOFormat::class],
|
||||
'Number => Boolean' => [NumberIOFormat::class, BooleanIOFormat::class],
|
||||
'Number -> String' => [NumberIOFormat::class, StringIOFormat::class],
|
||||
|
||||
'String => Attribute' => [StringIOFormat::class, AttributeIOFormat::class],
|
||||
'String => Class' => [StringIOFormat::class, ClassIOFormat::class],
|
||||
'String => Boolean' => [StringIOFormat::class, BooleanIOFormat::class],
|
||||
'String -> Number' => [StringIOFormat::class, NumberIOFormat::class],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -214,22 +223,10 @@ class FormBindingTest extends AbstractFormsTest
|
||||
{
|
||||
return [
|
||||
'Attribute -> Attribute' => [AttributeIOFormat::class, AttributeIOFormat::class],
|
||||
'Attribute -> Raw' => [AttributeIOFormat::class, RawFormat::class],
|
||||
|
||||
'Boolean => Boolean' => [BooleanIOFormat::class, BooleanIOFormat::class],
|
||||
'Boolean => Raw' => [BooleanIOFormat::class, RawFormat::class],
|
||||
|
||||
'Class => Class' => [ClassIOFormat::class, ClassIOFormat::class],
|
||||
'Class => Raw' => [ClassIOFormat::class, RawFormat::class],
|
||||
|
||||
'Number => Number' => [NumberIOFormat::class, NumberIOFormat::class],
|
||||
'Number => Raw' => [NumberIOFormat::class, RawFormat::class],
|
||||
|
||||
'Raw => Raw' => [RawFormat::class, RawFormat::class],
|
||||
'Raw => Attribute' => [RawFormat::class, AttributeIOFormat::class],
|
||||
'Raw => Boolean' => [RawFormat::class, BooleanIOFormat::class],
|
||||
'Raw => Class' => [RawFormat::class, ClassIOFormat::class],
|
||||
'Raw => Number' => [RawFormat::class, NumberIOFormat::class],
|
||||
'String => String' => [StringIOFormat::class, StringIOFormat::class],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user