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
56e50041
Commit
56e50041
authored
Jun 22, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improving validation code and comments.
parent
a536ceae
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
10 deletions
+14
-10
rule.php
system/validation/rule.php
+14
-10
No files found.
system/validation/rule.php
View file @
56e50041
...
@@ -5,7 +5,7 @@ use System\Lang;
...
@@ -5,7 +5,7 @@ use System\Lang;
abstract
class
Rule
{
abstract
class
Rule
{
/**
/**
* The attributes being validated.
* The attributes being validated
by the rule
.
*
*
* @var array
* @var array
*/
*/
...
@@ -22,7 +22,6 @@ abstract class Rule {
...
@@ -22,7 +22,6 @@ abstract class Rule {
* Create a new validation Rule instance.
* Create a new validation Rule instance.
*
*
* @param array $attributes
* @param array $attributes
* @param Validator $class
* @return void
* @return void
*/
*/
public
function
__construct
(
$attributes
)
public
function
__construct
(
$attributes
)
...
@@ -39,11 +38,6 @@ abstract class Rule {
...
@@ -39,11 +38,6 @@ abstract class Rule {
*/
*/
public
function
validate
(
$attributes
,
$errors
)
public
function
validate
(
$attributes
,
$errors
)
{
{
if
(
is_null
(
$this
->
message
))
{
throw
new
\Exception
(
"An error message must be specified for every Eloquent validation rule."
);
}
foreach
(
$this
->
attributes
as
$attribute
)
foreach
(
$this
->
attributes
as
$attribute
)
{
{
if
(
!
$this
->
check
(
$attribute
,
$attributes
))
if
(
!
$this
->
check
(
$attribute
,
$attributes
))
...
@@ -56,18 +50,28 @@ abstract class Rule {
...
@@ -56,18 +50,28 @@ abstract class Rule {
/**
/**
* Prepare the message to be added to the error collector.
* Prepare the message to be added to the error collector.
*
*
* Attribute and size place-holders will replace with their actual values.
*
* @param string $attribute
* @param string $attribute
* @return string
* @return string
*/
*/
private
function
prepare_message
(
$attribute
)
private
function
prepare_message
(
$attribute
)
{
{
if
(
is_null
(
$this
->
message
))
{
throw
new
\Exception
(
"An error message must be specified for every Eloquent validation rule."
);
}
$message
=
$this
->
message
;
$message
=
$this
->
message
;
// ---------------------------------------------------------
// Replace any place-holders with their actual values.
//
// Attribute place-holders are loaded from the language
// directory. If the line doesn't exist, the attribute
// name will be used instead.
// ---------------------------------------------------------
if
(
strpos
(
$message
,
':attribute'
))
if
(
strpos
(
$message
,
':attribute'
))
{
{
$message
=
str_replace
(
':attribute'
,
Lang
::
line
(
'attributes.'
.
$attribute
)
->
get
(),
$message
);
$message
=
str_replace
(
':attribute'
,
Lang
::
line
(
'attributes.'
.
$attribute
)
->
get
(
$attribute
),
$message
);
}
}
if
(
$this
instanceof
Rules\Size_Of
)
if
(
$this
instanceof
Rules\Size_Of
)
...
...
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