[李景山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]) ? $parameters[3] : ‘id‘;//default is id

        return [$idColumn, $parameters[2]];// return this id and other parameters
    }// this is a protected function to  get the excluded ID column
   // means these column not has ID
   // get column and value for the unique rule.

    /**
     * Get the extra conditions for a unique rule.
     *
     * @param  array  $parameters
     * @return array
     */
    protected function getUniqueExtra($parameters)
    {// get more conditions, like extra exists.
        if (isset($parameters[4])) {// if has return this value
            return $this->getExtraConditions(array_slice($parameters, 4));
        }
//else return null
        return [];
    }//Get the extra conditions for a unique rule.

    /**
     * Validate the existence of an attribute value in a database table.
     *
     * @param  string  $attribute
     * @param  mixed   $value
     * @param  array   $parameters
     * @return bool
     */
    protected function validateExists($attribute, $value, $parameters)
    {//Validate the existence of an attribute value in a database table
        $this->requireParameterCount(1, $parameters, ‘exists‘);// require Parameter Count

        list($connection, $table) = $this->parseTable($parameters[0]);//list get this value

        // The second parameter position holds the name of the column that should be
        // verified as existing. If this parameter is not specified we will guess
        // that the columns being "verified" shares the given attribute‘s name.
        $column = isset($parameters[1]) ? $parameters[1] : $attribute;
       // The second parameter position holds the name of the column that should be verified as existing.
       // means this second parameter must be existing.
       // if this parameter not exists, we will default think this column being "verified".
       // and will shares the given attribute name

       // get this column

        $expected = (is_array($value)) ? count($value) : 1;// get the number

        return $this->getExistCount($connection, $table, $column, $value, $parameters) >= $expected;
    }// too simple and this type.

    /**
     * Get the number of records that exist in storage.
     *
     * @param  mixed   $connection
     * @param  string  $table
     * @param  string  $column
     * @param  mixed   $value
     * @param  array   $parameters
     * @return int
     */
    protected function getExistCount($connection, $table, $column, $value, $parameters)
    {// Get the number of records that exist in storage.
       //this storage maybe is mysql or redis.
        $verifier = $this->getPresenceVerifier();//first get the verifier

        $verifier->setConnection($connection);// set connection

        $extra = $this->getExtraExistConditions($parameters);// get the extra condtion

        if (is_array($value)) {// if has value
           // return this value
            return $verifier->getMultiCount($table, $column, $value, $extra);
        }
// get Count
        return $verifier->getCount($table, $column, $value, null, null, $extra);
    }

    /**
     * Get the extra exist conditions.
     *
     * @param  array  $parameters
     * @return array
     */
    protected function getExtraExistConditions(array $parameters)
    {// get Extra Conditions
        return $this->getExtraConditions(array_values(array_slice($parameters, 2)));
    }// Get the extra exist conditons.

    /**
     * Get the extra conditions for a unique / exists rule.
     *
     * @param  array  $segments
     * @return array
     */
    protected function getExtraConditions(array $segments)
    {
        $extra = [];// extra this storage

        $count = count($segments);// get count number and segments

        for ($i = 0; $i < $count; $i = $i + 2) {// loop this segments
            $extra[$segments[$i]] = $segments[$i + 1];
        }

        return $extra;//return this result
    }//Get the extra conditions for a unique /exists rule.

    /**
     * Validate that an attribute is a valid IP.
     *
     * @param  string  $attribute
     * @param  mixed   $value
     * @return bool
     */
    protected function validateIp($attribute, $value)
    {
        return filter_var($value, FILTER_VALIDATE_IP) !== false;
    }//validate that an attribute is a valid IP.

    /**
     * Validate that an attribute is a valid e-mail address.
     *
     * @param  string  $attribute
     * @param  mixed   $value
     * @return bool
     */
    protected function validateEmail($attribute, $value)
    {
        return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
    }//validate that an attribute is a valid e-mail address

    /**
     * Validate that an attribute is a valid URL.
     *
     * @param  string  $attribute
     * @param  mixed   $value
     * @return bool
     */
    protected function validateUrl($attribute, $value)
    {// validate that an attribute is a valid URL
        /*
         * This pattern is derived from Symfony\Component\Validator\Constraints\UrlValidator (2.7.4)
         * (c) Fabien Potencier <[email protected]> http://symfony.com
         */
        $pattern = ‘~^
            ((aaa|aaas|about|acap|acct|acr|adiumxtra|afp|afs|aim|apt|attachment|aw|barion|beshare|bitcoin|blob|bolo|callto|cap|chrome|chrome-extension|cid|coap|coaps|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-playcontainer|dlna-playsingle|dns|dntp|dtn|dvb|ed2k|example|facetime|fax|feed|feedready|file|filesystem|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|ham|hcp|http|https|iax|icap|icon|im|imap|info|iotdisco|ipn|ipp|ipps|irc|irc6|ircs|iris|iris.beep|iris.lwz|iris.xpc|iris.xpcs|itms|jabber|jar|jms|keyparc|lastfm|ldap|ldaps|magnet|mailserver|mailto|maps|market|message|mid|mms|modem|ms-help|ms-settings|ms-settings-airplanemode|ms-settings-bluetooth|ms-settings-camera|ms-settings-cellular|ms-settings-cloudstorage|ms-settings-emailandaccounts|ms-settings-language|ms-settings-location|ms-settings-lock|ms-settings-nfctransactions|ms-settings-notifications|ms-settings-power|ms-settings-privacy|ms-settings-proximity|ms-settings-screenrotation|ms-settings-wifi|ms-settings-workplace|msnim|msrp|msrps|mtqp|mumble|mupdate|mvn|news|nfs|ni|nih|nntp|notes|oid|opaquelocktoken|pack|palm|paparazzi|pkcs11|platform|pop|pres|prospero|proxy|psyc|query|redis|rediss|reload|res|resource|rmi|rsync|rtmfp|rtmp|rtsp|rtsps|rtspu|secondlife|service|session|sftp|sgn|shttp|sieve|sip|sips|skype|smb|sms|smtp|snews|snmp|soap.beep|soap.beeps|soldat|spotify|ssh|steam|stun|stuns|submit|svn|tag|teamspeak|tel|teliaeid|telnet|tftp|things|thismessage|tip|tn3270|turn|turns|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|videotex|view-source|wais|webcal|ws|wss|wtai|wyciwyg|xcon|xcon-userid|xfire|xmlrpc\.beep|xmlrpc.beeps|xmpp|xri|ymsgr|z39\.50|z39\.50r|z39\.50s))://                                 # protocol
            (([\pL\pN-]+:)?([\pL\pN-]+)@)?          # basic auth
            (
                ([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
                    |                                              # or
                \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}                 # a IP address
                    |                                              # or
                \[
                    (?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(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a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
                \]  # a IPv6 address
            )
            (:[0-9]+)?                              # a port (optional)
            (/?|/\S+)                               # a /, nothing or a / with something
        $~ixu‘;

        return preg_match($pattern, $value) === 1;
    }// a big power full rules.

    /**
     * Validate that an attribute is an active URL.
     *
     * @param  string  $attribute
     * @param  mixed   $value
     * @return bool
     */
    protected function validateActiveUrl($attribute, $value)
    {
        if ($url = parse_url($value, PHP_URL_HOST)) {
            return count(dns_get_record($url, DNS_A | DNS_AAAA)) > 0;
        }// a super parse_url

        return false;
    }// validate that an attribute is an active URL

    /**
     * Validate the MIME type of a file is an image MIME type.
     *
     * @param  string  $attribute
     * @param  mixed   $value
     * @return bool
     */
    protected function validateImage($attribute, $value)
    {
        return $this->validateMimes($attribute, $value, [‘jpeg‘, ‘png‘, ‘gif‘, ‘bmp‘, ‘svg‘]);
    }// validate the MIME type of a file is an images MIME type.
时间: 2024-07-31 05:34:25

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

[李景山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-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]每天TP5-20161212|App.php-2

public static function run(Request $request = null) {// thinkphp经过了 自动加载.错误接管.配置文件预设,终于开始执行了.     // 第一步:获取请求参数     is_null($request) && $request = Request::instance();     // self::$instance = new static($options); 执行了 这个 instance     // 默认 没有传入任