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
bd3d8f63
Commit
bd3d8f63
authored
Jun 26, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added error type to validation rule.
parent
2289570c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
7 deletions
+26
-7
rule.php
system/validation/rule.php
+8
-0
size_of.php
system/validation/rules/size_of.php
+6
-0
upload_of.php
system/validation/rules/upload_of.php
+12
-7
No files found.
system/validation/rule.php
View file @
bd3d8f63
...
...
@@ -18,6 +18,14 @@ abstract class Rule {
*/
public
$message
;
/**
* The error type. This is used for rules that have more than
* one type of error such as Size_Of and Upload_Of.
*
* @var string
*/
protected
$error
;
/**
* Create a new validation Rule instance.
*
...
...
system/validation/rules/size_of.php
View file @
bd3d8f63
...
...
@@ -61,16 +61,19 @@ class Size_Of extends Rule {
{
if
(
!
is_null
(
$this
->
length
)
and
$attributes
[
$attribute
]
!==
$this
->
length
)
{
$this
->
error
=
'number_wrong_size'
;
return
false
;
}
if
(
!
is_null
(
$this
->
maximum
)
and
$attributes
[
$attribute
]
>
$this
->
maximum
)
{
$this
->
error
=
'number_too_big'
;
return
false
;
}
if
(
!
is_null
(
$this
->
minimum
and
$attributes
[
$attribute
]
<
$this
->
minimum
))
{
$this
->
error
=
'number_too_small'
;
return
false
;
}
...
...
@@ -90,16 +93,19 @@ class Size_Of extends Rule {
if
(
!
is_null
(
$this
->
length
)
and
Str
::
length
(
$value
)
!==
$this
->
length
)
{
$this
->
error
=
'string_wrong_size'
;
return
false
;
}
if
(
!
is_null
(
$this
->
maximum
)
and
Str
::
length
(
$value
)
>
$this
->
maximum
)
{
$this
->
error
=
'string_too_big'
;
return
false
;
}
if
(
!
is_null
(
$this
->
minimum
)
and
Str
::
length
(
$value
)
<
$this
->
minimum
)
{
$this
->
error
=
'string_too_small'
;
return
false
;
}
...
...
system/validation/rules/upload_of.php
View file @
bd3d8f63
...
...
@@ -7,11 +7,11 @@ use System\Validation\Rule;
class
Upload_Of
extends
Rule
{
/**
* The acceptable file
extension
s.
* The acceptable file
type
s.
*
* @var array
*/
public
$
extensions
;
public
$
types
=
array
()
;
/**
* The maximum file size in bytes.
...
...
@@ -38,25 +38,30 @@ class Upload_Of extends Rule {
if
(
!
is_null
(
$this
->
maximum
)
and
$file
[
'size'
]
>
$this
->
maximum
)
{
$this
->
error
=
'file_too_big'
;
return
false
;
}
if
(
!
is_null
(
$this
->
extensions
)
and
!
in_array
(
File
::
extension
(
$file
[
'name'
]),
$this
->
extensions
)
)
foreach
(
$this
->
types
as
$type
)
{
if
(
!
File
::
is
(
$type
,
$file
[
'tmp_name'
]))
{
$this
->
error
=
'file_wrong_type'
;
return
false
;
}
}
return
true
;
}
/**
* Set the acceptable file
extension
s.
* Set the acceptable file
type
s.
*
* @return Upload_Of
*/
public
function
has_extension
()
public
function
is
()
{
$this
->
extension
s
=
func_get_args
();
$this
->
type
s
=
func_get_args
();
return
$this
;
}
...
...
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