亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Validator.php-7

標簽:
PHP

/**

 * Validate that an attribute is an array.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @return bool

 */

protected function validateArray($attribute, $value)

{// function name is validate the array

    if (! $this->hasAttribute($attribute)) {

        return true;

    }// if it doesn't has this attribute

 

    return is_null($value) || is_array($value);// is_null and is_array

}// validate that an attribute is an array

 

/**

 * Validate that an attribute is a boolean.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @return bool

 */

protected function validateBoolean($attribute, $value)

{

    if (! $this->hasAttribute($attribute)) {

        return true;

    }// has attribute

 

    $acceptable = [true, false, 0, 1, '0', '1'];// can be acceptable options

 

    return is_null($value) || in_array($value, $acceptable, true);// is_null and it is array

}

 

/**

 * Validate that an attribute is an integer.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @return bool

 */

protected function validateInteger($attribute, $value)

{

    if (! $this->hasAttribute($attribute)) {

        return true;

    }//ditto

 

    return is_null($value) || filter_var($value, FILTER_VALIDATE_INT) !== false;

}// has a key like this

 

/**

 * Validate that an attribute is numeric.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @return bool

 */

protected function validateNumeric($attribute, $value)

{

    if (! $this->hasAttribute($attribute)) {

        return true;

    }//just a number not only a int or float

 

    return is_null($value) || is_numeric($value);

}// validate Numeric

 

/**

 * Validate that an attribute is a string.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @return bool

 */

protected function validateString($attribute, $value)

{

    if (! $this->hasAttribute($attribute)) {

        return true;

    }// determine this attribute

 

    return is_null($value) || is_string($value);

}// back value

 

/**

 * Validate the attribute is a valid JSON string.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @return bool

 */

protected function validateJson($attribute, $value)

{

    if (! is_scalar($value) && ! method_exists($value, '__toString')) {

        return false;

    }// scalar means it is a stander value ,just like integer float string boolean

 // other like array object resource

 // if this value is not a scalar and it is can't be change to string

 

    json_decode($value);// use this user function to change it.

 

    return json_last_error() === JSON_ERROR_NONE;// then return this result

}

 

/**

 * Validate that an attribute has a given number of digits.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @param  array   $parameters

 * @return bool

 */

protected function validateDigits($attribute, $value, $parameters)

{

    $this->requireParameterCount(1, $parameters, 'digits');// i hate this user method

 

    return $this->validateNumeric($attribute, $value)

        && strlen((string) $value) == $parameters[0];// just validate the attribute and this value

}//Validate that an attribute has a given number of digits.

 

/**

 * Validate that an attribute is between a given number of digits.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @param  array   $parameters

 * @return bool

 */

protected function validateDigitsBetween($attribute, $value, $parameters)

{

    $this->requireParameterCount(2, $parameters, 'digits_between');

 // this function has three parameter Count

 

    $length = strlen((string) $value);// get string length

 

    return $this->validateNumeric($attribute, $value)

      && $length >= $parameters[0] && $length <= $parameters[1];// a log

}// Validate that an attribute is between a given number of digits

 

/**

 * Validate the size of an attribute.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @param  array   $parameters

 * @return bool

 */

protected function validateSize($attribute, $value, $parameters)

{

    $this->requireParameterCount(1, $parameters, 'size');

 

    return $this->getSize($attribute, $value) == $parameters[0];

}//validate the size of an attribute.

 

/**

 * Validate the size of an attribute is between a set of values.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @param  array   $parameters

 * @return bool

 */

protected function validateBetween($attribute, $value, $parameters)

{

    $this->requireParameterCount(2, $parameters, 'between');

 

    $size = $this->getSize($attribute, $value);//get size

 

    return $size >= $parameters[0] && $size <= $parameters[1];// just return this judge result

}// validate Between

 

/**

 * Validate the size of an attribute is greater than a minimum value.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @param  array   $parameters

 * @return bool

 */

protected function validateMin($attribute, $value, $parameters)

{

    $this->requireParameterCount(1, $parameters, 'min');// get this Parameter Count

 

    return $this->getSize($attribute, $value) >= $parameters[0];//get Size

}// validate the size of an attribute is greater than a minimum value.

 

/**

 * Validate the size of an attribute is less than a maximum value.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @param  array   $parameters

 * @return bool

 */

protected function validateMax($attribute, $value, $parameters)

{

    $this->requireParameterCount(1, $parameters, 'max');

 

    if ($value instanceof UploadedFile && ! $value->isValid()) {

        return false;

    }

 

    return $this->getSize($attribute, $value) <= $parameters[0];

}//validate the size of an attribute is less than a maximum value.

 

/**

 * Get the size of an attribute.

 *

 * @param  string  $attribute

 * @param  mixed   $value

 * @return mixed

 */

protected function getSize($attribute, $value)

{

    $hasNumeric = $this->hasRule($attribute, $this->numericRules);// has Numeric

 

    // This method will determine if the attribute is a number, string, or file and

    // return the proper size accordingly. If it is a number, then number itself

    // is the size. If it is a file, we take kilobytes, and for a string the

    // entire length of the string will be considered the attribute size.

    if (is_numeric($value) && $hasNumeric) {

        return $value;// numeric just return it is self

    } elseif (is_array($value)) {

        return count($value);// get count

    } elseif ($value instanceof File) {

        return $value->getSize() / 1024;// get Size

    }

 

    return mb_strlen($value);// if it is mb_strlen

}


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消