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
d3098e3a
Commit
d3098e3a
authored
Jun 19, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor validator fix
parent
7b19bef1
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
26 deletions
+51
-26
Collection.php
Doctrine/Collection.php
+4
-2
Form.php
Doctrine/Form.php
+8
-9
Lib.php
Doctrine/Lib.php
+5
-5
Record.php
Doctrine/Record.php
+7
-4
Table.php
Doctrine/Table.php
+11
-4
Validator.php
Doctrine/Validator.php
+15
-2
ValidatorTestCase.php
tests/ValidatorTestCase.php
+1
-0
No files found.
Doctrine/Collection.php
View file @
d3098e3a
...
@@ -312,8 +312,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -312,8 +312,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @return boolean
* @return boolean
*/
*/
public
function
remove
(
$key
)
{
public
function
remove
(
$key
)
{
if
(
!
isset
(
$this
->
data
[
$key
]))
if
(
!
isset
(
$this
->
data
[
$key
]))
{
$this
->
expand
(
$key
);
throw
new
InvalidKeyException
();
throw
new
InvalidKeyException
();
}
$removed
=
$this
->
data
[
$key
];
$removed
=
$this
->
data
[
$key
];
...
@@ -417,7 +419,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -417,7 +419,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if
(
in_array
(
$record
,
$this
->
data
))
{
if
(
in_array
(
$record
,
$this
->
data
))
{
return
false
;
return
false
;
}
else
}
if
(
isset
(
$this
->
generator
))
{
if
(
isset
(
$this
->
generator
))
{
$key
=
$this
->
generator
->
getIndex
(
$record
);
$key
=
$this
->
generator
->
getIndex
(
$record
);
...
...
Doctrine/Form.php
View file @
d3098e3a
...
@@ -21,25 +21,24 @@ class Doctrine_Form implements Iterator {
...
@@ -21,25 +21,24 @@ class Doctrine_Form implements Iterator {
$definitions
=
$this
->
columns
[
$column
];
$definitions
=
$this
->
columns
[
$column
];
$e
=
explode
(
"|"
,
$definitions
[
2
]);
$e
=
explode
(
"|"
,
$definitions
[
2
]);
$enum
=
false
;
$enum
=
false
;
foreach
(
$e
as
$v
)
{
$e2
=
explode
(
":"
,
$v
);
if
(
$definitions
[
0
]
==
"enum"
)
if
(
$e2
[
0
]
==
"enum"
)
{
$enum
=
$this
->
record
->
getTable
()
->
getEnumValues
(
$column
);
$enum
=
explode
(
"-"
,
$e2
[
1
]);
break
;
}
}
$length
=
$definitions
[
1
];
$length
=
$definitions
[
1
];
if
(
!
in_array
(
"autoincrement"
,
$e
)
&&
!
in_array
(
"protected"
,
$e
))
{
if
(
!
in_array
(
"autoincrement"
,
$e
)
&&
!
in_array
(
"protected"
,
$e
))
{
if
(
$enum
)
{
if
(
$enum
)
{
$elements
[
$column
]
=
"<select name='data[
$column
]'>
\n
"
;
$elements
[
$column
]
=
"<select name='data[
$column
]'>
\n
"
;
foreach
(
$enum
as
$k
=>
$v
)
{
foreach
(
$enum
as
$k
=>
$v
)
{
if
(
$this
->
record
->
get
(
$column
)
==
$
k
)
{
if
(
$this
->
record
->
get
(
$column
)
==
$
v
)
{
$str
=
'selected'
;
$str
=
'selected'
;
}
else
}
else
$str
=
''
;
$str
=
''
;
$elements
[
$column
]
.=
" <option value='
$
k
'
$str
>
$v
</option>
\n
"
;
$elements
[
$column
]
.=
" <option value='
$
v
'
$str
>
$v
</option>
\n
"
;
}
}
$elements
[
$column
]
.=
"</select>
\n
"
;
$elements
[
$column
]
.=
"</select>
\n
"
;
}
else
{
}
else
{
...
...
Doctrine/Lib.php
View file @
d3098e3a
...
@@ -29,7 +29,7 @@ class Doctrine_Lib {
...
@@ -29,7 +29,7 @@ class Doctrine_Lib {
* @param Doctrine_Record $record
* @param Doctrine_Record $record
* @return string
* @return string
*/
*/
public
function
getRecordAsString
(
Doctrine_Record
$record
)
{
public
static
function
getRecordAsString
(
Doctrine_Record
$record
)
{
$r
[]
=
"<pre>"
;
$r
[]
=
"<pre>"
;
$r
[]
=
"Component : "
.
$record
->
getTable
()
->
getComponentName
();
$r
[]
=
"Component : "
.
$record
->
getTable
()
->
getComponentName
();
$r
[]
=
"ID : "
.
$record
->
getID
();
$r
[]
=
"ID : "
.
$record
->
getID
();
...
@@ -65,7 +65,7 @@ class Doctrine_Lib {
...
@@ -65,7 +65,7 @@ class Doctrine_Lib {
* @param Doctrine_Session $session
* @param Doctrine_Session $session
* @return string
* @return string
*/
*/
public
function
getSessionAsString
(
Doctrine_Session
$session
)
{
public
static
function
getSessionAsString
(
Doctrine_Session
$session
)
{
$r
[]
=
"<pre>"
;
$r
[]
=
"<pre>"
;
$r
[]
=
"Doctrine_Session object"
;
$r
[]
=
"Doctrine_Session object"
;
$r
[]
=
"State : "
.
Doctrine_Lib
::
getSessionStateAsString
(
$session
->
getState
());
$r
[]
=
"State : "
.
Doctrine_Lib
::
getSessionStateAsString
(
$session
->
getState
());
...
@@ -109,7 +109,7 @@ class Doctrine_Lib {
...
@@ -109,7 +109,7 @@ class Doctrine_Lib {
* @param Doctrine_Table $table
* @param Doctrine_Table $table
* @return string
* @return string
*/
*/
public
function
getTableAsString
(
Doctrine_Table
$table
)
{
public
static
function
getTableAsString
(
Doctrine_Table
$table
)
{
$r
[]
=
"<pre>"
;
$r
[]
=
"<pre>"
;
$r
[]
=
"Component : "
.
$this
->
getComponentName
();
$r
[]
=
"Component : "
.
$this
->
getComponentName
();
$r
[]
=
"Table : "
.
$this
->
getTableName
();
$r
[]
=
"Table : "
.
$this
->
getTableName
();
...
@@ -124,7 +124,7 @@ class Doctrine_Lib {
...
@@ -124,7 +124,7 @@ class Doctrine_Lib {
/**
/**
* @return string
* @return string
*/
*/
public
function
formatSql
(
$sql
)
{
public
static
function
formatSql
(
$sql
)
{
$e
=
explode
(
"
\n
"
,
$sql
);
$e
=
explode
(
"
\n
"
,
$sql
);
$color
=
"367FAC"
;
$color
=
"367FAC"
;
$l
=
$sql
;
$l
=
$sql
;
...
@@ -146,7 +146,7 @@ class Doctrine_Lib {
...
@@ -146,7 +146,7 @@ class Doctrine_Lib {
* @param Doctrine_Collection $collection
* @param Doctrine_Collection $collection
* @return string
* @return string
*/
*/
public
function
getCollectionAsString
(
Doctrine_Collection
$collection
)
{
public
static
function
getCollectionAsString
(
Doctrine_Collection
$collection
)
{
$r
[]
=
"<pre>"
;
$r
[]
=
"<pre>"
;
$r
[]
=
get_class
(
$collection
);
$r
[]
=
get_class
(
$collection
);
...
...
Doctrine/Record.php
View file @
d3098e3a
...
@@ -172,6 +172,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -172,6 +172,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
// listen the onLoad event
// listen the onLoad event
$this
->
table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onLoad
(
$this
);
$this
->
table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onLoad
(
$this
);
}
}
$this
->
table
->
getRepository
()
->
add
(
$this
);
$this
->
table
->
getRepository
()
->
add
(
$this
);
}
}
}
}
...
@@ -229,7 +230,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -229,7 +230,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if
(
!
isset
(
$tmp
[
$name
]))
{
if
(
!
isset
(
$tmp
[
$name
]))
{
if
(
$type
==
'array'
)
{
if
(
$type
==
'array'
)
{
$this
->
data
[
$name
]
=
array
();
$this
->
data
[
$name
]
=
array
();
$this
->
modified
[]
=
$name
;
}
else
}
else
$this
->
data
[
$name
]
=
self
::
$null
;
$this
->
data
[
$name
]
=
self
::
$null
;
}
else
{
}
else
{
...
@@ -715,7 +715,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -715,7 +715,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
final
public
function
getModified
()
{
final
public
function
getModified
()
{
$a
=
array
();
$a
=
array
();
foreach
(
$this
->
modified
as
$k
=>
$v
)
{
foreach
(
$this
->
modified
as
$k
=>
$v
)
{
$a
[
$v
]
=
$this
->
data
[
$v
];
$a
[
$v
]
=
$this
->
data
[
$v
];
}
}
return
$a
;
return
$a
;
...
@@ -726,10 +726,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -726,10 +726,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*
*
* @return array
* @return array
*/
*/
final
public
function
getPrepared
()
{
final
public
function
getPrepared
(
array
$array
=
array
()
)
{
$a
=
array
();
$a
=
array
();
foreach
(
$this
->
modified
as
$k
=>
$v
)
{
if
(
empty
(
$array
))
$array
=
$this
->
modified
;
foreach
(
$array
as
$k
=>
$v
)
{
$type
=
$this
->
table
->
getTypeOf
(
$v
);
$type
=
$this
->
table
->
getTypeOf
(
$v
);
if
(
$type
==
'array'
||
if
(
$type
==
'array'
||
...
...
Doctrine/Table.php
View file @
d3098e3a
...
@@ -127,12 +127,9 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -127,12 +127,9 @@ class Doctrine_Table extends Doctrine_Configurable {
$record
=
new
$name
(
$this
);
$record
=
new
$name
(
$this
);
$names
=
array
();
$names
=
array
();
$class
=
$name
;
$class
=
$name
;
// get parent classes
// get parent classes
...
@@ -825,6 +822,16 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -825,6 +822,16 @@ class Doctrine_Table extends Doctrine_Configurable {
final
public
function
setEnumValues
(
$field
,
array
$values
)
{
final
public
function
setEnumValues
(
$field
,
array
$values
)
{
$this
->
enum
[
$field
]
=
$values
;
$this
->
enum
[
$field
]
=
$values
;
}
}
/**
* @param string $field
* @return array
*/
final
public
function
getEnumValues
(
$field
)
{
if
(
isset
(
$this
->
enum
[
$field
]))
return
$this
->
enum
[
$field
];
else
return
array
();
}
/**
/**
* enumValue
* enumValue
*/
*/
...
@@ -836,7 +843,7 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -836,7 +843,7 @@ class Doctrine_Table extends Doctrine_Configurable {
*/
*/
final
public
function
enumIndex
(
$field
,
$value
)
{
final
public
function
enumIndex
(
$field
,
$value
)
{
$v
=
array_search
(
$value
,
$this
->
enum
[
$field
]);
$v
=
array_search
(
$value
,
$this
->
enum
[
$field
]);
return
(
$v
!==
false
)
?
$v
:
$value
;
return
$v
;
}
}
/**
/**
* @return integer
* @return integer
...
...
Doctrine/Validator.php
View file @
d3098e3a
...
@@ -106,21 +106,31 @@ class Doctrine_Validator {
...
@@ -106,21 +106,31 @@ class Doctrine_Validator {
switch
(
$record
->
getState
())
:
switch
(
$record
->
getState
())
:
case
Doctrine_Record
::
STATE_TDIRTY
:
case
Doctrine_Record
::
STATE_TDIRTY
:
case
Doctrine_Record
::
STATE_TCLEAN
:
case
Doctrine_Record
::
STATE_TCLEAN
:
// all fields will be validated
$data
=
$record
->
getData
();
$data
=
$record
->
getData
();
break
;
break
;
default
:
default
:
// only the modified fields will be validated
$data
=
$record
->
getModified
();
$data
=
$record
->
getModified
();
endswitch
;
endswitch
;
$err
=
array
();
$err
=
array
();
foreach
(
$data
as
$key
=>
$value
)
{
foreach
(
$data
as
$key
=>
$value
)
{
if
(
$value
===
self
::
$null
)
if
(
$value
===
self
::
$null
)
$value
=
null
;
$value
=
null
;
$column
=
$columns
[
$key
];
$column
=
$columns
[
$key
];
if
(
$column
[
0
]
==
"enum"
)
{
$value
=
$record
->
getTable
()
->
enumIndex
(
$value
);
if
(
$value
===
false
)
{
$err
[
$key
]
=
Doctrine_Validator
::
ERR_ENUM
;
continue
;
}
}
if
(
$column
[
0
]
==
'array'
||
$column
[
0
]
==
'object'
)
if
(
$column
[
0
]
==
"array"
||
$column
[
0
]
==
"object"
)
$length
=
strlen
(
serialize
(
$value
));
$length
=
strlen
(
serialize
(
$value
));
else
else
$length
=
strlen
(
$value
);
$length
=
strlen
(
$value
);
...
@@ -199,6 +209,9 @@ class Doctrine_Validator {
...
@@ -199,6 +209,9 @@ class Doctrine_Validator {
*/
*/
public
static
function
isValidType
(
$var
,
$type
)
{
public
static
function
isValidType
(
$var
,
$type
)
{
$looseType
=
self
::
gettype
(
$var
);
$looseType
=
self
::
gettype
(
$var
);
if
(
$type
==
'enum'
)
$type
=
'integer'
;
switch
(
$looseType
)
:
switch
(
$looseType
)
:
case
'float'
:
case
'float'
:
case
'double'
:
case
'double'
:
...
...
tests/ValidatorTestCase.php
View file @
d3098e3a
...
@@ -158,5 +158,6 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
...
@@ -158,5 +158,6 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$a
[
"User"
][
0
][
"name"
],
Doctrine_Validator
::
ERR_LENGTH
);
$this
->
assertEqual
(
$a
[
"User"
][
0
][
"name"
],
Doctrine_Validator
::
ERR_LENGTH
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
false
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_VLD
,
false
);
}
}
}
}
?>
?>
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