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
Hide 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
...
@@ -34,8 +34,17 @@ class Doctrine_DataDict {
...
@@ -34,8 +34,17 @@ class Doctrine_DataDict {
foreach
(
$columns
as
$name
=>
$args
)
{
foreach
(
$columns
as
$name
=>
$args
)
{
if
(
!
is_array
(
$args
[
2
]))
if
(
!
is_array
(
$args
[
2
]))
$args
[
2
]
=
array
();
$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 {
...
@@ -67,7 +67,10 @@ class Doctrine_Validator {
* constant for range validation error
* constant for range validation error
*/
*/
const
ERR_RANGE
=
8
;
const
ERR_RANGE
=
8
;
/**
* constant for regexp validation error
*/
const
ERR_REGEXP
=
9
;
...
@@ -119,8 +122,8 @@ class Doctrine_Validator {
...
@@ -119,8 +122,8 @@ class Doctrine_Validator {
* @return void
* @return void
*/
*/
public
function
validateRecord
(
Doctrine_Record
$record
)
{
public
function
validateRecord
(
Doctrine_Record
$record
)
{
$columns
=
$record
->
getTable
()
->
getColumns
();
$columns
=
$record
->
getTable
()
->
getColumns
();
$
name
=
$record
->
getTable
()
->
getComponentName
();
$
component
=
$record
->
getTable
()
->
getComponentName
();
switch
(
$record
->
getState
())
:
switch
(
$record
->
getState
())
:
case
Doctrine_Record
::
STATE_TDIRTY
:
case
Doctrine_Record
::
STATE_TDIRTY
:
...
@@ -165,21 +168,23 @@ class Doctrine_Validator {
...
@@ -165,21 +168,23 @@ class Doctrine_Validator {
foreach
(
$e
as
$k
=>
$arg
)
{
foreach
(
$e
as
$k
=>
$arg
)
{
if
(
empty
(
$arg
)
||
$arg
==
"primary"
||
$arg
==
"protected"
||
$arg
==
"autoincrement"
)
if
(
is_string
(
$k
))
{
continue
;
$name
=
$k
;
if
(
!
is_integer
(
$k
))
{
$args
=
$arg
;
$args
=
$arg
;
}
else
}
else
{
$args
=
explode
(
":"
,
$arg
);
$args
=
explode
(
":"
,
$arg
);
$name
=
array_shift
(
$args
);
if
(
!
isset
(
$args
[
1
]))
if
(
!
isset
(
$args
[
0
]))
$args
[
1
]
=
''
;
$args
[
0
]
=
''
;
}
if
(
empty
(
$name
)
||
$name
==
"primary"
||
$name
==
"protected"
||
$name
==
"autoincrement"
)
continue
;
$validator
=
self
::
getValidator
(
$
args
[
0
]
);
$validator
=
self
::
getValidator
(
$
name
);
if
(
!
$validator
->
validate
(
$record
,
$key
,
$value
,
$args
[
1
]
))
{
if
(
!
$validator
->
validate
(
$record
,
$key
,
$value
,
$args
))
{
$constant
=
'Doctrine_Validator::ERR_'
.
strtoupper
(
$
args
[
0
]
);
$constant
=
'Doctrine_Validator::ERR_'
.
strtoupper
(
$
name
);
if
(
defined
(
$constant
))
if
(
defined
(
$constant
))
$err
[
$key
]
=
constant
(
$constant
);
$err
[
$key
]
=
constant
(
$constant
);
...
@@ -197,7 +202,7 @@ class Doctrine_Validator {
...
@@ -197,7 +202,7 @@ class Doctrine_Validator {
}
}
if
(
!
empty
(
$err
))
{
if
(
!
empty
(
$err
))
{
$this
->
stack
[
$
name
][]
=
$err
;
$this
->
stack
[
$
component
][]
=
$err
;
return
false
;
return
false
;
}
}
...
...
Doctrine/Validator/Range.php
View file @
276af652
...
@@ -8,11 +8,10 @@ class Doctrine_Validator_Range {
...
@@ -8,11 +8,10 @@ class Doctrine_Validator_Range {
* @return boolean
* @return boolean
*/
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
$e
=
explode
(
"-"
,
$args
);
if
(
isset
(
$args
[
0
])
&&
$value
<
$args
[
0
])
if
(
$value
<
$e
[
0
])
return
false
;
return
false
;
if
(
isset
(
$
e
[
1
])
&&
$value
>
$e
[
1
])
if
(
isset
(
$
args
[
1
])
&&
$value
>
$args
[
1
])
return
false
;
return
false
;
return
true
;
return
true
;
...
...
Doctrine/Validator/Regexp.php
View file @
276af652
...
@@ -8,9 +8,17 @@ class Doctrine_Validator_Regexp {
...
@@ -8,9 +8,17 @@ class Doctrine_Validator_Regexp {
* @return boolean
* @return boolean
*/
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
if
(
preg_match
(
"/
$args
/"
,
$value
))
if
(
is_array
(
$args
))
{
foreach
(
$args
as
$regexp
)
{
if
(
!
preg_match
(
"/
$args
/"
,
$value
))
return
false
;
}
return
true
;
return
true
;
}
else
{
if
(
preg_match
(
"/
$args
/"
,
$value
))
return
true
;
}
return
false
;
return
false
;
}
}
}
}
...
...
tests/ValidatorTestCase.php
View file @
276af652
...
@@ -72,7 +72,9 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
...
@@ -72,7 +72,9 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
public
function
testValidate2
()
{
public
function
testValidate2
()
{
$test
=
new
ValidatorTest
();
$test
=
new
ValidatorTest
();
$test
->
mymixed
=
"message"
;
$test
->
mymixed
=
"message"
;
$test
->
myrange
=
1
;
$test
->
myregexp
=
'123a'
;
$validator
=
new
Doctrine_Validator
();
$validator
=
new
Doctrine_Validator
();
$validator
->
validateRecord
(
$test
);
$validator
->
validateRecord
(
$test
);
...
@@ -85,6 +87,8 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
...
@@ -85,6 +87,8 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$stack
[
'mystring'
],
Doctrine_Validator
::
ERR_NOTNULL
);
$this
->
assertEqual
(
$stack
[
'mystring'
],
Doctrine_Validator
::
ERR_NOTNULL
);
$this
->
assertEqual
(
$stack
[
'myemail2'
],
Doctrine_Validator
::
ERR_NOTBLANK
);
$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'
;
$test
->
mystring
=
'str'
;
...
...
tests/classes.php
View file @
276af652
...
@@ -397,6 +397,9 @@ class ValidatorTest extends Doctrine_Record {
...
@@ -397,6 +397,9 @@ class ValidatorTest extends Doctrine_Record {
$this
->
hasColumn
(
"myarray"
,
"array"
,
1000
);
$this
->
hasColumn
(
"myarray"
,
"array"
,
1000
);
$this
->
hasColumn
(
"myobject"
,
"object"
,
1000
);
$this
->
hasColumn
(
"myobject"
,
"object"
,
1000
);
$this
->
hasColumn
(
"myinteger"
,
"integer"
,
11
);
$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
(
"myemail"
,
"string"
,
100
,
"email"
);
$this
->
hasColumn
(
"myemail2"
,
"string"
,
100
,
"email|notblank"
);
$this
->
hasColumn
(
"myemail2"
,
"string"
,
100
,
"email|notblank"
);
}
}
...
...
tests/run.php
View file @
276af652
...
@@ -62,8 +62,6 @@ $test->addTestCase(new Doctrine_Filter_TestCase());
...
@@ -62,8 +62,6 @@ $test->addTestCase(new Doctrine_Filter_TestCase());
$test
->
addTestCase
(
new
Doctrine_ValueHolder_TestCase
());
$test
->
addTestCase
(
new
Doctrine_ValueHolder_TestCase
());
$test
->
addTestCase
(
new
Doctrine_ValidatorTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
$test
->
addTestCase
(
new
Doctrine_RawSql_TestCase
());
$test
->
addTestCase
(
new
Doctrine_RawSql_TestCase
());
...
@@ -76,6 +74,7 @@ $test->addTestCase(new Doctrine_ImportTestCase());
...
@@ -76,6 +74,7 @@ $test->addTestCase(new Doctrine_ImportTestCase());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_ValidatorTestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
//$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