[李景山php]每天laravel-20161011|Validator.php-11

來源:互聯網
上載者:User

標籤:function   return   before   

/** * Given two date/time strings, check that one is after the other. * * @param  string  $format * @param  string  $before * @param  string  $after * @return bool */protected function checkDateTimeOrder($format, $before, $after){    $before = $this->getDateTimeWithOptionalFormat($format, $before);// format it    $after = $this->getDateTimeWithOptionalFormat($format, $after);// format after    return ($before && $after) && ($after > $before);// a big logic}// get two date/time strings, check that one is after the other./** * Get a DateTime instance from a string. * * @param  string  $format * @param  string  $value * @return \DateTime|null */protected function getDateTimeWithOptionalFormat($format, $value){//Get a DateTime instance from a sting.    $date = DateTime::createFromFormat($format, $value);//Date::createFromFormat    if ($date) {// if date        return $date;    }    try {// return new DateTime        return new DateTime($value);    } catch (Exception $e) {        // do nothing    }}/** * Validate that an attribute is a valid timezone. * * @param  string  $attribute * @param  mixed   $value * @return bool */protected function validateTimezone($attribute, $value){    try {        new DateTimeZone($value);    } catch (Exception $e) {        return false;    }    return true;}//validate timezone/** * Get the date format for an attribute if it has one. * * @param  string  $attribute * @return string|null */protected function getDateFormat($attribute){    if ($result = $this->getRule($attribute, ‘DateFormat‘)) {        return $result[1][0];    }}// Get the date format from an attribute if it has one./** * Get the validation message for an attribute and rule. * * @param  string  $attribute * @param  string  $rule * @return string */protected function getMessage($attribute, $rule){    $lowerRule = Str::snake($rule);// use snake method to get this you  want    $inlineMessage = $this->getInlineMessage($attribute, $lowerRule);// get message    // First we will retrieve the custom message for the validation rule if one    // exists. If a custom validation message is being used we‘ll return the    // custom message, otherwise we‘ll keep searching for a valid message.    if (! is_null($inlineMessage)) {        return $inlineMessage;    }// if it is a good message    $customKey = "validation.custom.{$attribute}.{$lowerRule}";// this can  get a good key    $customMessage = $this->getCustomMessageFromTranslator($customKey);    // First we check for a custom defined validation message for the attribute    // and rule. This allows the developer to specify specific messages for    // only some attributes and rules that need to get specially formed.    if ($customMessage !== $customKey) {        return $customMessage;    }// return the custom message    // If the rule being validated is a "size" rule, we will need to gather the    // specific error message for the type of attribute being validated such    // as a number, file or string which all have different message types.    elseif (in_array($rule, $this->sizeRules)) {        return $this->getSizeMessage($attribute, $rule);    }// specific error    // Finally, if no developer specified messages have been set, and no other    // special messages apply for this rule, we will just pull the default    // messages out of the translator service for this validation rule.    $key = "validation.{$lowerRule}";    if ($key != ($value = $this->translator->trans($key))) {        return $value;    }// just message    return $this->getInlineMessage(        $attribute, $lowerRule, $this->fallbackMessages    ) ?: $key;// return key}


本文出自 “專註php” 部落格,請務必保留此出處http://jingshanls.blog.51cto.com/3357095/1837147

[李景山php]每天laravel-20161011|Validator.php-11

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.