[李景山php]每天laravel-20161004|Validator.php-4


    /**
     * Determine if it's a necessary presence validation.
     *
     * This is to avoid possible database type comparison errors.
     *
     * @param  string  $rule
     * @param  string  $attribute
     * @return bool
     */
    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

    /**
     * Add a failed rule and error message to the collection.
     *
     * @param  string  $attribute
     * @param  string  $rule
     * @param  array   $parameters
     * @return void
     */
    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

    /**
     * Add an error message to the validator's collection of messages.
     *
     * @param  string  $attribute
     * @param  string  $rule
     * @param  array   $parameters
     * @return void
     */
    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

    /**
     * "Validate" optional attributes.
     *
     * Always returns true, just lets us put sometimes in rules.
     *
     * @return bool
     */
    protected function validateSometimes()
    {
        return true;
    }// Validate optional attributes.
    // return true;

    /**
     * "Break" on first validation fail.
     *
     * Always returns true, just lets us put "bail" in rules.
     *
     * @return bool
     */
    protected function validateBail()
    {
        return true;
    }// just return ok, in this break type

    /**
     * Stop on error if "bail" rule is assigned and attribute has a message.
     *
     * @param  string  $attribute
     * @return bool
     */
    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

    /**
     * Validate that a required attribute exists.
     *
     * @param  string  $attribute
     * @param  mixed   $value
     * @return bool
     */
    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

    /**
     * Validate the given attribute is filled if it is present.
     *
     * @param  string  $attribute
     * @param  mixed   $value
     * @return bool
     */
    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

    /**
     * Determine if any of the given attributes fail the required test.
     *
     * @param  array  $attributes
     * @return bool
     */
    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.

    /**
     * Determine if all of the given attributes fail the required test.
     *
     * @param  array  $attributes
     * @return bool
     */
    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 ?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值