Webiny\Component\Entity\Attribute\AbstractAttribute::validate PHP Метод

validate() защищенный Метод

Perform validation against given value
protected validate ( &$value )
$value
    protected function validate(&$value)
    {
        $validators = $this->getValidators();
        unset($validators['required']);
        // Do not validate if attribute value is not required and empty value is given
        // 'empty' function is not suitable for this check here
        if (!$this->required && (is_null($value) || $value === '')) {
            return;
        }
        $messages = $this->getValidationMessages();
        foreach ($validators as $validator) {
            $this->applyValidator($validator, $this->attribute, $value, $messages);
        }
    }

Usage Example

Пример #1
0
 /**
  * Perform validation against given value
  *
  * @param $value
  *
  * @throws ValidationException
  * @return $this
  */
 protected function validate(&$value)
 {
     if ($this->str($value)->contains(',')) {
         $value = $this->str($value)->replace(',', '.')->val();
     }
     $value = floatval($value);
     if (!$this->isNumber($value)) {
         $this->expected('number', gettype($value));
     }
     parent::validate($value);
     return $this;
 }
All Usage Examples Of Webiny\Component\Entity\Attribute\AbstractAttribute::validate