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
86b319e6
Commit
86b319e6
authored
May 24, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved validation API
require_once bug fix
parent
ced9625b
Changes
34
Hide whitespace changes
Inline
Side-by-side
Showing
34 changed files
with
124 additions
and
29 deletions
+124
-29
Collection.class.php
classes/Collection.class.php
+1
-0
Lazy.class.php
classes/Collection/Lazy.class.php
+1
-1
Find.class.php
classes/Exception/Find.class.php
+1
-0
Mapping.class.php
classes/Exception/Mapping.class.php
+1
-0
Naming.class.php
classes/Exception/Naming.class.php
+1
-0
PrimaryKey.class.php
classes/Exception/PrimaryKey.class.php
+1
-0
Refresh.class.php
classes/Exception/Refresh.class.php
+1
-0
Session.class.php
classes/Exception/Session.class.php
+1
-0
Table.class.php
classes/Exception/Table.class.php
+1
-0
Validator.class.php
classes/Exception/Validator.class.php
+2
-0
Query.class.php
classes/Query.class.php
+1
-0
Record.class.php
classes/Record.class.php
+25
-0
Sensei.class.php
classes/Sensei/Sensei.class.php
+1
-1
Common.class.php
classes/Session/Common.class.php
+1
-0
Firebird.class.php
classes/Session/Firebird.class.php
+1
-0
Informix.class.php
classes/Session/Informix.class.php
+1
-0
Mssql.class.php
classes/Session/Mssql.class.php
+1
-0
Mysql.class.php
classes/Session/Mysql.class.php
+1
-0
Oracle.class.php
classes/Session/Oracle.class.php
+1
-0
Pgsql.class.php
classes/Session/Pgsql.class.php
+1
-0
Sqlite.class.php
classes/Session/Sqlite.class.php
+1
-0
Validator.class.php
classes/Validator.class.php
+47
-9
Country.class.php
classes/Validator/Country.class.php
+2
-1
Date.class.php
classes/Validator/Date.class.php
+2
-1
Email.class.php
classes/Validator/Email.class.php
+2
-1
Htmlcolor.class.php
classes/Validator/Htmlcolor.class.php
+2
-1
Ip.class.php
classes/Validator/Ip.class.php
+2
-1
Nospace.class.php
classes/Validator/Nospace.class.php
+2
-1
Notblank.class.php
classes/Validator/Notblank.class.php
+5
-2
Range.class.php
classes/Validator/Range.class.php
+2
-1
Regexp.class.php
classes/Validator/Regexp.class.php
+2
-1
Unique.class.php
classes/Validator/Unique.class.php
+2
-1
Usstate.class.php
classes/Validator/Usstate.class.php
+2
-1
ValidatorTestCase.class.php
tests/ValidatorTestCase.class.php
+6
-6
No files found.
classes/Collection.class.php
View file @
86b319e6
<?php
require_once
(
"Access.class.php"
);
/**
* Doctrine_Collection
* Collection of Doctrine_Record objects.
...
...
classes/Collection/Lazy.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Collection
.class.php"
);
require_once
(
"Batch
.class.php"
);
/**
* a collection of Doctrine_Record objects with lazy load strategy
* (batch load strategy with batch size 1)
...
...
classes/Exception/Find.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Exception.class.php"
);
/**
* thrown when user tries to find a Doctrine_Record for given primary key and that object is not found
*/
...
...
classes/Exception/Mapping.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Exception.class.php"
);
/**
* thrown when user tries to get a foreign key object but the mapping is not done right
*/
...
...
classes/Exception/Naming.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Exception.class.php"
);
/**
* thrown when user defined Doctrine_Table is badly named
*/
...
...
classes/Exception/PrimaryKey.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Exception.class.php"
);
/**
* thrown when Doctrine_Record is loaded and there is no primary key field
*/
...
...
classes/Exception/Refresh.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Exception.class.php"
);
/**
* thrown when Doctrine_Record is refreshed and the refreshed primary key doens't match the old one
*/
...
...
classes/Exception/Session.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Exception.class.php"
);
/**
* thrown when user tries to get the current
* session and there are no open sessions
...
...
classes/Exception/Table.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Exception.class.php"
);
/**
* thrown when user tries to initialize a new instance of Doctrine_Table,
* while there already exists an instance of that table
...
...
classes/Exception/Validator.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Exception.class.php"
);
class
Doctrine_Validator_Exception
extends
Doctrine_Exception
{
private
$validator
;
public
function
__construct
(
Doctrine_Validator
$validator
)
{
...
...
classes/Query.class.php
View file @
86b319e6
<?php
require_once
(
"Access.class.php"
);
/**
* Doctrine_Query
*
...
...
classes/Record.class.php
View file @
86b319e6
...
...
@@ -533,6 +533,31 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this
->
references
[
$name
]
=
$value
;
}
}
/**
* __isset
*
* @param string $name
* @return boolean
*/
public
function
__isset
(
$name
)
{
if
(
isset
(
$this
->
data
[
$name
]))
return
true
;
if
(
isset
(
$this
->
references
[
$name
]))
return
true
;
return
false
;
}
/**
* @param string $name
* @return void
*/
public
function
__unset
(
$name
)
{
if
(
isset
(
$this
->
data
[
$name
]))
$this
->
data
[
$name
]
=
array
();
// todo: what to do with references ?
}
/**
* applies the changes made to this object into database
* this method is smart enough to know if any changes are made
...
...
classes/Sensei/Sensei.class.php
View file @
86b319e6
...
...
@@ -94,7 +94,7 @@ class Sensei extends Doctrine_Access {
public
function
__construct
()
{
if
(
headers_sent
())
if
(
headers_sent
())
throw
new
Sensei_Exception
(
"Headers already sent. Couldn't initialize session."
);
$this
->
session
=
Doctrine_Manager
::
getInstance
()
->
getCurrentSession
();
...
...
classes/Session/Common.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Session.class.php"
);
/**
* standard session, the parent of pgsql, mysql and sqlite
*/
...
...
classes/Session/Firebird.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Session.class.php"
);
/**
* firebird driver
*/
...
...
classes/Session/Informix.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Session.class.php"
);
/**
* informix database driver
*/
...
...
classes/Session/Mssql.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Session.class.php"
);
/**
* mssql driver
*/
...
...
classes/Session/Mysql.class.php
View file @
86b319e6
<?php
require_once
(
"Common.class.php"
);
/**
* mysql driver
*/
...
...
classes/Session/Oracle.class.php
View file @
86b319e6
<?php
require_once
(
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
.
"Session.class.php"
);
/**
* oracle driver
*/
...
...
classes/Session/Pgsql.class.php
View file @
86b319e6
<?php
require_once
(
"Common.class.php"
);
/**
* pgsql driver
*/
...
...
classes/Session/Sqlite.class.php
View file @
86b319e6
<?php
require_once
(
"Common.class.php"
);
/**
* sqlite driver
*/
...
...
classes/Validator.class.php
View file @
86b319e6
...
...
@@ -15,19 +15,42 @@ class Doctrine_Validator {
/**
* constant for length validation error
*/
const
ERR_LENGTH
=
0
;
const
ERR_LENGTH
=
0
;
/**
* constant for type validation error
*/
const
ERR_TYPE
=
1
;
const
ERR_TYPE
=
1
;
/**
* constant for general validation error
*/
const
ERR_VALID
=
2
;
const
ERR_VALID
=
2
;
/**
* constant for unique validation error
*/
const
ERR_UNIQUE
=
3
;
const
ERR_UNIQUE
=
3
;
/**
* constant for blank validation error
*/
const
ERR_BLANK
=
4
;
/**
* constant for date validation error
*/
const
ERR_DATE
=
5
;
/**
* constant for null validation error
*/
const
ERR_NULL
=
6
;
/**
* constant for enum validation error
*/
const
ERR_ENUM
=
7
;
/**
* constant for range validation error
*/
const
ERR_RANGE
=
8
;
/**
* @var array $stack error stack
...
...
@@ -74,7 +97,7 @@ class Doctrine_Validator {
if
(
strlen
(
$value
)
>
$column
[
1
])
{
$err
[
$key
]
=
Doctrine_Validator
::
ERR_LENGTH
;
continue
;
}
}
if
(
self
::
gettype
(
$value
)
!==
$column
[
0
])
{
$err
[
$key
]
=
Doctrine_Validator
::
ERR_TYPE
;
...
...
@@ -84,20 +107,35 @@ class Doctrine_Validator {
$e
=
explode
(
"|"
,
$column
[
2
]);
foreach
(
$e
as
$k
=>
$arg
)
{
if
(
empty
(
$arg
)
||
$arg
==
"primary"
)
if
(
empty
(
$arg
)
||
$arg
==
"primary"
||
$arg
==
"protected"
||
$arg
==
"autoincrement"
)
continue
;
$validator
=
self
::
getValidator
(
$arg
);
if
(
!
$validator
->
validate
(
$record
,
$key
,
$value
))
{
switch
(
strtolower
(
$arg
))
:
$args
=
explode
(
":"
,
$arg
);
if
(
!
isset
(
$args
[
1
]))
$args
[
1
]
=
''
;
$validator
=
self
::
getValidator
(
$args
[
0
]);
if
(
!
$validator
->
validate
(
$record
,
$key
,
$value
,
$args
[
1
]))
{
switch
(
strtolower
(
$args
[
0
]))
:
case
"unique"
:
$err
[
$key
]
=
Doctrine_Validator
::
ERR_UNIQUE
;
break
;
case
"notnull"
:
$err
[
$key
]
=
Doctrine_Validator
::
ERR_NULL
;
break
;
case
"notblank"
:
$err
[
$key
]
=
Doctrine_Validator
::
ERR_BLANK
;
break
;
case
"enum"
:
$err
[
$key
]
=
Doctrine_Validator
::
ERR_VALID
;
break
;
default
:
$err
[
$key
]
=
Doctrine_Validator
::
ERR_VALID
;
break
;
endswitch
;
}
// errors found quit validation looping for this column
if
(
isset
(
$err
[
$key
]))
break
;
}
...
...
classes/Validator/Country.class.php
View file @
86b319e6
...
...
@@ -254,9 +254,10 @@ class Doctrine_Validator_Country {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
return
isset
(
self
::
$countries
[
$value
]);
}
...
...
classes/Validator/Date.class.php
View file @
86b319e6
...
...
@@ -4,9 +4,10 @@ class Doctrine_Validator_Date {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
return
checkdate
(
$value
);
}
}
...
...
classes/Validator/Email.class.php
View file @
86b319e6
...
...
@@ -4,9 +4,10 @@ class Doctrine_Validator_Email {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
$parts
=
explode
(
"@"
,
$value
);
if
(
count
(
$parts
)
!=
2
)
...
...
classes/Validator/Htmlcolor.class.php
View file @
86b319e6
...
...
@@ -4,9 +4,10 @@ class Doctrine_Validator_HtmlColor {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
if
(
!
preg_match
(
"/^#
{
0,1}[0-9]{6
}
$/"
,
$color
))
{
return
false
;
}
...
...
classes/Validator/Ip.class.php
View file @
86b319e6
...
...
@@ -4,9 +4,10 @@ class Doctrine_Validator_Ip {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
$e
=
explode
(
"."
,
$request
);
if
(
count
(
$e
)
!=
4
)
return
false
;
...
...
classes/Validator/Nospace.class.php
View file @
86b319e6
...
...
@@ -4,9 +4,10 @@ class Doctrine_Validator_NoSpace {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
if
(
preg_match
(
"/[\s
\r\t\n
]/"
,
$value
))
return
false
;
...
...
classes/Validator/Notblank.class.php
View file @
86b319e6
...
...
@@ -4,15 +4,18 @@ class Doctrine_Validator_Notblank {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
$string
=
str_replace
(
"
\n
"
,
""
,
$value
);
$string
=
str_replace
(
"
\r
"
,
""
,
$string
);
$string
=
str_replace
(
"
\t
"
,
""
,
$string
);
$string
=
str_replace
(
"\s"
,
""
,
$string
);
$string
=
str_replace
(
" "
,
""
,
$string
);
if
(
$string
==
""
)
return
true
;
if
(
$string
==
""
)
return
false
;
return
true
;
}
}
?>
classes/Validator/Range.class.php
View file @
86b319e6
...
...
@@ -16,9 +16,10 @@ class Doctrine_Validator_Range {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
if
(
$var
<
$this
->
min
)
return
false
;
...
...
classes/Validator/Regexp.class.php
View file @
86b319e6
...
...
@@ -4,9 +4,10 @@ class Doctrine_Validator_Regexp {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
return
$value
;
}
}
...
...
classes/Validator/Unique.class.php
View file @
86b319e6
...
...
@@ -4,9 +4,10 @@ class Doctrine_Validator_Unique {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
$table
=
$record
->
getTable
();
$sql
=
"SELECT id FROM "
.
$table
->
getTableName
()
.
" WHERE "
.
$key
.
" = ?"
;
$stmt
=
$table
->
getSession
()
->
getDBH
()
->
prepare
(
$sql
);
...
...
classes/Validator/Usstate.class.php
View file @
86b319e6
...
...
@@ -62,9 +62,10 @@ class ValidatorUSState {
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
{
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
return
isset
(
self
::
$states
[
$value
]);
}
}
...
...
tests/ValidatorTestCase.class.php
View file @
86b319e6
...
...
@@ -39,13 +39,13 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
$validator
=
new
Doctrine_Validator_Email
();
$email
=
$this
->
session
->
create
(
"Email"
);
$this
->
assertFalse
(
$validator
->
validate
(
$email
,
"address"
,
"example@example"
));
$this
->
assertFalse
(
$validator
->
validate
(
$email
,
"address"
,
"example@@example"
));
$this
->
assertFalse
(
$validator
->
validate
(
$email
,
"address"
,
"example@example."
));
$this
->
assertFalse
(
$validator
->
validate
(
$email
,
"address"
,
"example@e.."
));
$this
->
assertFalse
(
$validator
->
validate
(
$email
,
"address"
,
"example@example"
,
null
));
$this
->
assertFalse
(
$validator
->
validate
(
$email
,
"address"
,
"example@@example"
,
null
));
$this
->
assertFalse
(
$validator
->
validate
(
$email
,
"address"
,
"example@example."
,
null
));
$this
->
assertFalse
(
$validator
->
validate
(
$email
,
"address"
,
"example@e.."
,
null
));
$this
->
assertFalse
(
$validator
->
validate
(
$email
,
"address"
,
"example@e.."
));
$this
->
assertTrue
(
$validator
->
validate
(
$email
,
"address"
,
"example@e.e.e.e.e"
));
$this
->
assertFalse
(
$validator
->
validate
(
$email
,
"address"
,
"example@e.."
,
null
));
$this
->
assertTrue
(
$validator
->
validate
(
$email
,
"address"
,
"example@e.e.e.e.e"
,
null
));
}
public
function
testSave
()
{
...
...
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