From 0196765eb68a2e9ef7b42ef793ef69192b86530b Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Fri, 31 Oct 2025 08:58:50 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B08772=20-=20automatic=20dependency=20in?= =?UTF-8?q?=20controller=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/Forms/Block/AbstractFormBlock.php | 6 ++---- sources/Forms/Block/IO/AbstractFormIO.php | 17 ++--------------- sources/Forms/Block/IO/FormOutput.php | 5 +++-- sources/Forms/FormBuilder/DependencyMap.php | 13 +++++++++++++ .../Forms/Block/IO/AbstractFormIOTest.php | 15 +++++++++++++++ 5 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 tests/php-unit-tests/unitary-tests/sources/Forms/Block/IO/AbstractFormIOTest.php diff --git a/sources/Forms/Block/AbstractFormBlock.php b/sources/Forms/Block/AbstractFormBlock.php index a6e4f860d..826602ed1 100644 --- a/sources/Forms/Block/AbstractFormBlock.php +++ b/sources/Forms/Block/AbstractFormBlock.php @@ -134,8 +134,7 @@ abstract class AbstractFormBlock */ public function AddInput(string $sName, string $sType): void { - $oFormInput = new FormInput($sName, $sType); - $oFormInput->SetOwnerBlock($this); + $oFormInput = new FormInput($sName, $sType, $this); $this->aFormInputs[$oFormInput->GetName()] = $oFormInput; } @@ -167,8 +166,7 @@ abstract class AbstractFormBlock */ public function AddOutput(string $sName, string $sType, AbstractConverter $oConverter = null): void { - $oFormOutput = new FormOutput($sName, $sType, $oConverter); - $oFormOutput->SetOwnerBlock($this); + $oFormOutput = new FormOutput($sName, $sType, $this, $oConverter); $this->aFormOutputs[$oFormOutput->GetName()] = $oFormOutput; } diff --git a/sources/Forms/Block/IO/AbstractFormIO.php b/sources/Forms/Block/IO/AbstractFormIO.php index ab678082d..4ffbf0932 100644 --- a/sources/Forms/Block/IO/AbstractFormIO.php +++ b/sources/Forms/Block/IO/AbstractFormIO.php @@ -38,10 +38,11 @@ class AbstractFormIO * @param string $sName name of the IO * @param string $sType type of the IO */ - public function __construct(string $sName, string $sType) + public function __construct(string $sName, string $sType, AbstractFormBlock $oOwnerBlock) { $this->sName = $sName; $this->sType = $sType; + $this->oOwnerBlock = $oOwnerBlock; } /** @@ -54,20 +55,6 @@ class AbstractFormIO return $this->oOwnerBlock; } - /** - * Set the owner block. - * - * @param AbstractFormBlock $oOwnerBlock - * - * @return $this - */ - public function SetOwnerBlock(AbstractFormBlock $oOwnerBlock): self - { - $this->oOwnerBlock = $oOwnerBlock; - - return $this; - } - /** * Get the IO name. * diff --git a/sources/Forms/Block/IO/FormOutput.php b/sources/Forms/Block/IO/FormOutput.php index 29ca940ad..55cd68508 100644 --- a/sources/Forms/Block/IO/FormOutput.php +++ b/sources/Forms/Block/IO/FormOutput.php @@ -6,6 +6,7 @@ namespace Combodo\iTop\Forms\Block\IO; +use Combodo\iTop\Forms\Block\AbstractFormBlock; use Combodo\iTop\Forms\Block\IO\Converter\AbstractConverter; /** @@ -27,9 +28,9 @@ class FormOutput extends AbstractFormIO * @param string $sType * @param AbstractConverter|null $oConverter */ - public function __construct(string $sName, string $sType, AbstractConverter $oConverter = null) + public function __construct(string $sName, string $sType, AbstractFormBlock $oOwnerBlock, AbstractConverter $oConverter = null) { - parent::__construct($sName, $sType); + parent::__construct($sName, $sType, $oOwnerBlock); $this->oConverter = $oConverter; } diff --git a/sources/Forms/FormBuilder/DependencyMap.php b/sources/Forms/FormBuilder/DependencyMap.php index 57b0f0f5d..88c05deac 100644 --- a/sources/Forms/FormBuilder/DependencyMap.php +++ b/sources/Forms/FormBuilder/DependencyMap.php @@ -121,6 +121,19 @@ class DependencyMap return $aResult; } + public function GetImpacted(string $sBlockName): array + { + $aImpacted = []; + foreach ($this->aOutputToInputsMap[$sBlockName] as $aBindings) { + foreach ($aBindings as $oBinding) { + $oDestBlock = $oBinding->oDestinationIO->GetOwnerBlock(); + $aImpacted[] = $oDestBlock; + } + } + + return $aImpacted; + } + /** * @param string $sBlockName * diff --git a/tests/php-unit-tests/unitary-tests/sources/Forms/Block/IO/AbstractFormIOTest.php b/tests/php-unit-tests/unitary-tests/sources/Forms/Block/IO/AbstractFormIOTest.php new file mode 100644 index 000000000..90c8ef381 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/sources/Forms/Block/IO/AbstractFormIOTest.php @@ -0,0 +1,15 @@ +