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
c9877af4
Commit
c9877af4
authored
May 13, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preliminary support for relation aliases
parent
774f3fb7
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
183 additions
and
118 deletions
+183
-118
Access.class.php
classes/Access.class.php
+4
-2
Manager.class.php
classes/Manager.class.php
+7
-1
Record.class.php
classes/Record.class.php
+8
-5
Session.class.php
classes/Session.class.php
+50
-14
Table.class.php
classes/Table.class.php
+61
-69
Validator.class.php
classes/Validator.class.php
+12
-1
RecordTestCase.class.php
tests/RecordTestCase.class.php
+34
-23
TableTestCase.class.php
tests/TableTestCase.class.php
+2
-0
UnitTestCase.class.php
tests/UnitTestCase.class.php
+1
-0
classes.php
tests/classes.php
+4
-3
No files found.
classes/Access.class.php
View file @
c9877af4
<?php
<?php
/**
/**
* class Doctrine_Access
* class Doctrine_Access
* Doctrine_Record and Doctrine_Collection classes extend this base class
*
* the purpose of DAOStrategy is to provice array access and property overload interface for these classes
* the purpose of Doctrine_Access is to provice array access
* and property overload interface for subclasses
*/
*/
abstract
class
Doctrine_Access
implements
ArrayAccess
{
abstract
class
Doctrine_Access
implements
ArrayAccess
{
/**
/**
...
@@ -33,6 +34,7 @@ abstract class Doctrine_Access implements ArrayAccess {
...
@@ -33,6 +34,7 @@ abstract class Doctrine_Access implements ArrayAccess {
return
$this
->
get
(
$name
);
return
$this
->
get
(
$name
);
}
}
/**
/**
* @param mixed $offset
* @return boolean -- whether or not the data has a field $offset
* @return boolean -- whether or not the data has a field $offset
*/
*/
public
function
offsetExists
(
$offset
)
{
public
function
offsetExists
(
$offset
)
{
...
...
classes/Manager.class.php
View file @
c9877af4
...
@@ -70,6 +70,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
...
@@ -70,6 +70,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
}
}
/**
/**
* returns the root directory of Doctrine
* returns the root directory of Doctrine
*
* @return string
* @return string
*/
*/
final
public
function
getRoot
()
{
final
public
function
getRoot
()
{
...
@@ -77,7 +78,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
...
@@ -77,7 +78,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
}
}
/**
/**
* getInstance
* getInstance
* this class uses the singleton pattern
* returns an instance of this class
* (this class uses the singleton pattern)
*
* @return Doctrine_Manager
* @return Doctrine_Manager
*/
*/
final
public
static
function
getInstance
()
{
final
public
static
function
getInstance
()
{
...
@@ -171,6 +174,8 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
...
@@ -171,6 +174,8 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
}
}
/**
/**
* setCurrentSession
* setCurrentSession
* sets the current session to $key
*
* @param mixed $key the session key
* @param mixed $key the session key
* @throws InvalidKeyException
* @throws InvalidKeyException
* @return void
* @return void
...
@@ -217,6 +222,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
...
@@ -217,6 +222,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
/**
/**
* __toString
* __toString
* returns a string representation of this object
* returns a string representation of this object
*
* @return string
* @return string
*/
*/
public
function
__toString
()
{
public
function
__toString
()
{
...
...
classes/Record.class.php
View file @
c9877af4
...
@@ -815,7 +815,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -815,7 +815,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
final
public
function
loadReference
(
$name
)
{
final
public
function
loadReference
(
$name
)
{
$fk
=
$this
->
table
->
getForeignKey
(
$name
);
$fk
=
$this
->
table
->
getForeignKey
(
$name
);
$table
=
$fk
->
getTable
();
$table
=
$fk
->
getTable
();
$name
=
$table
->
getComponentName
();
$local
=
$fk
->
getLocal
();
$local
=
$fk
->
getLocal
();
$foreign
=
$fk
->
getForeign
();
$foreign
=
$fk
->
getForeign
();
$graph
=
$table
->
getQueryObject
();
$graph
=
$table
->
getQueryObject
();
...
@@ -837,7 +837,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -837,7 +837,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this
->
set
(
$fk
->
getLocal
(),
$this
->
references
[
$name
]);
$this
->
set
(
$fk
->
getLocal
(),
$this
->
references
[
$name
]);
}
}
}
else
{
}
else
{
$this
->
references
[
$name
]
=
new
Doctrine_Collection
(
$table
);
$this
->
references
[
$name
]
=
new
Doctrine_Collection
(
$table
);
if
(
$fk
instanceof
Doctrine_ForeignKey
)
{
if
(
$fk
instanceof
Doctrine_ForeignKey
)
{
// ONE-TO-MANY
// ONE-TO-MANY
...
@@ -849,13 +848,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -849,13 +848,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
case
Doctrine_Record
::
STATE_DIRTY
:
case
Doctrine_Record
::
STATE_DIRTY
:
case
Doctrine_Record
::
STATE_CLEAN
:
case
Doctrine_Record
::
STATE_CLEAN
:
case
Doctrine_Record
::
STATE_PROXY
:
case
Doctrine_Record
::
STATE_PROXY
:
switch
(
$fk
->
getType
())
:
switch
(
$fk
->
getType
())
:
case
Doctrine_Relation
::
ONE_COMPOSITE
:
case
Doctrine_Relation
::
ONE_COMPOSITE
:
case
Doctrine_Relation
::
ONE_AGGREGATE
:
case
Doctrine_Relation
::
ONE_AGGREGATE
:
// ONE-TO-ONE
// ONE-TO-ONE
$id
=
$this
->
get
(
$local
);
$id
=
$this
->
get
(
$local
);
if
(
$fk
instanceof
Doctrine_LocalKey
)
{
if
(
$fk
instanceof
Doctrine_LocalKey
)
{
if
(
empty
(
$id
))
{
if
(
empty
(
$id
))
{
$this
->
references
[
$name
]
=
$table
->
create
();
$this
->
references
[
$name
]
=
$table
->
create
();
$this
->
set
(
$fk
->
getLocal
(),
$this
->
references
[
$name
]);
$this
->
set
(
$fk
->
getLocal
(),
$this
->
references
[
$name
]);
...
@@ -868,11 +870,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -868,11 +870,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
}
}
elseif
(
$fk
instanceof
Doctrine_ForeignKey
)
{
}
elseif
(
$fk
instanceof
Doctrine_ForeignKey
)
{
if
(
empty
(
$id
))
{
if
(
empty
(
$id
))
{
$this
->
references
[
$name
]
=
$table
->
create
();
$this
->
references
[
$name
]
=
$table
->
create
();
$this
->
references
[
$name
]
->
set
(
$fk
->
getForeign
(),
$this
);
$this
->
references
[
$name
]
->
set
(
$fk
->
getForeign
(),
$this
);
}
else
{
}
else
{
$dql
=
"FROM "
.
$
name
.
" WHERE "
.
$name
.
"."
.
$fk
->
getForeign
()
.
" = ?"
;
$dql
=
"FROM "
.
$
table
->
getComponentName
()
.
" WHERE "
.
$table
->
getComponentName
()
.
"."
.
$fk
->
getForeign
()
.
" = ?"
;
$coll
=
$graph
->
query
(
$dql
,
array
(
$id
));
$coll
=
$graph
->
query
(
$dql
,
array
(
$id
));
$this
->
references
[
$name
]
=
$coll
[
0
];
$this
->
references
[
$name
]
=
$coll
[
0
];
$this
->
references
[
$name
]
->
set
(
$fk
->
getForeign
(),
$this
);
$this
->
references
[
$name
]
->
set
(
$fk
->
getForeign
(),
$this
);
...
@@ -883,7 +886,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -883,7 +886,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
// ONE-TO-MANY
// ONE-TO-MANY
if
(
$fk
instanceof
Doctrine_ForeignKey
)
{
if
(
$fk
instanceof
Doctrine_ForeignKey
)
{
$id
=
$this
->
get
(
$local
);
$id
=
$this
->
get
(
$local
);
$query
=
"FROM "
.
$
name
.
" WHERE "
.
$name
.
"."
.
$fk
->
getForeign
()
.
" = ?"
;
$query
=
"FROM "
.
$
table
->
getComponentName
()
.
" WHERE "
.
$table
->
getComponentName
()
.
"."
.
$fk
->
getForeign
()
.
" = ?"
;
$coll
=
$graph
->
query
(
$query
,
array
(
$id
));
$coll
=
$graph
->
query
(
$query
,
array
(
$id
));
$this
->
references
[
$name
]
=
$coll
;
$this
->
references
[
$name
]
=
$coll
;
...
...
classes/Session.class.php
View file @
c9877af4
...
@@ -131,6 +131,9 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -131,6 +131,9 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
/**
/**
* query
* query
* queries the database with Doctrine Query Language
* queries the database with Doctrine Query Language
*
* @param string $query DQL query
* @param array $params query parameters
*/
*/
final
public
function
query
(
$query
,
array
$params
=
array
())
{
final
public
function
query
(
$query
,
array
$params
=
array
())
{
$parser
=
new
Doctrine_Query
(
$this
);
$parser
=
new
Doctrine_Query
(
$this
);
...
@@ -177,12 +180,13 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -177,12 +180,13 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
return
isset
(
$this
->
tables
[
$name
]);
return
isset
(
$this
->
tables
[
$name
]);
}
}
/**
/**
* returns a table object for given component name
*
* @param string $name component name
* @param string $name component name
* @throws Doctrine_Table_Exception
* @return object Doctrine_Table
* @return object Doctrine_Table
*/
*/
public
function
getTable
(
$name
)
{
public
function
getTable
(
$name
)
{
$name
=
ucwords
(
strtolower
(
$name
));
//
$name = ucwords(strtolower($name));
if
(
isset
(
$this
->
tables
[
$name
]))
if
(
isset
(
$this
->
tables
[
$name
]))
return
$this
->
tables
[
$name
];
return
$this
->
tables
[
$name
];
...
@@ -197,25 +201,32 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -197,25 +201,32 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
}
}
}
}
/**
/**
* @return array -- an array of all initialized tables
* returns an array of all initialized tables
*
* @return array
*/
*/
public
function
getTables
()
{
public
function
getTables
()
{
return
$this
->
tables
;
return
$this
->
tables
;
}
}
/**
/**
* returns an iterator that iterators through all
* initialized table objects
*
* @return ArrayIterator
* @return ArrayIterator
*/
*/
public
function
getIterator
()
{
public
function
getIterator
()
{
return
new
ArrayIterator
(
$this
->
tables
);
return
new
ArrayIterator
(
$this
->
tables
);
}
}
/**
/**
* returns the count of initialized table objects
*
* @return integer
* @return integer
*/
*/
public
function
count
()
{
public
function
count
()
{
return
count
(
$this
->
tables
);
return
count
(
$this
->
tables
);
}
}
/**
/**
* @param $objTable
-- a Doctrine_Table object to be added into factory
registry
* @param $objTable
a Doctrine_Table object to be added into
registry
* @return boolean
* @return boolean
*/
*/
public
function
addTable
(
Doctrine_Table
$objTable
)
{
public
function
addTable
(
Doctrine_Table
$objTable
)
{
...
@@ -228,6 +239,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -228,6 +239,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
return
true
;
return
true
;
}
}
/**
/**
* creates a record
*
* create creates a record
* create creates a record
* @param string $name component name
* @param string $name component name
* @return Doctrine_Record Doctrine_Record object
* @return Doctrine_Record Doctrine_Record object
...
@@ -237,6 +250,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -237,6 +250,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
}
}
/**
/**
* buildFlushTree
* buildFlushTree
* builds a flush tree that is used in transactions
*
* @return array
* @return array
*/
*/
public
function
buildFlushTree
()
{
public
function
buildFlushTree
()
{
...
@@ -293,6 +308,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -293,6 +308,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
/**
/**
* saveAll
* saveAll
* saves all the records from all tables
* saves all the records from all tables
*
* @return void
*/
*/
private
function
saveAll
()
{
private
function
saveAll
()
{
$tree
=
$this
->
buildFlushTree
();
$tree
=
$this
->
buildFlushTree
();
...
@@ -314,6 +331,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -314,6 +331,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
/**
/**
* clear
* clear
* clears the whole registry
* clears the whole registry
*
* @return void
* @return void
*/
*/
public
function
clear
()
{
public
function
clear
()
{
...
@@ -408,7 +426,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -408,7 +426,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
}
}
/**
/**
* rollback
* rollback
* rolls back all t
he t
ransactions
* rolls back all transactions
* @return void
* @return void
*/
*/
public
function
rollback
()
{
public
function
rollback
()
{
...
@@ -501,6 +519,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -501,6 +519,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
/**
/**
* bulkUpdate
* bulkUpdate
* updates all objects in the pending update list
* updates all objects in the pending update list
*
* @return void
* @return void
*/
*/
public
function
bulkUpdate
()
{
public
function
bulkUpdate
()
{
...
@@ -527,6 +546,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -527,6 +546,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
}
}
/**
/**
* bulkDelete
* bulkDelete
* deletes all records from the pending delete list
*
* @return void
* @return void
*/
*/
public
function
bulkDelete
()
{
public
function
bulkDelete
()
{
...
@@ -549,10 +570,9 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -549,10 +570,9 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
}
}
$this
->
delete
=
array
();
$this
->
delete
=
array
();
}
}
/**
/**
* saves a collection
*
* @param Doctrine_Collection $coll
* @param Doctrine_Collection $coll
* @return void
* @return void
*/
*/
...
@@ -566,6 +586,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -566,6 +586,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$this
->
commit
();
$this
->
commit
();
}
}
/**
/**
* deletes all records from collection
*
* @param Doctrine_Collection $coll
* @param Doctrine_Collection $coll
* @return void
* @return void
*/
*/
...
@@ -577,6 +599,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -577,6 +599,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$this
->
commit
();
$this
->
commit
();
}
}
/**
/**
* saves the given record
*
* @param Doctrine_Record $record
* @param Doctrine_Record $record
* @return void
* @return void
*/
*/
...
@@ -596,6 +620,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -596,6 +620,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
endswitch
;
endswitch
;
}
}
/**
/**
* saves all related records to $record
*
* @param Doctrine_Record $record
* @param Doctrine_Record $record
*/
*/
final
public
function
saveRelated
(
Doctrine_Record
$record
)
{
final
public
function
saveRelated
(
Doctrine_Record
$record
)
{
...
@@ -638,6 +664,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -638,6 +664,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
return
$saveLater
;
return
$saveLater
;
}
}
/**
/**
* updates the given record
*
* @param Doctrine_Record $record
* @param Doctrine_Record $record
* @return boolean
* @return boolean
*/
*/
...
@@ -676,6 +704,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -676,6 +704,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
return
true
;
return
true
;
}
}
/**
/**
* inserts a record into database
*
* @param Doctrine_Record $record
* @param Doctrine_Record $record
* @return boolean
* @return boolean
*/
*/
...
@@ -711,7 +741,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -711,7 +741,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
}
}
/**
/**
* deletes all related composites
* deletes all related composites
* this method is always called internally when
this data access object
is deleted
* this method is always called internally when
a record
is deleted
*
*
* @return void
* @return void
*/
*/
...
@@ -752,7 +782,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -752,7 +782,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
endswitch
;
endswitch
;
}
}
/**
/**
* adds
data access object
into pending insert list
* adds
record
into pending insert list
* @param Doctrine_Record $record
* @param Doctrine_Record $record
*/
*/
public
function
addInsert
(
Doctrine_Record
$record
)
{
public
function
addInsert
(
Doctrine_Record
$record
)
{
...
@@ -760,7 +790,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -760,7 +790,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$this
->
insert
[
$name
][]
=
$record
;
$this
->
insert
[
$name
][]
=
$record
;
}
}
/**
/**
* adds
data access object
into penging update list
* adds
record
into penging update list
* @param Doctrine_Record $record
* @param Doctrine_Record $record
*/
*/
public
function
addUpdate
(
Doctrine_Record
$record
)
{
public
function
addUpdate
(
Doctrine_Record
$record
)
{
...
@@ -768,7 +798,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -768,7 +798,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$this
->
update
[
$name
][]
=
$record
;
$this
->
update
[
$name
][]
=
$record
;
}
}
/**
/**
* adds
data access object
into pending delete list
* adds
record
into pending delete list
* @param Doctrine_Record $record
* @param Doctrine_Record $record
*/
*/
public
function
addDelete
(
Doctrine_Record
$record
)
{
public
function
addDelete
(
Doctrine_Record
$record
)
{
...
@@ -776,18 +806,24 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -776,18 +806,24 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$this
->
delete
[
$name
][]
=
$record
;
$this
->
delete
[
$name
][]
=
$record
;
}
}
/**
/**
* returns the pending insert list
*
* @return array
* @return array
*/
*/
public
function
getInserts
()
{
public
function
getInserts
()
{
return
$this
->
insert
;
return
$this
->
insert
;
}
}
/**
/**
* returns the pending update list
*
* @return array
* @return array
*/
*/
public
function
getUpdates
()
{
public
function
getUpdates
()
{
return
$this
->
update
;
return
$this
->
update
;
}
}
/**
/**
* returns the pending delete list
*
* @return array
* @return array
*/
*/
public
function
getDeletes
()
{
public
function
getDeletes
()
{
...
...
classes/Table.class.php
View file @
c9877af4
...
@@ -21,9 +21,9 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -21,9 +21,9 @@ class Doctrine_Table extends Doctrine_Configurable {
*/
*/
private
$data
=
array
();
private
$data
=
array
();
/**
/**
* @var array $
foreignKeys an array containing all the Doctrine_ForeignKey
objects for this table
* @var array $
relations an array containing all the Doctrine_Relation
objects for this table
*/
*/
private
$
foreignKeys
=
array
();
private
$
relations
=
array
();
/**
/**
* @var array $primaryKeys an array containing all primary key column names
* @var array $primaryKeys an array containing all primary key column names
*/
*/
...
@@ -337,25 +337,14 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -337,25 +337,14 @@ class Doctrine_Table extends Doctrine_Configurable {
return
$this
->
bound
[
$name
];
return
$this
->
bound
[
$name
];
}
}
/**
/**
* @param string $
objTableN
ame
* @param string $
n
ame
* @param string $field
* @param string $field
* @return void
* @return void
*/
*/
final
public
function
bind
(
$objTableName
,
$field
,
$type
,
$localKey
)
{
final
public
function
bind
(
$name
,
$field
,
$type
,
$localKey
)
{
$name
=
(
string
)
$objTableName
;
if
(
isset
(
$this
->
relations
[
$name
]))
$field
=
(
string
)
$field
;
if
(
isset
(
$this
->
foreignKeys
[
$name
]))
throw
new
InvalidKeyException
();
throw
new
InvalidKeyException
();
$e
=
explode
(
"."
,
$field
);
// is reference table used?
if
(
$e
[
0
]
!=
$name
&&
$e
[
0
]
==
$this
->
name
)
$this
->
bound
[
$name
]
=
array
(
$field
,
Doctrine_Relation
::
MANY_COMPOSITE
);
$this
->
bound
[
$name
]
=
array
(
$field
,
$type
,
$localKey
);
$this
->
bound
[
$name
]
=
array
(
$field
,
$type
,
$localKey
);
}
}
/**
/**
...
@@ -388,55 +377,58 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -388,55 +377,58 @@ class Doctrine_Table extends Doctrine_Configurable {
* @return Doctrine_Relation
* @return Doctrine_Relation
*/
*/
final
public
function
getForeignKey
(
$name
)
{
final
public
function
getForeignKey
(
$name
)
{
if
(
isset
(
$this
->
foreignKey
s
[
$name
]))
if
(
isset
(
$this
->
relation
s
[
$name
]))
return
$this
->
foreignKey
s
[
$name
];
return
$this
->
relation
s
[
$name
];
if
(
isset
(
$this
->
bound
[
$name
]))
{
if
(
isset
(
$this
->
bound
[
$name
]))
{
$field
=
$this
->
bound
[
$name
][
0
];
$type
=
$this
->
bound
[
$name
][
1
];
$type
=
$this
->
bound
[
$name
][
1
];
$local
=
$this
->
bound
[
$name
][
2
];
$local
=
$this
->
bound
[
$name
][
2
];
$e
=
explode
(
"."
,
$field
);
$e
=
explode
(
"."
,
$this
->
bound
[
$name
][
0
]);
$objTable
=
$this
->
session
->
getTable
(
$name
);
$component
=
$e
[
0
];
$foreign
=
$e
[
1
];
switch
(
$e
[
0
])
:
$e
=
explode
(
" as "
,
$name
);
case
$name
:
$name
=
$e
[
0
];
if
(
!
isset
(
$local
))
$local
=
$this
->
identifier
;
// ONE-TO-MANY or ONE-TO-ONE
if
(
isset
(
$e
[
1
]))
$foreignKey
=
new
Doctrine_ForeignKey
(
$objTable
,
$local
,
$e
[
1
],
$type
);
$alias
=
$e
[
1
];
break
;
else
case
$this
->
name
:
$alias
=
$name
;
// ONE-TO-ONE
$table
=
$this
->
session
->
getTable
(
$name
);
if
(
$component
==
$this
->
name
||
in_array
(
$component
,
$this
->
parents
))
{
if
(
$type
<=
Doctrine_Relation
::
ONE_COMPOSITE
)
{
// ONE-TO-ONE
if
(
$type
==
Doctrine_Relation
::
ONE_COMPOSITE
||
$type
==
Doctrine_Relation
::
ONE_AGGREGATE
)
{
if
(
!
isset
(
$local
))
if
(
!
isset
(
$local
))
$local
=
$objT
able
->
getIdentifier
();
$local
=
$t
able
->
getIdentifier
();
$foreignKey
=
new
Doctrine_LocalKey
(
$objTable
,
$e
[
1
]
,
$local
,
$type
);
$relation
=
new
Doctrine_LocalKey
(
$table
,
$foreign
,
$local
,
$type
);
}
else
}
else
throw
new
Doctrine_Mapping_Exception
();
throw
new
Doctrine_Mapping_Exception
();
break
;
default
:
if
(
in_array
(
$e
[
0
],
$this
->
parents
))
{
// ONE-TO-ONE
if
(
$type
<=
Doctrine_Relation
::
ONE_COMPOSITE
)
{
}
elseif
(
$component
==
$name
||
(
$component
==
$alias
&&
$name
==
$this
->
name
)
)
{
if
(
!
isset
(
$local
))
if
(
!
isset
(
$local
))
$local
=
$objTable
->
getIdentifier
();
$local
=
$this
->
identifier
;
// ONE-TO-MANY or ONE-TO-ONE
$relation
=
new
Doctrine_ForeignKey
(
$table
,
$local
,
$foreign
,
$type
);
$foreignKey
=
new
Doctrine_LocalKey
(
$objTable
,
$e
[
1
],
$local
,
$type
);
}
else
throw
new
Doctrine_Mapping_Exception
();
}
else
{
}
else
{
// POSSIBLY MANY-TO-MANY
// MANY-TO-MANY
// only aggregate relations allowed
if
(
$type
!=
Doctrine_Relation
::
MANY_AGGREGATE
)
throw
new
Doctrine_Mapping_Exception
();
$classes
=
array_merge
(
$this
->
parents
,
array
(
$this
->
name
));
$classes
=
array_merge
(
$this
->
parents
,
array
(
$this
->
name
));
foreach
(
$classes
as
$class
)
{
foreach
(
$classes
as
$class
)
{
try
{
try
{
$bound
=
$objT
able
->
getBound
(
$class
);
$bound
=
$t
able
->
getBound
(
$class
);
break
;
break
;
}
catch
(
InvalidKeyException
$exc
)
{
}
catch
(
InvalidKeyException
$exc
)
{
...
@@ -447,18 +439,18 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -447,18 +439,18 @@ class Doctrine_Table extends Doctrine_Configurable {
$e2
=
explode
(
"."
,
$bound
[
0
]);
$e2
=
explode
(
"."
,
$bound
[
0
]);
if
(
$e2
[
0
]
!=
$e
[
0
]
)
if
(
$e2
[
0
]
!=
$component
)
throw
new
Doctrine_Mapping_Exception
();
throw
new
Doctrine_Mapping_Exception
();
$associationTable
=
$this
->
session
->
getTable
(
$e2
[
0
]);
$associationTable
=
$this
->
session
->
getTable
(
$e2
[
0
]);
$this
->
foreignKeys
[
$e2
[
0
]]
=
new
Doctrine_ForeignKey
(
$associationTable
,
$local
,
$e2
[
1
],
Doctrine_Relation
::
MANY_COMPOSITE
);
$this
->
relations
[
$e2
[
0
]]
=
new
Doctrine_ForeignKey
(
$associationTable
,
$local
,
$e2
[
1
],
Doctrine_Relation
::
MANY_COMPOSITE
);
$relation
=
new
Doctrine_Association
(
$table
,
$associationTable
,
$e2
[
1
],
$foreign
,
$type
);
$foreignKey
=
new
Doctrine_Association
(
$objTable
,
$associationTable
,
$e2
[
1
],
$e
[
1
],
$type
);
}
}
endswitch
;
$this
->
relations
[
$alias
]
=
$relation
;
$this
->
foreignKeys
[
$name
]
=
$foreignKey
;
return
$this
->
relations
[
$alias
];
return
$this
->
foreignKeys
[
$name
];
}
else
{
}
else
{
throw
new
InvalidKeyException
();
throw
new
InvalidKeyException
();
}
}
...
...
classes/Validator.class.php
View file @
c9877af4
...
@@ -29,11 +29,14 @@ class Doctrine_Validator {
...
@@ -29,11 +29,14 @@ class Doctrine_Validator {
*/
*/
private
$stack
=
array
();
private
$stack
=
array
();
/**
/**
* @var array $validators
* @var array $validators
an array of validator objects
*/
*/
private
static
$validators
=
array
();
private
static
$validators
=
array
();
/**
/**
* returns a validator object
*
* @param string $name
* @param string $name
* @return Doctrine_Validator_Interface
*/
*/
public
static
function
getValidator
(
$name
)
{
public
static
function
getValidator
(
$name
)
{
if
(
!
isset
(
self
::
$validators
[
$name
]))
{
if
(
!
isset
(
self
::
$validators
[
$name
]))
{
...
@@ -48,6 +51,9 @@ class Doctrine_Validator {
...
@@ -48,6 +51,9 @@ class Doctrine_Validator {
return
self
::
$validators
[
$name
];
return
self
::
$validators
[
$name
];
}
}
/**
/**
* validates a given record and saves possible errors
* in Doctrine_Validator::$stack
*
* @param Doctrine_Record $record
* @param Doctrine_Record $record
* @return void
* @return void
*/
*/
...
@@ -101,12 +107,15 @@ class Doctrine_Validator {
...
@@ -101,12 +107,15 @@ class Doctrine_Validator {
}
}
/**
/**
* whether or not this validator has errors
* whether or not this validator has errors
*
* @return boolean
* @return boolean
*/
*/
public
function
hasErrors
()
{
public
function
hasErrors
()
{
return
(
count
(
$this
->
stack
)
>
0
);
return
(
count
(
$this
->
stack
)
>
0
);
}
}
/**
/**
* returns the error stack
*
* @return array
* @return array
*/
*/
public
function
getErrorStack
()
{
public
function
getErrorStack
()
{
...
@@ -114,7 +123,9 @@ class Doctrine_Validator {
...
@@ -114,7 +123,9 @@ class Doctrine_Validator {
}
}
/**
/**
* returns the type of loosely typed variable
* returns the type of loosely typed variable
*
* @param mixed $var
* @param mixed $var
* @return string
*/
*/
public
static
function
gettype
(
$var
)
{
public
static
function
gettype
(
$var
)
{
$type
=
gettype
(
$var
);
$type
=
gettype
(
$var
);
...
...
tests/RecordTestCase.class.php
View file @
c9877af4
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
require_once
(
"UnitTestCase.class.php"
);
require_once
(
"UnitTestCase.class.php"
);
class
Doctrine_RecordTestCase
extends
Doctrine_UnitTestCase
{
class
Doctrine_RecordTestCase
extends
Doctrine_UnitTestCase
{
public
function
testManyToManyTreeStructure
()
{
public
function
testManyToManyTreeStructure
()
{
$task
=
$this
->
session
->
create
(
"Task"
);
$task
=
$this
->
session
->
create
(
"Task"
);
...
@@ -14,20 +15,20 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
...
@@ -14,20 +15,20 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$task
=
new
Task
();
$task
=
new
Task
();
$this
->
assertTrue
(
$task
instanceof
Task
);
$this
->
assertTrue
(
$task
instanceof
Task
);
$this
->
assertEqual
(
$task
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertEqual
(
$task
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertTrue
(
$task
->
T
ask
[
0
]
instanceof
Task
);
$this
->
assertTrue
(
$task
->
Subt
ask
[
0
]
instanceof
Task
);
$this
->
assertEqual
(
$task
->
T
ask
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertEqual
(
$task
->
Subt
ask
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertTrue
(
$task
->
Resource
[
0
]
instanceof
Resource
);
$this
->
assertTrue
(
$task
->
Resource
[
0
]
instanceof
Resource
);
$this
->
assertEqual
(
$task
->
Resource
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertEqual
(
$task
->
Resource
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$task
->
name
=
"Task 1"
;
$task
->
name
=
"Task 1"
;
$task
->
Resource
[
0
]
->
name
=
"Resource 1"
;
$task
->
Resource
[
0
]
->
name
=
"Resource 1"
;
$task
->
T
ask
[
0
]
->
name
=
"Subtask 1"
;
$task
->
Subt
ask
[
0
]
->
name
=
"Subtask 1"
;
$this
->
assertEqual
(
$task
->
name
,
"Task 1"
);
$this
->
assertEqual
(
$task
->
name
,
"Task 1"
);
$this
->
assertEqual
(
$task
->
Resource
[
0
]
->
name
,
"Resource 1"
);
$this
->
assertEqual
(
$task
->
Resource
[
0
]
->
name
,
"Resource 1"
);
$this
->
assertEqual
(
$task
->
Resource
->
count
(),
1
);
$this
->
assertEqual
(
$task
->
Resource
->
count
(),
1
);
$this
->
assertEqual
(
$task
->
T
ask
[
0
]
->
name
,
"Subtask 1"
);
$this
->
assertEqual
(
$task
->
Subt
ask
[
0
]
->
name
,
"Subtask 1"
);
$this
->
session
->
flush
();
$this
->
session
->
flush
();
...
@@ -36,7 +37,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
...
@@ -36,7 +37,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$task
->
name
,
"Task 1"
);
$this
->
assertEqual
(
$task
->
name
,
"Task 1"
);
$this
->
assertEqual
(
$task
->
Resource
[
0
]
->
name
,
"Resource 1"
);
$this
->
assertEqual
(
$task
->
Resource
[
0
]
->
name
,
"Resource 1"
);
$this
->
assertEqual
(
$task
->
Resource
->
count
(),
1
);
$this
->
assertEqual
(
$task
->
Resource
->
count
(),
1
);
$this
->
assertEqual
(
$task
->
T
ask
[
0
]
->
name
,
"Subtask 1"
);
$this
->
assertEqual
(
$task
->
Subt
ask
[
0
]
->
name
,
"Subtask 1"
);
}
}
...
@@ -119,43 +120,53 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
...
@@ -119,43 +120,53 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
$user
->
getState
()
==
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertTrue
(
$user
->
getState
()
==
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertTrue
(
$user
->
name
,
"John Locke"
);
$this
->
assertTrue
(
$user
->
name
,
"John Locke"
);
}
}
public
function
testTreeStructure
()
{
public
function
testTreeStructure
()
{
$e
=
new
Element
();
$e
=
new
Element
();
$fk
=
$e
->
getTable
()
->
getForeignKey
(
"Child"
);
$this
->
assertTrue
(
$fk
instanceof
Doctrine_ForeignKey
);
$this
->
assertEqual
(
$fk
->
getType
(),
Doctrine_Relation
::
MANY_AGGREGATE
);
$this
->
assertEqual
(
$fk
->
getForeign
(),
"parent_id"
);
$this
->
assertEqual
(
$fk
->
getLocal
(),
"id"
);
$e
->
name
=
"parent"
;
$e
->
name
=
"parent"
;
$e
->
Element
[
0
]
->
name
=
"child 1"
;
$e
->
Child
[
0
]
->
name
=
"child 1"
;
$e
->
Element
[
1
]
->
name
=
"child 2"
;
$e
->
Child
[
1
]
->
name
=
"child 2"
;
$e
->
Element
[
1
]
->
Element
[
0
]
->
name
=
"child 1's child 1"
;
$e
->
Child
[
1
]
->
Child
[
0
]
->
name
=
"child 1's child 1"
;
$e
->
Element
[
1
]
->
Element
[
1
]
->
name
=
"child 1's child 1"
;
$e
->
Child
[
1
]
->
Child
[
1
]
->
name
=
"child 1's child 1"
;
$this
->
assertEqual
(
$e
->
name
,
"parent"
);
$this
->
assertEqual
(
$e
->
name
,
"parent"
);
$this
->
assertEqual
(
$e
->
Element
[
0
]
->
name
,
"child 1"
);
$this
->
assertEqual
(
$e
->
Element
[
1
]
->
name
,
"child 2"
);
$this
->
assertEqual
(
$e
->
Element
[
1
]
->
Element
[
0
]
->
name
,
"child 1's child 1"
);
$this
->
assertEqual
(
$e
->
Element
[
1
]
->
Element
[
1
]
->
name
,
"child 1's child 1"
);
$this
->
assertEqual
(
$e
->
Child
[
0
]
->
name
,
"child 1"
);
$this
->
session
->
flush
();
$this
->
assertEqual
(
$e
->
Child
[
1
]
->
name
,
"child 2"
);
$this
->
assertEqual
(
$e
->
Child
[
1
]
->
Child
[
0
]
->
name
,
"child 1's child 1"
);
$this
->
assertEqual
(
$e
->
Child
[
1
]
->
Child
[
1
]
->
name
,
"child 1's child 1"
);
$this
->
session
->
flush
();
$e
=
$e
->
getTable
()
->
find
(
1
);
$e
=
$e
->
getTable
()
->
find
(
1
);
$this
->
assertEqual
(
$e
->
name
,
"parent"
);
$this
->
assertEqual
(
$e
->
name
,
"parent"
);
$this
->
assertEqual
(
$e
->
Element
[
0
]
->
name
,
"child 1"
);
$this
->
assertEqual
(
$e
->
Child
[
0
]
->
name
,
"child 1"
);
$c
=
$e
->
getTable
()
->
find
(
2
);
$c
=
$e
->
getTable
()
->
find
(
2
);
$this
->
assertEqual
(
$c
->
name
,
"child 1"
);
$this
->
assertEqual
(
$c
->
name
,
"child 1"
);
$this
->
assertEqual
(
$e
->
Child
[
0
]
->
parent_id
,
1
);
$this
->
assertEqual
(
$e
->
Child
[
0
]
->
Parent
->
getID
(),
$e
->
getID
());
$this
->
assertEqual
(
$e
->
Element
[
0
]
->
parent_id
,
1
);
$this
->
assertEqual
(
$e
->
Child
[
1
]
->
parent_id
,
1
);
$this
->
assertEqual
(
$e
->
Element
[
1
]
->
parent_id
,
1
);
$this
->
assertEqual
(
$e
->
Child
[
1
]
->
Child
[
0
]
->
name
,
"child 1's child 1"
);
$this
->
assertEqual
(
$e
->
Element
[
1
]
->
Element
[
0
]
->
name
,
"child 1's child 1"
);
$this
->
assertEqual
(
$e
->
Child
[
1
]
->
Child
[
1
]
->
name
,
"child 1's child 1"
);
$this
->
assertEqual
(
$e
->
Element
[
1
]
->
Element
[
1
]
->
name
,
"child 1's child 1"
);
$this
->
assertEqual
(
$e
->
Child
[
1
]
->
Child
[
0
]
->
parent_id
,
3
);
$this
->
assertEqual
(
$e
->
Element
[
1
]
->
Element
[
0
]
->
parent_id
,
3
);
$this
->
assertEqual
(
$e
->
Child
[
1
]
->
Child
[
1
]
->
parent_id
,
3
);
$this
->
assertEqual
(
$e
->
Element
[
1
]
->
Element
[
1
]
->
parent_id
,
3
);
}
}
...
...
tests/TableTestCase.class.php
View file @
c9877af4
...
@@ -26,6 +26,8 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
...
@@ -26,6 +26,8 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
$fk
->
getType
()
==
Doctrine_Relation
::
MANY_COMPOSITE
);
$this
->
assertTrue
(
$fk
->
getType
()
==
Doctrine_Relation
::
MANY_COMPOSITE
);
$this
->
assertTrue
(
$fk
->
getLocal
()
==
$this
->
objTable
->
getIdentifier
());
$this
->
assertTrue
(
$fk
->
getLocal
()
==
$this
->
objTable
->
getIdentifier
());
$this
->
assertTrue
(
$fk
->
getForeign
()
==
"entity_id"
);
$this
->
assertTrue
(
$fk
->
getForeign
()
==
"entity_id"
);
}
}
public
function
testGetComponentName
()
{
public
function
testGetComponentName
()
{
$this
->
assertTrue
(
$this
->
objTable
->
getComponentName
()
==
"User"
);
$this
->
assertTrue
(
$this
->
objTable
->
getComponentName
()
==
"User"
);
...
...
tests/UnitTestCase.class.php
View file @
c9877af4
...
@@ -55,6 +55,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
...
@@ -55,6 +55,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
}
}
foreach
(
$tables
as
$name
)
{
foreach
(
$tables
as
$name
)
{
$name
=
ucwords
(
$name
);
$table
=
$this
->
session
->
getTable
(
$name
);
$table
=
$this
->
session
->
getTable
(
$name
);
$table
->
getCache
()
->
deleteAll
();
$table
->
getCache
()
->
deleteAll
();
}
}
...
...
tests/classes.php
View file @
c9877af4
...
@@ -97,7 +97,8 @@ class Element extends Doctrine_Record {
...
@@ -97,7 +97,8 @@ class Element extends Doctrine_Record {
$this
->
hasColumn
(
"parent_id"
,
"integer"
);
$this
->
hasColumn
(
"parent_id"
,
"integer"
);
}
}
public
function
setUp
()
{
public
function
setUp
()
{
$this
->
hasMany
(
"Element"
,
"Element.parent_id"
);
$this
->
hasMany
(
"Element as Child"
,
"Child.parent_id"
);
$this
->
hasOne
(
"Element as Parent"
,
"Element.parent_id"
);
}
}
}
}
class
Email
extends
Doctrine_Record
{
class
Email
extends
Doctrine_Record
{
...
@@ -128,7 +129,7 @@ class Song extends Doctrine_Record {
...
@@ -128,7 +129,7 @@ class Song extends Doctrine_Record {
class
Task
extends
Doctrine_Record
{
class
Task
extends
Doctrine_Record
{
public
function
setUp
()
{
public
function
setUp
()
{
$this
->
hasMany
(
"Resource"
,
"Assignment.resource_id"
);
$this
->
hasMany
(
"Resource"
,
"Assignment.resource_id"
);
$this
->
hasMany
(
"Task
"
,
"Task.parent_id"
);
$this
->
hasMany
(
"Task
as Subtask"
,
"Subtask.parent_id"
);
}
}
public
function
setTableDefinition
()
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
100
);
$this
->
hasColumn
(
"name"
,
"string"
,
100
);
...
...
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