[李景山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 ?
时间: 2024-07-29 04:37:35

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

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

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