Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
95af0204
Commit
95af0204
authored
Oct 17, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
continued validation refactoring.
parent
d849cda3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
13 deletions
+33
-13
validator.php
laravel/validation/validator.php
+33
-13
No files found.
laravel/validation/validator.php
View file @
95af0204
...
...
@@ -59,6 +59,13 @@ class Validator {
*/
protected
$size_rules
=
array
(
'size'
,
'between'
,
'min'
,
'max'
);
/**
* The inclusion related validation rules.
*
* @var array
*/
protected
$inclusion_rules
=
array
(
'in'
,
'not_in'
,
'mimes'
);
/**
* The numeric related validation rules.
*
...
...
@@ -195,7 +202,7 @@ class Validator {
*/
protected
function
error
(
$attribute
,
$rule
,
$parameters
)
{
$message
=
$this
->
format
(
$this
->
message
(
$attribute
,
$rule
),
$attribute
,
$rule
,
$parameters
);
$message
=
$this
->
replace
(
$this
->
message
(
$attribute
,
$rule
),
$attribute
,
$rule
,
$parameters
);
$this
->
errors
->
add
(
$attribute
,
$message
);
}
...
...
@@ -545,26 +552,20 @@ class Validator {
* @param array $parameters
* @return string
*/
protected
function
format
(
$message
,
$attribute
,
$rule
,
$parameters
)
protected
function
replace
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
// First we will get the language line for the attribute being validated.
// Storing attribute names in a validation file allows the easily replacement
// of attribute names (email) with more reader friendly versions (E-Mail).
$display
=
Lang
::
line
(
'validation.attributes.'
.
$attribute
)
->
get
(
$this
->
language
,
str_replace
(
'_'
,
' '
,
$attribute
));
$message
=
str_replace
(
':attribute'
,
$this
->
attribute
(
$attribute
),
$message
);
$message
=
str_replace
(
':attribute'
,
$display
,
$message
);
// The "size" family of rules all have place-holders for the values applicable
// to their function. For example, the "max" rule has a ":max" place-holder.
if
(
in_array
(
$rule
,
$this
->
size_rules
))
{
// Even though every size rule will not have a place-holder for min, max, and size,
// we will go ahead and make replacements for all of them just for convenience.
// Except for "between" every replacement should be the first parameter.
$max
=
(
$rule
==
'between'
)
?
$parameters
[
1
]
:
$parameters
[
0
];
$message
=
str_replace
(
array
(
':size'
,
':min'
,
':max'
),
array
(
$parameters
[
0
],
$parameters
[
0
],
$max
),
$message
);
}
// The "inclusion" rules, which are rules that check if a value is within
// a list of values, all have a place-holder to display the allowed values.
elseif
(
in_array
(
$rule
,
array
(
'in'
,
'not_in'
,
'mimes'
)))
elseif
(
in_array
(
$rule
,
$this
->
inclusion_rules
))
{
$message
=
str_replace
(
':values'
,
implode
(
', '
,
$parameters
),
$message
);
}
...
...
@@ -572,6 +573,25 @@ class Validator {
return
$message
;
}
/**
* Get the displayable name for a given attribute.
*
* Storing attribute names in the language file allows a more reader friendly
* version of the attribute name to be place in the :attribute place-holder.
*
* If no language line is specified for the attribute, a default formatting
* will be used for the attribute.
*
* @param string $attribute
* @return string
*/
protected
function
attribute
(
$attribute
)
{
$display
=
Lang
::
line
(
'validation.attributes.'
.
$attribute
)
->
get
(
$this
->
language
);
return
(
is_null
(
$display
))
?
str_replace
(
'_'
,
' '
,
$attribute
)
:
$display
;
}
/**
* Determine if an attribute has a rule assigned to it.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment