SetValid(true); $this->EmptyErrorMessages(); if ($this->bValidationDisabled) { return $this->GetValid(); } $bEmpty = (($this->GetCurrentValue() === null) || ($this->GetCurrentValue() === '')); if (!$bEmpty || $this->GetMandatory()) { foreach ($this->GetValidators() as $oValidator) { $aValidationErrorMessages = $oValidator->Validate($this->GetCurrentValue()); if (count($aValidationErrorMessages) > 0) { $this->SetValid(false); foreach ($aValidationErrorMessages as $sErrorMessage) { $this->AddErrorMessage($sErrorMessage); } } } } return $this->GetValid(); } public function SetMandatory(bool $bMandatory) { // Before changing the property, we check if it was already mandatory. If not, we had the mandatory validator if ($bMandatory && !$this->bMandatory) { $this->AddValidator($this->GetMandatoryValidatorInstance()); } if (false === $bMandatory) { foreach ($this->aValidators as $iKey => $oValue) { if ($oValue instanceof MandatoryValidator) { unset($this->aValidators[$iKey]); } } } $this->bMandatory = $bMandatory; return parent::SetMandatory($bMandatory); } }