[李景山php]每天laravel-20161008|Validator.php-8
2016-08-09 09:14
585 查看
/** * Validate an attribute is contained within a list of values. * * @param string $attribute * @param mixed $value * @param array $parameters * @return bool */ protected function validateIn($attribute, $value, $parameters) { if (is_array($value) && $this->hasRule($attribute, 'Array')) { return count(array_diff($value, $parameters)) == 0; }// if it is value and this get the count return ! is_array($value) && in_array((string) $value, $parameters); }//validate an attribute is contained within a list of values // i like this two way , just return this result /** * Validate an attribute is not contained within a list of values. * * @param string $attribute * @param mixed $value * @param array $parameters * @return bool */ protected function validateNotIn($attribute, $value, $parameters) { return ! $this->validateIn($attribute, $value, $parameters);// return a wrap function }//validate an attribute is not contained within a list of values /** * Validate the uniqueness of an attribute value on a given database table. * * If a database column is not specified, the attribute will be used. * * @param string $attribute * @param mixed $value * @param array $parameters * @return bool */ // validate the uniqueness of an attribute value on a given database table. // if a database column is not specified, the attribute will be used. protected function validateUnique($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'unique');//get this function list($connection, $table) = $this->parseTable($parameters[0]);// list some method // The second parameter position holds the name of the column that needs to // be verified as unique. If this parameter isn't specified we will just // assume that this column to be verified shares the attribute's name. $column = isset($parameters[1]) ? $parameters[1] : $attribute; // The second parameter position holds the name of the column that needs to // be verified as unique. If this parameter isn't specified we will just // assume that this column to be verified shares the attribute's name. list($idColumn, $id) = [null, null];// init this parameter if (isset($parameters[2])) { list($idColumn, $id) = $this->getUniqueIds($parameters);//a good method if (strtolower($id) == 'null') { $id = null; }// set the number } // The presence verifier is responsible for counting rows within this store // mechanism which might be a relational database or any other permanent // data store like Redis, etc. We will use it to determine uniqueness. $verifier = $this->getPresenceVerifier();//get Presence Verifier $verifier->setConnection($connection);// set Connection $extra = $this->getUniqueExtra($parameters);//get Unique Extra return $verifier->getCount( $table, $column, $value, $id, $idColumn, $extra ) == 0;// get Count }// so powerfull /** * Parse the connection / table for the unique / exists rules. * * @param string $table * @return array */ protected function parseTable($table) { return Str::contains($table, '.') ? explode('.', $table, 2) : [null, $table]; }//Parse the connection table for the unique and exists rules.
相关文章推荐
- [李景山php]每天laravel-20161002|Validator.php-2
- [李景山php]每天laravel-20161005|Validator.php-5
- [李景山php]每天laravel-20161012|Validator.php-12
- [李景山php]每天laravel-20161014|Validator.php-14
- [李景山php]每天laravel-20161003|Validator.php-3
- [李景山php]每天laravel-20161010|Validator.php-10
- [李景山php]每天laravel-20161013|Validator.php-13
- [李景山php]每天laravel-20161011|Validator.php-11
- [李景山php]每天laravel-20161004|Validator.php-4
- [李景山php]每天laravel-20161009|Validator.php-9
- [李景山php]每天laravel-20161006|Validator.php-6
- [李景山php]每天laravel-20161013|Validator.php-13
- [李景山php]每天laravel-20161001|Validator.php-1
- [李景山php]每天laravel-20161004|Validator.php-4
- [李景山php]每天laravel-20161007|Validator.php-7
- [李景山php]每天laravel-20161007|Validator.php-7
- [李景山php]每天laravel-20161014|Validator.php-14
- [李景山php]每天laravel-20161012|Validator.php-12
- [李景山php]每天laravel-20161010|Validator.php-10
- [李景山php]每天laravel-20161006|Validator.php-6