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
04ca92b0
Commit
04ca92b0
authored
Jun 17, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enum datatype added
parent
aacb2795
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
104 additions
and
9 deletions
+104
-9
Collection.php
Doctrine/Collection.php
+7
-0
DataDict.php
Doctrine/DataDict.php
+2
-0
Module.php
Doctrine/Module.php
+0
-0
Query.php
Doctrine/Query.php
+5
-1
Record.php
Doctrine/Record.php
+22
-2
Table.php
Doctrine/Table.php
+38
-6
RecordTestCase.php
tests/RecordTestCase.php
+24
-0
classes.php
tests/classes.php
+6
-0
No files found.
Doctrine/Collection.php
View file @
04ca92b0
...
...
@@ -428,6 +428,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return
true
;
}
/**
* populate
*
* @param Doctrine_Query $query
* @param integer $key
*/
...
...
@@ -458,6 +460,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
}
/**
* getNormalIterator
* returns normal iterator - an iterator that will not expand this collection
*
* @return Doctrine_Iterator_Normal
*/
public
function
getNormalIterator
()
{
...
...
@@ -466,6 +471,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
/**
* save
* saves all records
*
* @return void
*/
public
function
save
()
{
$this
->
table
->
getSession
()
->
saveCollection
(
$this
);
...
...
Doctrine/DataDict.php
View file @
04ca92b0
...
...
@@ -82,6 +82,8 @@ class Doctrine_DataDict {
case
"bool"
:
return
"L"
;
break
;
case
"enum"
:
case
"e"
:
case
"integer"
:
case
"int"
:
case
"i"
:
...
...
Doctrine/Module.
class.
php
→
Doctrine/Module.php
View file @
04ca92b0
File moved
Doctrine/Query.php
View file @
04ca92b0
...
...
@@ -386,7 +386,7 @@ class Doctrine_Query extends Doctrine_Access {
foreach
(
$maps
as
$map
)
{
$b
=
array
();
foreach
(
$map
as
$field
=>
$value
)
{
$b
[]
=
$tname
.
".
$field
=
$value
"
;
$b
[]
=
$tname
.
".
$field
=
$value
"
;
//OR $tname.$field IS NULL";
}
if
(
!
empty
(
$b
))
$a
[]
=
implode
(
" AND "
,
$b
);
}
...
...
@@ -526,9 +526,13 @@ class Doctrine_Query extends Doctrine_Access {
if
(
$emptyID
)
{
$pointer
=
$this
->
joins
[
$name
];
$alias
=
$this
->
tables
[
$pointer
]
->
getAlias
(
$name
);
$fk
=
$this
->
tables
[
$pointer
]
->
getForeignKey
(
$alias
);
if
(
!
$prev
[
$pointer
])
continue
;
$last
=
$prev
[
$pointer
]
->
getLast
();
switch
(
$fk
->
getType
())
:
...
...
Doctrine/Record.php
View file @
04ca92b0
...
...
@@ -213,6 +213,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* $data = array("name"=>"John","lastname" => Object(Doctrine_Null));
*
* here column 'id' is removed since its auto-incremented primary key (protected)
*
* @return integer
*/
private
function
cleanData
()
{
$tmp
=
$this
->
data
;
...
...
@@ -236,12 +238,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
case
"object"
:
if
(
$tmp
[
$name
]
!==
self
::
$null
)
$this
->
data
[
$name
]
=
unserialize
(
$tmp
[
$name
]);
break
;
case
"enum"
:
$this
->
data
[
$name
]
=
$this
->
table
->
enumValue
(
$name
,
$tmp
[
$name
]);
break
;
default
:
$this
->
data
[
$name
]
=
$tmp
[
$name
];
$count
++
;
endswitch
;
$count
++
;
}
}
return
$count
;
...
...
@@ -429,6 +433,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
/**
* factoryRefresh
* refreshes the data from outer source (Doctrine_Table)
*
* @throws Doctrine_Exception
* @return void
*/
...
...
@@ -731,6 +737,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$a
[
$v
]
=
serialize
(
$this
->
data
[
$v
]);
continue
;
}
elseif
(
$type
==
'enum'
)
{
$a
[
$v
]
=
$this
->
table
->
enumIndex
(
$v
,
$this
->
data
[
$v
]);
continue
;
}
if
(
$this
->
data
[
$v
]
instanceof
Doctrine_Record
)
...
...
@@ -1127,6 +1137,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
break
;
endswitch
;
}
/**
* sets enumerated value array for given field
*
* @param string $field
* @param array $values
* @return void
*/
final
public
function
setEnumValues
(
$field
,
array
$values
)
{
$this
->
table
->
setEnumValues
(
$field
,
$values
);
}
/**
* binds One-to-One composite relation
...
...
Doctrine/Table.php
View file @
04ca92b0
...
...
@@ -102,6 +102,12 @@ class Doctrine_Table extends Doctrine_Configurable {
* @var array $parents the parent classes of this component
*/
private
$parents
=
array
();
/**
* @var array $enum enum value arrays
*/
private
$enum
=
array
();
/**
* the constructor
...
...
@@ -328,7 +334,7 @@ class Doctrine_Table extends Doctrine_Configurable {
* getParents
*/
final
public
function
getParents
()
{
return
$this
->
parents
;
return
$this
->
parents
;
}
/**
* @return boolean
...
...
@@ -742,11 +748,6 @@ class Doctrine_Table extends Doctrine_Configurable {
if
(
isset
(
$this
->
identityMap
[
$id
]))
$record
=
$this
->
identityMap
[
$id
];
else
{
/**
if($this->createsChildren) {
}
*/
$record
=
new
$this
->
name
(
$this
);
$this
->
identityMap
[
$id
]
=
$record
;
}
...
...
@@ -814,12 +815,36 @@ class Doctrine_Table extends Doctrine_Configurable {
}
return
$coll
;
}
/**
* sets enumerated value array for given field
*
* @param string $field
* @param array $values
* @return void
*/
final
public
function
setEnumValues
(
$field
,
array
$values
)
{
$this
->
enum
[
$field
]
=
$values
;
}
/**
* enumValue
*/
final
public
function
enumValue
(
$field
,
$index
)
{
return
isset
(
$this
->
enum
[
$field
][
$index
])
?
$this
->
enum
[
$field
][
$index
]
:
$index
;
}
/**
* enumIndex
*/
final
public
function
enumIndex
(
$field
,
$value
)
{
$v
=
array_search
(
$value
,
$this
->
enum
[
$field
]);
return
(
$v
!==
false
)
?
$v
:
$value
;
}
/**
* @return integer
*/
final
public
function
getColumnCount
()
{
return
$this
->
columnCount
;
}
/**
* returns all columns and their definitions
*
...
...
@@ -836,6 +861,13 @@ class Doctrine_Table extends Doctrine_Configurable {
public
function
getColumnNames
()
{
return
array_keys
(
$this
->
columns
);
}
/**
* getDefinitionOf
*/
public
function
getDefinitionOf
(
$column
)
{
if
(
isset
(
$this
->
columns
[
$column
]))
return
$this
->
columns
[
$column
];
}
/**
* getTypeOf
*/
...
...
tests/RecordTestCase.php
View file @
04ca92b0
...
...
@@ -2,6 +2,30 @@
require_once
(
"UnitTestCase.php"
);
class
Doctrine_RecordTestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareTables
()
{
$this
->
tables
[]
=
"enumTest"
;
parent
::
prepareTables
();
}
public
function
testEnumType
()
{
$enum
=
new
EnumTest
();
$enum
->
status
=
"open"
;
$this
->
assertEqual
(
$enum
->
status
,
"open"
);
$enum
->
save
();
$this
->
assertEqual
(
$enum
->
status
,
"open"
);
$enum
->
refresh
();
$this
->
assertEqual
(
$enum
->
status
,
"open"
);
$enum
->
status
=
"closed"
;
$this
->
assertEqual
(
$enum
->
status
,
"closed"
);
$enum
->
save
();
$this
->
assertEqual
(
$enum
->
status
,
"closed"
);
$enum
->
refresh
();
$this
->
assertEqual
(
$enum
->
status
,
"closed"
);
}
public
function
testSerialize
()
{
$user
=
$this
->
session
->
getTable
(
"User"
)
->
find
(
4
);
$str
=
serialize
(
$user
);
...
...
tests/classes.php
View file @
04ca92b0
...
...
@@ -312,6 +312,12 @@ class ORM_AccessControlsGroups extends Doctrine_Record {
$this
->
setPrimaryKey
(
array
(
"accessControlID"
,
"accessGroupID"
));
}
}
class
EnumTest
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"status"
,
"enum"
,
11
);
$this
->
setEnumValues
(
"status"
,
array
(
"open"
,
"verified"
,
"closed"
));
}
}
class
Log_Entry
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"stamp"
,
"timestamp"
);
...
...
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