validate() protected method

Perform validation against given value
protected validate ( &$value )
$value
コード例 #1
0
ファイル: FloatAttribute.php プロジェクト: Webiny/Framework
 /**
  * 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;
 }
コード例 #2
0
ファイル: IntegerAttribute.php プロジェクト: Webiny/Framework
 /**
  * Perform validation against given value
  *
  * @param $value
  *
  * @throws ValidationException
  * @return $this
  */
 protected function validate(&$value)
 {
     if ($this->isString($value) && $this->isNumber($value)) {
         if (!$this->str($value)->contains('.') && !$this->str($value)->contains(',')) {
             $value = intval($value);
         }
     }
     if (!$this->isInteger($value)) {
         $this->expected('integer', gettype($value));
     }
     parent::validate($value);
     return $this;
 }
コード例 #3
0
ファイル: CharAttribute.php プロジェクト: Webiny/Framework
 /**
  * Perform validation against given value
  *
  * @param $value
  *
  * @throws ValidationException
  * @return $this
  */
 protected function validate(&$value)
 {
     if ($value instanceof AbstractEntity) {
         $value = $value->id;
     }
     if ($value != null && !$this->isString($value) && !$this->isNumber($value)) {
         $this->expected('string, number or AbstractEntity', gettype($value));
     }
     // Make sure it's a string even if it is a number (convert to numeric string)
     $value = '' . $value;
     parent::validate($value);
     return $this;
 }
コード例 #4
0
ファイル: ArrayAttribute.php プロジェクト: webiny/entity
 /**
  * Perform validation against given value
  *
  * @param $value
  *
  * @return $this
  * @throws ValidationException
  */
 protected function validate(&$value)
 {
     if ($this->isNull($value)) {
         return $this;
     }
     if (!$this->isArray($value) && !$this->isArrayObject($value)) {
         $this->expected('array or ArrayObject', gettype($value));
     }
     // Call parent method
     parent::validate($value);
     // Validate array keys
     $this->validateNestedKeys($value);
     return $this;
 }
コード例 #5
0
ファイル: BooleanAttribute.php プロジェクト: Webiny/Framework
 /**
  * Perform validation against given value
  *
  * @param $value
  *
  * @return $this
  */
 protected function validate(&$value)
 {
     $value = StdObjectWrapper::toBool($value);
     parent::validate($value);
     return $this;
 }