sName = $sName; $this->sType = $sType; $this->oOwnerBlock = $oOwnerBlock; } /** * Get the owner block. * * @return AbstractFormBlock */ public function GetOwnerBlock(): AbstractFormBlock { return $this->oOwnerBlock; } /** * Get the IO name. * * @return string */ public function GetName(): string { return $this->sName; } /** * Set the IO name. * * @param string $sName * * @return self */ public function SetName(string $sName): self { $this->sName = $sName; return $this; } /** * Get the IO data type. * * @return string */ public function GetDataType(): string { return $this->sType; } /** * Set the IO value. * * @param string $sEventType * @param mixed $oValue * * @return self */ public function SetValue(string $sEventType, mixed $oValue): self { $this->aValues[$sEventType] = $oValue; return $this; } /** * Get the IO value. * * @param string|null $sEventType * * @return mixed */ public function GetValue(string $sEventType = null): mixed { if($sEventType === null) { return $this->Value(); } return $this->aValues[$sEventType] ?? null; } /** * Return true if value exist. * * @return bool */ public function HasValue(): bool { return $this->HasEventValue(FormEvents::POST_SET_DATA) || $this->HasEventValue(FormEvents::POST_SUBMIT); } /** * Return true if value exist. * * @param string|null $sEventType * * @return bool */ public function HasEventValue(string $sEventType = null): bool { if($sEventType === null){ return $this->HasValue(); } return array_key_exists($sEventType, $this->aValues) && $this->aValues[$sEventType] !== null; } /** * Return all values. * * @return array */ public function GetValues(): array { return $this->aValues; } /** * Set the IO values. * * @param array $aValues * * @return $this */ public function SetValues(array $aValues): self { $this->aValues = $aValues; return $this; } /** * Get the most relevant value. * * @return mixed */ private function Value(): mixed { if (array_key_exists(FormEvents::POST_SUBMIT, $this->aValues)) { return $this->aValues[FormEvents::POST_SUBMIT]; } if (array_key_exists(FormEvents::POST_SET_DATA, $this->aValues)) { return $this->aValues[FormEvents::POST_SET_DATA]; } return null; } /** * Bind to input. * * @param FormInput $oDestinationIO * * @return FormBinding */ public function BindToInput(FormInput $oDestinationIO): FormBinding { $oBinding = new FormBinding($this, $oDestinationIO); $this->aBindingsToInputs[] = $oBinding; $oDestinationIO->Attach($oBinding); return $oBinding; } /** * Attach a binding. * * @param FormBinding $oFormBinding * * @return void */ public function Attach(FormBinding $oFormBinding) { $this->oBinding = $oFormBinding; } /** * Indicate IO is bound. * * @return bool */ public function IsBound(): bool { return $this->oBinding !== null; } /** * Return the binding. * * @return FormBinding|null */ public function GetBinding(): ?FormBinding { return $this->oBinding; } /** * Indicated inputs data is ready. * * @return bool */ public function IsDataReady(): bool { return $this->HasValue(); } public function HasBindingOut(): bool { return count($this->aBindingsToInputs) > 0; } public function GetBindingsToInputs(): array { return $this->aBindingsToInputs; } }