diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php index 1f254f382..cfcf6c839 100644 --- a/lib/composer/autoload_classmap.php +++ b/lib/composer/autoload_classmap.php @@ -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', diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php index 0238b2704..b9ac234ec 100644 --- a/lib/composer/autoload_static.php +++ b/lib/composer/autoload_static.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', diff --git a/sources/Forms/Block/AbstractFormBlock.php b/sources/Forms/Block/AbstractFormBlock.php index a097b54f4..59a685751 100644 --- a/sources/Forms/Block/AbstractFormBlock.php +++ b/sources/Forms/Block/AbstractFormBlock.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 diff --git a/sources/Forms/Block/Base/CheckboxFormBlock.php b/sources/Forms/Block/Base/CheckboxFormBlock.php index 4ef18d6c5..cc527b7d7 100644 --- a/sources/Forms/Block/Base/CheckboxFormBlock.php +++ b/sources/Forms/Block/Base/CheckboxFormBlock.php @@ -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); } } diff --git a/sources/Forms/Block/Base/ChoiceFormBlock.php b/sources/Forms/Block/Base/ChoiceFormBlock.php index ad55adb2a..047751651 100644 --- a/sources/Forms/Block/Base/ChoiceFormBlock.php +++ b/sources/Forms/Block/Base/ChoiceFormBlock.php @@ -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); } } diff --git a/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php b/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php index a1905b054..e44863f7b 100644 --- a/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php +++ b/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php @@ -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 diff --git a/sources/Forms/Block/Expression/ExpressionFormBlock.php b/sources/Forms/Block/Expression/ExpressionFormBlock.php index e42d52953..48c9c6fea 100644 --- a/sources/Forms/Block/Expression/ExpressionFormBlock.php +++ b/sources/Forms/Block/Expression/ExpressionFormBlock.php @@ -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); } diff --git a/sources/Forms/IO/Converter/ChoiceValueToLabelConverter.php b/sources/Forms/IO/Converter/ChoiceValueToLabelConverter.php index 8785ad8d8..6cb092d78 100644 --- a/sources/Forms/IO/Converter/ChoiceValueToLabelConverter.php +++ b/sources/Forms/IO/Converter/ChoiceValueToLabelConverter.php @@ -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]); } } diff --git a/sources/Forms/IO/FormBinding.php b/sources/Forms/IO/FormBinding.php index 5966e01fb..103c469e0 100644 --- a/sources/Forms/IO/FormBinding.php +++ b/sources/Forms/IO/FormBinding.php @@ -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; diff --git a/sources/Forms/IO/Format/AbstractIOFormat.php b/sources/Forms/IO/Format/AbstractIOFormat.php index 06faf5a0e..73822a45d 100644 --- a/sources/Forms/IO/Format/AbstractIOFormat.php +++ b/sources/Forms/IO/Format/AbstractIOFormat.php @@ -12,6 +12,4 @@ use JsonSerializable; abstract class AbstractIOFormat implements JsonSerializable { abstract public function jsonSerialize(): mixed; - - abstract public static function IsCompatible(string $sOtherFormatClass): bool; } diff --git a/sources/Forms/IO/Format/AttributeIOFormat.php b/sources/Forms/IO/Format/AttributeIOFormat.php index 336233faf..f39cac1f2 100644 --- a/sources/Forms/IO/Format/AttributeIOFormat.php +++ b/sources/Forms/IO/Format/AttributeIOFormat.php @@ -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); - } } diff --git a/sources/Forms/IO/Format/BooleanIOFormat.php b/sources/Forms/IO/Format/BooleanIOFormat.php index 9a4a13c1b..24e4845a7 100644 --- a/sources/Forms/IO/Format/BooleanIOFormat.php +++ b/sources/Forms/IO/Format/BooleanIOFormat.php @@ -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); - } } diff --git a/sources/Forms/IO/Format/ClassIOFormat.php b/sources/Forms/IO/Format/ClassIOFormat.php index a8d57886a..b9e28301c 100644 --- a/sources/Forms/IO/Format/ClassIOFormat.php +++ b/sources/Forms/IO/Format/ClassIOFormat.php @@ -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); - } } diff --git a/sources/Forms/IO/Format/NumberIOFormat.php b/sources/Forms/IO/Format/NumberIOFormat.php index 806154bd6..5d1aaad54 100644 --- a/sources/Forms/IO/Format/NumberIOFormat.php +++ b/sources/Forms/IO/Format/NumberIOFormat.php @@ -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); - } } diff --git a/sources/Forms/IO/Format/RawFormat.php b/sources/Forms/IO/Format/StringIOFormat.php similarity index 59% rename from sources/Forms/IO/Format/RawFormat.php rename to sources/Forms/IO/Format/StringIOFormat.php index dfef56663..497f929fc 100644 --- a/sources/Forms/IO/Format/RawFormat.php +++ b/sources/Forms/IO/Format/StringIOFormat.php @@ -1,11 +1,18 @@ sValue = $sValue; @@ -20,9 +27,4 @@ class RawFormat extends AbstractIOFormat { return $this->sValue; } - - public static function IsCompatible(string $sOtherFormatClass): bool - { - return true; - } -} +} \ No newline at end of file diff --git a/tests/php-unit-tests/unitary-tests/sources/Forms/AbstractFormsTest.php b/tests/php-unit-tests/unitary-tests/sources/Forms/AbstractFormsTest.php index 2de72cec8..0877ffe36 100644 --- a/tests/php-unit-tests/unitary-tests/sources/Forms/AbstractFormsTest.php +++ b/tests/php-unit-tests/unitary-tests/sources/Forms/AbstractFormsTest.php @@ -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'); diff --git a/tests/php-unit-tests/unitary-tests/sources/Forms/IO/Converter/TestStringToBooleanConverter.php b/tests/php-unit-tests/unitary-tests/sources/Forms/IO/Converter/TestStringToBooleanConverter.php deleted file mode 100644 index 896f1f56f..000000000 --- a/tests/php-unit-tests/unitary-tests/sources/Forms/IO/Converter/TestStringToBooleanConverter.php +++ /dev/null @@ -1,25 +0,0 @@ -Convert('1'); - - $this->assertTrue($oIOFormat->IsTrue()); - - //$oIOFormat = $oConverter->Convert(null); - //$this->assertFalse($oIOFormat->IsFalse()); - } -} diff --git a/tests/php-unit-tests/unitary-tests/sources/Forms/IO/FormBindingTest.php b/tests/php-unit-tests/unitary-tests/sources/Forms/IO/FormBindingTest.php index e8232b798..1b8c5d051 100644 --- a/tests/php-unit-tests/unitary-tests/sources/Forms/IO/FormBindingTest.php +++ b/tests/php-unit-tests/unitary-tests/sources/Forms/IO/FormBindingTest.php @@ -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], ]; }