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
ad24b08b
Commit
ad24b08b
authored
Feb 03, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor the validation replacement code.
parent
554d390f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
17 deletions
+113
-17
validator.php
laravel/validator.php
+113
-17
No files found.
laravel/validator.php
View file @
ad24b08b
...
...
@@ -714,28 +714,124 @@ class Validator {
{
$message
=
str_replace
(
':attribute'
,
$this
->
attribute
(
$attribute
),
$message
);
if
(
in_array
(
$rule
,
$this
->
size_rules
))
if
(
method_exists
(
$this
,
$replacer
=
'replace_'
.
$rule
))
{
// 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 in the array.
$max
=
(
$rule
==
'between'
)
?
$parameters
[
1
]
:
$parameters
[
0
];
$message
=
$this
->
$replacer
(
$message
,
$attribute
,
$rule
,
$parameters
);
}
$replace
=
array
(
$parameters
[
0
],
$parameters
[
0
],
$max
);
return
$message
;
}
$message
=
str_replace
(
array
(
':size'
,
':min'
,
':max'
),
$replace
,
$message
);
}
/**
* Replace all place-holders for the between rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected
function
replace_between
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
return
str_replace
(
array
(
':min'
,
':max'
),
$parameters
,
$message
);
}
// The :values place-holder is used for rules that accept a list of
// values, such as "in" and "not_in". The place-holder value will
// be replaced with a comma delimited list of the values.
elseif
(
in_array
(
$rule
,
$this
->
inclusion_rules
))
{
$message
=
str_replace
(
':values'
,
implode
(
', '
,
$parameters
),
$message
);
}
/**
* Replace all place-holders for the size rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected
function
replace_size
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
return
str_replace
(
':size'
,
$parameters
[
0
],
$message
);
}
return
$message
;
/**
* Replace all place-holders for the min rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected
function
replace_min
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
return
str_replace
(
':min'
,
$parameters
[
0
],
$message
);
}
/**
* Replace all place-holders for the max rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected
function
replace_max
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
return
str_replace
(
':max'
,
$parameters
[
0
],
$message
);
}
/**
* Replace all place-holders for the in rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected
function
replace_in
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
return
str_replace
(
':values'
,
implode
(
', '
,
$parameters
),
$message
);
}
/**
* Replace all place-holders for the not_in rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected
function
replace_not_in
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
return
str_replace
(
':values'
,
implode
(
', '
,
$parameters
),
$message
);
}
/**
* Replace all place-holders for the same rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected
function
replace_same
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
return
str_replace
(
':other'
,
$parameters
[
0
],
$message
);
}
/**
* Replace all place-holders for the different rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected
function
replace_different
(
$message
,
$attribute
,
$rule
,
$parameters
)
{
return
str_replace
(
':other'
,
$parameters
[
0
],
$message
);
}
/**
...
...
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