Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Tomáš Trávníček
doctrine-dbal
Commits
276af652
Commit
276af652
authored
Sep 04, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for passing an array as constraint/validator argument
parent
7bb07a5b
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
26 deletions
+53
-26
DataDict.php
Doctrine/DataDict.php
+11
-2
Validator.php
Doctrine/Validator.php
+20
-15
Range.php
Doctrine/Validator/Range.php
+3
-4
Regexp.php
Doctrine/Validator/Regexp.php
+10
-2
ValidatorTestCase.php
tests/ValidatorTestCase.php
+5
-1
classes.php
tests/classes.php
+3
-0
run.php
tests/run.php
+1
-2
No files found.
Doctrine/DataDict.php
View file @
276af652
...
...
@@ -35,7 +35,16 @@ class Doctrine_DataDict {
if
(
!
is_array
(
$args
[
2
]))
$args
[
2
]
=
array
();
$r
[]
=
$name
.
" "
.
$this
->
getADOType
(
$args
[
0
],
$args
[
1
])
.
" "
.
implode
(
' '
,
$args
[
2
]);
$constraints
=
array
();
foreach
(
$args
[
2
]
as
$k
=>
$v
)
{
if
(
is_string
(
$k
))
$constraints
[]
=
$k
;
else
$constraints
[]
=
$v
;
}
$r
[]
=
$name
.
" "
.
$this
->
getADOType
(
$args
[
0
],
$args
[
1
])
.
" "
.
implode
(
' '
,
$constraints
);
}
...
...
Doctrine/Validator.php
View file @
276af652
...
...
@@ -67,7 +67,10 @@ class Doctrine_Validator {
* constant for range validation error
*/
const
ERR_RANGE
=
8
;
/**
* constant for regexp validation error
*/
const
ERR_REGEXP
=
9
;
...
...
@@ -120,7 +123,7 @@ class Doctrine_Validator {
*/
public
function
validateRecord
(
Doctrine_Record
$record
)
{
$columns
=
$record
->
getTable
()
->
getColumns
();
$
name
=
$record
->
getTable
()
->
getComponentName
();
$
component
=
$record
->
getTable
()
->
getComponentName
();
switch
(
$record
->
getState
())
:
case
Doctrine_Record
::
STATE_TDIRTY
:
...
...
@@ -165,21 +168,23 @@ class Doctrine_Validator {
foreach
(
$e
as
$k
=>
$arg
)
{
if
(
empty
(
$arg
)
||
$arg
==
"primary"
||
$arg
==
"protected"
||
$arg
==
"autoincrement"
)
continue
;
if
(
!
is_integer
(
$k
))
{
if
(
is_string
(
$k
))
{
$name
=
$k
;
$args
=
$arg
;
}
else
}
else
{
$args
=
explode
(
":"
,
$arg
);
$name
=
array_shift
(
$args
);
if
(
!
isset
(
$args
[
0
]))
$args
[
0
]
=
''
;
}
if
(
!
isset
(
$args
[
1
]))
$args
[
1
]
=
''
;
if
(
empty
(
$name
)
||
$name
==
"primary"
||
$name
==
"protected"
||
$name
==
"autoincrement"
)
continue
;
$validator
=
self
::
getValidator
(
$
args
[
0
]
);
if
(
!
$validator
->
validate
(
$record
,
$key
,
$value
,
$args
[
1
]
))
{
$validator
=
self
::
getValidator
(
$
name
);
if
(
!
$validator
->
validate
(
$record
,
$key
,
$value
,
$args
))
{
$constant
=
'Doctrine_Validator::ERR_'
.
strtoupper
(
$
args
[
0
]
);
$constant
=
'Doctrine_Validator::ERR_'
.
strtoupper
(
$
name
);
if
(
defined
(
$constant
))
$err
[
$key
]
=
constant
(
$constant
);
...
...
@@ -197,7 +202,7 @@ class Doctrine_Validator {
}
if
(
!
empty
(
$err
))
{
$this
->
stack
[
$
name
][]
=
$err
;
$this
->
stack
[
$
component
][]
=
$err
;
return
false
;
}
...
...
Doctrine/Validator/Range.php
View file @
276af652
...
...
@@ -8,11 +8,10 @@ class Doctrine_Validator_Range {
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
$e
=
explode
(
"-"
,
$args
);
if
(
$value
<
$e
[
0
])
if
(
isset
(
$args
[
0
])
&&
$value
<
$args
[
0
])
return
false
;
if
(
isset
(
$
e
[
1
])
&&
$value
>
$e
[
1
])
if
(
isset
(
$
args
[
1
])
&&
$value
>
$args
[
1
])
return
false
;
return
true
;
...
...
Doctrine/Validator/Regexp.php
View file @
276af652
...
...
@@ -8,8 +8,16 @@ class Doctrine_Validator_Regexp {
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
if
(
is_array
(
$args
))
{
foreach
(
$args
as
$regexp
)
{
if
(
!
preg_match
(
"/
$args
/"
,
$value
))
return
false
;
}
return
true
;
}
else
{
if
(
preg_match
(
"/
$args
/"
,
$value
))
return
true
;
}
return
false
;
}
...
...
tests/ValidatorTestCase.php
View file @
276af652
...
...
@@ -72,6 +72,8 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
public
function
testValidate2
()
{
$test
=
new
ValidatorTest
();
$test
->
mymixed
=
"message"
;
$test
->
myrange
=
1
;
$test
->
myregexp
=
'123a'
;
$validator
=
new
Doctrine_Validator
();
$validator
->
validateRecord
(
$test
);
...
...
@@ -85,6 +87,8 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$stack
[
'mystring'
],
Doctrine_Validator
::
ERR_NOTNULL
);
$this
->
assertEqual
(
$stack
[
'myemail2'
],
Doctrine_Validator
::
ERR_NOTBLANK
);
$this
->
assertEqual
(
$stack
[
'myrange'
],
Doctrine_Validator
::
ERR_RANGE
);
$this
->
assertEqual
(
$stack
[
'myregexp'
],
Doctrine_Validator
::
ERR_REGEXP
);
$test
->
mystring
=
'str'
;
...
...
tests/classes.php
View file @
276af652
...
...
@@ -397,6 +397,9 @@ class ValidatorTest extends Doctrine_Record {
$this
->
hasColumn
(
"myarray"
,
"array"
,
1000
);
$this
->
hasColumn
(
"myobject"
,
"object"
,
1000
);
$this
->
hasColumn
(
"myinteger"
,
"integer"
,
11
);
$this
->
hasColumn
(
"myrange"
,
"integer"
,
11
,
array
(
'range'
=>
array
(
4
,
123
)));
$this
->
hasColumn
(
"myregexp"
,
"string"
,
5
,
array
(
'regexp'
=>
'^[0-9]+$'
));
$this
->
hasColumn
(
"myemail"
,
"string"
,
100
,
"email"
);
$this
->
hasColumn
(
"myemail2"
,
"string"
,
100
,
"email|notblank"
);
}
...
...
tests/run.php
View file @
276af652
...
...
@@ -62,8 +62,6 @@ $test->addTestCase(new Doctrine_Filter_TestCase());
$test
->
addTestCase
(
new
Doctrine_ValueHolder_TestCase
());
$test
->
addTestCase
(
new
Doctrine_ValidatorTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
$test
->
addTestCase
(
new
Doctrine_RawSql_TestCase
());
...
...
@@ -76,6 +74,7 @@ $test->addTestCase(new Doctrine_ImportTestCase());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_ValidatorTestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
...
...
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