栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

Validator.php-4

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Validator.php-4

   protected function hasNotFailedPreviousRuleIfPresenceRule($rule, $attribute)

   {//this function name it is to long

    //but can tell all about this function action

    // determine it is has not failed previousRule if Presence Rule

       return in_array($rule, ['Unique', 'Exists'])

                       ? ! $this->messages->has($attribute) : true;

    // if this rule is unique or exists, we need determine this attribute other wo just return it it ok!

   }// determine if it is necessary presence validation

 

   

   protected function addFailure($attribute, $rule, $parameters)

   {

       $this->addError($attribute, $rule, $parameters);//add Error message

 

       $this->failedRules[$attribute][$rule] = $parameters;// insert this parameters into this failed Rules

   }// add a failed rule and error message into this collection

 

   

   protected function addError($attribute, $rule, $parameters)

   {

       $message = $this->getMessage($attribute, $rule);//first ,get all message about this rule

 

       $message = $this->doReplacements($message, $attribute, $rule, $parameters);// change this message into this right format message

 

       $this->messages->add($attribute, $message);// add it to this attribute

   }// this is a small wrap about addFailed rule

 

   

   protected function validateSometimes()

   {

       return true;

   }// Validate optional attributes.

// return true;

 

   

   protected function validateBail()

   {

       return true;

   }// just return ok, in this break type

 

   

   protected function shouldStopValidating($attribute)

   {

       if (! $this->hasRule($attribute, ['Bail'])) {

           return false;

       }// no Bail switch no true,just return false,

 

       return $this->messages->has($attribute);// if has it,just return this message.

   }// determine this Bail messages

 

   

   protected function validateRequired($attribute, $value)

   {

       if (is_null($value)) {// no $value no ture

           return false;

       } elseif (is_string($value) && trim($value) === '') {

           return false;// a null string just return false

       } elseif ((is_array($value) || $value instanceof Countable) && count($value) < 1) {

           return false;// array or a structural and no value in this structural

       } elseif ($value instanceof File) {// if a file

           return (string) $value->getPath() != '';// can't be null

       }

   //in the end, we will found only this value parameters has value whatever it is,just return true.

       return true;

   }//Validate a required attribute is exists

 

   

   protected function validateFilled($attribute, $value)

   {

       if (array_key_exists($attribute, $this->data) || array_key_exists($attribute, $this->files)) {

           return $this->validateRequired($attribute, $value);// a filled just a required wrap

       }// two type

 

       return true;// normal it is true

   }// present : now

// means this attribute just has a value

 

   

   protected function anyFailingRequired(array $attributes)

   {

       foreach ($attributes as $key) {

           if (! $this->validateRequired($key, $this->getValue($key))) {

               return true;

           }

       }// same to ditto

    // ues a loop about this attribute

 

       return false;

   }//Determine if any of the given attributes fail the required test.

 

   

   protected function allFailingRequired(array $attributes)

   {

       foreach ($attributes as $key) {

           if ($this->validateRequired($key, $this->getValue($key))) {

               return false;

           }

       }

 

       return true;

   }// all Fail just any ,the same , fool or stupid ?

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/229585.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号