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
b7b258a1
Commit
b7b258a1
authored
Jun 26, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed error collector bloat, switched to plain array. thanks mikelbring.
parent
4a5190df
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
10 additions
and
103 deletions
+10
-103
html.php
system/html.php
+2
-2
error_collector.php
system/validation/error_collector.php
+0
-81
rule.php
system/validation/rule.php
+4
-4
validator.php
system/validator.php
+4
-6
view.php
system/view.php
+0
-10
No files found.
system/html.php
View file @
b7b258a1
...
...
@@ -21,7 +21,7 @@ class HTML {
*/
public
static
function
script
(
$url
)
{
return
'<script type="text/javascript" src="'
.
trim
(
static
::
entities
(
URL
::
to_asset
(
$url
)),
'.js'
)
.
'.js
"></script>'
.
PHP_EOL
;
return
'<script type="text/javascript" src="'
.
static
::
entities
(
URL
::
to_asset
(
$url
))
.
'
"></script>'
.
PHP_EOL
;
}
/**
...
...
@@ -32,7 +32,7 @@ class HTML {
*/
public
static
function
style
(
$url
,
$media
=
'all'
)
{
return
'<link href="'
.
trim
(
static
::
entities
(
URL
::
to_asset
(
$url
)),
'.css'
)
.
'.css
" rel="stylesheet" type="text/css" media="'
.
$media
.
'" />'
.
PHP_EOL
;
return
'<link href="'
.
static
::
entities
(
URL
::
to_asset
(
$url
))
.
'
" rel="stylesheet" type="text/css" media="'
.
$media
.
'" />'
.
PHP_EOL
;
}
/**
...
...
system/validation/error_collector.php
deleted
100644 → 0
View file @
4a5190df
<?php
namespace
System\Validation
;
class
Error_Collector
{
/**
* All of the error messages.
*
* @var array
*/
public
$messages
;
/**
* Create a new Error Collector instance.
*
* @return void
*/
public
function
__construct
(
$messages
=
array
())
{
$this
->
messages
=
$messages
;
}
/**
* Add an error message to the collector.
*
* @param string $attribute
* @param string $message
* @return void
*/
public
function
add
(
$attribute
,
$message
)
{
$this
->
messages
[
$attribute
][]
=
$message
;
}
/**
* Determine if errors exist for an attribute.
*
* @param string $attribute
* @return bool
*/
public
function
has
(
$attribute
)
{
return
$this
->
first
(
$attribute
)
!==
''
;
}
/**
* Get the first error message for an attribute.
*
* @param string $attribute
* @return string
*/
public
function
first
(
$attribute
)
{
return
(
count
(
$messages
=
$this
->
get
(
$attribute
))
>
0
)
?
$messages
[
0
]
:
''
;
}
/**
* Get all of the error messages for an attribute.
*
* If no attribute is specified, all of the error messages will be returned.
*
* @param string $attribute
* @return array
*/
public
function
get
(
$attribute
=
null
)
{
if
(
is_null
(
$attribute
))
{
$all
=
array
();
foreach
(
$this
->
messages
as
$messages
)
{
$all
=
array_merge
(
$all
,
$messages
);
}
return
$all
;
}
return
(
array_key_exists
(
$attribute
,
$this
->
messages
))
?
$this
->
messages
[
$attribute
]
:
array
();
}
}
\ No newline at end of file
system/validation/rule.php
View file @
b7b258a1
...
...
@@ -32,17 +32,17 @@ abstract class Rule {
/**
* Run the validation rule.
*
* @param array
$attributes
* @param
Error_Collector
$errors
* @param array $attributes
* @param
array
$errors
* @return void
*/
public
function
validate
(
$attributes
,
$errors
)
public
function
validate
(
$attributes
,
&
$errors
)
{
foreach
(
$this
->
attributes
as
$attribute
)
{
if
(
!
$this
->
check
(
$attribute
,
$attributes
))
{
$errors
->
add
(
$attribute
,
$this
->
prepare_message
(
$attribute
)
);
$errors
[
$attribute
][]
=
$this
->
prepare_message
(
$attribute
);
}
}
}
...
...
system/validator.php
View file @
b7b258a1
...
...
@@ -10,9 +10,9 @@ class Validator {
public
$attributes
;
/**
* The validation error
collector.
* The validation error
s
*
* @var
Error_Collector
* @var
array
*/
public
$errors
;
...
...
@@ -36,8 +36,6 @@ class Validator {
// attributes as the validation attributes.
// ---------------------------------------------------------
$this
->
attributes
=
(
$target
instanceof
DB\Eloquent
)
?
$target
->
attributes
:
(
array
)
$target
;
$this
->
errors
=
new
Validation\Error_Collector
;
}
/**
...
...
@@ -58,7 +56,7 @@ class Validator {
*/
public
function
is_valid
()
{
$this
->
errors
->
messages
=
array
();
$this
->
errors
=
array
();
foreach
(
$this
->
rules
as
$rule
)
{
...
...
@@ -69,7 +67,7 @@ class Validator {
$rule
->
validate
(
$this
->
attributes
,
$this
->
errors
);
}
return
count
(
$this
->
errors
->
messages
)
==
0
;
return
count
(
$this
->
errors
)
==
0
;
}
/**
...
...
system/view.php
View file @
b7b258a1
...
...
@@ -34,16 +34,6 @@ class View {
{
$this
->
view
=
$view
;
$this
->
data
=
$data
;
// -----------------------------------------------------
// Every view has an error collector. This makes it
// convenient to check for any validation errors without
// worrying if the error collector is instantiated.
//
// If an error collector is in the session, it will
// be used as the error collector for the view.
// -----------------------------------------------------
$this
->
data
[
'errors'
]
=
(
Config
::
get
(
'session.driver'
)
!=
''
and
Session
::
has
(
'errors'
))
?
Session
::
get
(
'errors'
)
:
new
Validation\Error_Collector
;
}
/**
...
...
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