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
86075c27
Commit
86075c27
authored
Jul 30, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved validation/errors into system/messages... not just useful for error messages.
parent
f3ddadce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
1 deletion
+115
-1
messages.php
system/messages.php
+114
-0
validator.php
system/validator.php
+1
-1
No files found.
system/
validation/error
s.php
→
system/
message
s.php
View file @
86075c27
<?php
namespace
System
\Validation
;
<?php
namespace
System
;
class
Error
s
{
class
Message
s
{
/**
/**
* All of the
error
messages.
* All of the messages.
*
*
* @var array
* @var array
*/
*/
public
$messages
;
public
$messages
;
/**
/**
* Create a new
Error
s instance.
* Create a new
Message
s instance.
*
*
* @return void
* @return void
*/
*/
...
@@ -20,67 +20,67 @@ class Errors {
...
@@ -20,67 +20,67 @@ class Errors {
}
}
/**
/**
* Add a
n error
message to the collector.
* Add a message to the collector.
*
*
* Duplicate messages will not be added.
* Duplicate messages will not be added.
*
*
* @param string $
attribute
* @param string $
key
* @param string $message
* @param string $message
* @return void
* @return void
*/
*/
public
function
add
(
$
attribute
,
$message
)
public
function
add
(
$
key
,
$message
)
{
{
// Make sure the
error
message is not duplicated.
// Make sure the message is not duplicated.
if
(
!
array_key_exists
(
$
attribute
,
$this
->
messages
)
or
!
is_array
(
$this
->
messages
[
$attribute
])
or
!
in_array
(
$message
,
$this
->
messages
[
$attribute
]))
if
(
!
array_key_exists
(
$
key
,
$this
->
messages
)
or
!
is_array
(
$this
->
messages
[
$key
])
or
!
in_array
(
$message
,
$this
->
messages
[
$key
]))
{
{
$this
->
messages
[
$
attribute
][]
=
$message
;
$this
->
messages
[
$
key
][]
=
$message
;
}
}
}
}
/**
/**
* Determine if
errors exist for an attribute
.
* Determine if
messages exist for a given key
.
*
*
* @param string $
attribute
* @param string $
key
* @return bool
* @return bool
*/
*/
public
function
has
(
$
attribute
)
public
function
has
(
$
key
)
{
{
return
$this
->
first
(
$
attribute
)
!==
''
;
return
$this
->
first
(
$
key
)
!==
''
;
}
}
/**
/**
* Get the first
error message for an attribute
.
* Get the first
message for a given key
.
*
*
* @param string $
attribute
* @param string $
key
* @param string $format
* @param string $format
* @return string
* @return string
*/
*/
public
function
first
(
$
attribute
,
$format
=
':message'
)
public
function
first
(
$
key
,
$format
=
':message'
)
{
{
return
(
count
(
$messages
=
$this
->
get
(
$
attribute
,
$format
))
>
0
)
?
$messages
[
0
]
:
''
;
return
(
count
(
$messages
=
$this
->
get
(
$
key
,
$format
))
>
0
)
?
$messages
[
0
]
:
''
;
}
}
/**
/**
* Get all of the
error messages for an attribute
.
* Get all of the
messages for a key
.
*
*
* If no
attribute is specified, all of the error
messages will be returned.
* If no
key is specified, all of the
messages will be returned.
*
*
* @param string $
attribute
* @param string $
key
* @param string $format
* @param string $format
* @return array
* @return array
*/
*/
public
function
get
(
$
attribute
=
null
,
$format
=
':message'
)
public
function
get
(
$
key
=
null
,
$format
=
':message'
)
{
{
if
(
is_null
(
$
attribute
))
if
(
is_null
(
$
key
))
{
{
return
$this
->
all
(
$format
);
return
$this
->
all
(
$format
);
}
}
return
(
array_key_exists
(
$
attribute
,
$this
->
messages
))
?
$this
->
format
(
$this
->
messages
[
$attribute
],
$format
)
:
array
();
return
(
array_key_exists
(
$
key
,
$this
->
messages
))
?
$this
->
format
(
$this
->
messages
[
$key
],
$format
)
:
array
();
}
}
/**
/**
* Get all of the
error
messages.
* Get all of the messages.
*
*
* @param string $format
* @param string $format
* @return array
* @return array
...
...
system/validator.php
View file @
86075c27
...
@@ -94,7 +94,7 @@ class Validator {
...
@@ -94,7 +94,7 @@ class Validator {
*/
*/
public
function
valid
()
public
function
valid
()
{
{
$this
->
errors
=
new
Validation\Error
s
;
$this
->
errors
=
new
Message
s
;
foreach
(
$this
->
rules
as
$attribute
=>
$rules
)
foreach
(
$this
->
rules
as
$attribute
=>
$rules
)
{
{
...
...
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