[李景山php]每天laravel-20161003|Validator.php-3

   /**
    * Validate a given attribute against a rule.
    *
    * @param  string  $attribute
    * @param  string  $rule
    * @return void
    */
   protected function validate($attribute, $rule)
   {// validate a given attribute against a rule.
       list($rule, $parameters) = $this->parseRule($rule);//list function to get the

       if ($rule == ‘‘) {
           return;
       }// if no rule

       // First we will get the numeric keys for the given attribute in case the field is nested in
       // an array. Then we determine if the given rule accepts other field names as parameters.
       // If so, we will replace any asterisks found in the parameters with the numeric keys.
       if (($keys = $this->getNumericKeys($attribute)) &&
           $this->dependsOnOtherFields($rule)) {//get number and depends
           $parameters = $this->replaceAsterisksInParameters($parameters, $keys);
       }// a normal logic function

       // We will get the value for the given attribute from the array of data and then
       // verify that the attribute is indeed validatable. Unless the rule implies
       // that the attribute is required, rules are not run for missing values.
       $value = $this->getValue($attribute);
    // We will get the value for the given attribute from the array of data and then
    // verify that the attribute is indeed vaidatable.Unless the rule implies
    // that the attribute is required,rules are not run for missing values.

       $validatable = $this->isValidatable($rule, $attribute, $value);
    // determine validatable

       $method = "validate{$rule}";// get method way

       if ($validatable && ! $this->$method($attribute, $value, $parameters, $this)) {
           $this->addFailure($attribute, $rule, $parameters);
       }// determine all
   }

   /**
    * Returns the data which was valid.
    *
    * @return array
    */
   public function valid()
   {
       if (! $this->messages) {
           $this->passes();
       }

       return array_diff_key($this->data, $this->messages()->toArray());
   }// change it is a real valid data

   /**
    * Returns the data which was invalid.
    *
    * @return array
    */
   public function invalid()
   {
       if (! $this->messages) {
           $this->passes();
       }//if do not has messages get passes

       return array_intersect_key($this->data, $this->messages()->toArray());// return array_intersect_key
   }// a invalid method

   /**
    * Get the value of a given attribute.
    *
    * @param  string  $attribute
    * @return mixed
    */
   protected function getValue($attribute)
   {
       if (! is_null($value = Arr::get($this->data, $attribute))) {// type1
           return $value;// return value
       } elseif (! is_null($value = Arr::get($this->files, $attribute))) {//type2
           return $value;// return value
       }
   }//Get the value of a given attribute

   /**
    * Determine if the attribute is validatable.
    *
    * @param  string  $rule
    * @param  string  $attribute
    * @param  mixed   $value
    * @return bool
    */
   protected function isValidatable($rule, $attribute, $value)
   {
       return $this->presentOrRuleIsImplicit($rule, $attribute, $value) &&
              $this->passesOptionalCheck($attribute) &&
              $this->hasNotFailedPreviousRuleIfPresenceRule($rule, $attribute);
    //three type determine this value.
   }//determine if the attribute is validatable.

   /**
    * Determine if the field is present, or the rule implies required.
    *
    * @param  string  $rule
    * @param  string  $attribute
    * @param  mixed   $value
    * @return bool
    */
   protected function presentOrRuleIsImplicit($rule, $attribute, $value)
   {
       return $this->validateRequired($attribute, $value) || $this->isImplicit($rule);
    // this validateRequired
   }//Determine if the field is present, or the rule implies required.

   /**
    * Determine if the attribute passes any optional check.
    *
    * @param  string  $attribute
    * @return bool
    */
   protected function passesOptionalCheck($attribute)
   {
       if ($this->hasRule($attribute, [‘Sometimes‘])) {
           return array_key_exists($attribute, Arr::dot($this->data))
               || in_array($attribute, array_keys($this->data))
               || array_key_exists($attribute, $this->files);
       }// this->hasRule($attribute)

       return true;
   }// passes Optional Check

   /**
    * Determine if a given rule implies the attribute is required.
    *
    * @param  string  $rule
    * @return bool
    */
   protected function isImplicit($rule)
   {
       return in_array($rule, $this->implicitRules);
   }// check it is a implicit
// in_array
// sorry today,we need to make a very important PPT, so done.
时间: 2024-08-26 07:51:09

[李景山php]每天laravel-20161003|Validator.php-3的相关文章

[李景山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 

[李景山php]每天laravel-20161014|Validator.php-14

    //2016-08-16     /**      * Parse a parameter list.      *      * @param  string  $rule      * @param  string  $parameter      * @return array      */     protected function parseParameters($rule, $parameter)     {//Parse a parameter list        

[李景山php]每天laravel-20161009|Validator.php-9

    /**      * Get the excluded ID column and value for the unique rule.      *      * @param  array  $parameters      * @return array      */     protected function getUniqueIds($parameters)     {         $idColumn = isset($parameters[3]) ? $paramet

[李景山php]每天laravel-20161010|Validator.php-10

   /**     * Validate the guessed extension of a file upload is in a set of file extensions.     *     * @param  string  $attribute     * @param  mixed  $value     * @param  array   $parameters     * @return bool     */    protected function validate

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

/**  * 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) {     $befor

[李景山php]每天laravel-20161005|Validator.php-5

    /**      * Validate that an attribute exists when any other attribute exists.      *      * @param  string  $attribute      * @param  mixed   $value      * @param  mixed   $parameters      * @return bool      */     protected function validateReq

[李景山php]每天laravel-20161012|Validator.php-12

/**  * Get the inline message for a rule if it exists.  *  * @param  string  $attribute  * @param  string  $lowerRule  * @param  array   $source  * @return string|null  */ protected function getInlineMessage($attribute, $lowerRule, $source = null) {/

[李景山php]每天laravel-20161006|Validator.php-6

   /**     * Validate that an attribute is different from another attribute.     *     * @param  string  $attribute     * @param  mixed   $value     * @param  array   $parameters     * @return bool     */    protected function validateDifferent($attr

[李景山php]每天laravel-20160920|Writer-2

    //2016-07-20     /**      * Register a file log handler.      *      * @param  string  $path      * @param  string  $level      * @return void      */     public function useFiles($path, $level = 'debug')     {         $this->monolog->pushHandle