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
e1fbae22
Commit
e1fbae22
authored
Jun 25, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EventListener method names updated
parent
628aac0e
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
306 additions
and
505 deletions
+306
-505
Connection.php
lib/Doctrine/Connection.php
+25
-23
Profiler.php
lib/Doctrine/Connection/Profiler.php
+1
-5
Statement.php
lib/Doctrine/Connection/Statement.php
+31
-22
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+4
-21
Event.php
lib/Doctrine/Event.php
+6
-4
EventListener.php
lib/Doctrine/EventListener.php
+22
-50
Chain.php
lib/Doctrine/EventListener/Chain.php
+49
-206
Interface.php
lib/Doctrine/EventListener/Interface.php
+20
-54
Manager.php
lib/Doctrine/Manager.php
+2
-2
Record.php
lib/Doctrine/Record.php
+0
-15
Transaction.php
lib/Doctrine/Transaction.php
+47
-42
ProfilerTestCase.php
tests/Connection/ProfilerTestCase.php
+15
-14
DBTestCase.php
tests/DBTestCase.php
+40
-37
HookTestCase.php
tests/Record/HookTestCase.php
+43
-9
classes.php
tests/classes.php
+1
-1
No files found.
lib/Doctrine/Connection.php
View file @
e1fbae22
...
...
@@ -64,10 +64,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* keys representing Doctrine_Table component names and values as Doctrine_Table objects
*/
protected
$tables
=
array
();
/**
* @var array $exported
*/
protected
$exported
=
array
();
/**
* @var string $driverName the name of this connection driver
*/
...
...
@@ -331,7 +327,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
CONNECT
);
$this
->
getListener
()
->
onP
reConnect
(
$event
);
$this
->
getListener
()
->
p
reConnect
(
$event
);
$e
=
explode
(
':'
,
$this
->
options
[
'dsn'
]);
$found
=
false
;
...
...
@@ -365,7 +361,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this
->
isConnected
=
true
;
$this
->
getListener
()
->
on
Connect
(
$event
);
$this
->
getListener
()
->
post
Connect
(
$event
);
return
true
;
}
...
...
@@ -676,13 +672,17 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{
$this
->
connect
();
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_
Db_
Event
::
PREPARE
,
$statement
);
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
PREPARE
,
$statement
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onP
rePrepare
(
$event
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
p
rePrepare
(
$event
);
$stmt
=
$this
->
dbh
->
prepare
(
$statement
);
$stmt
=
false
;
if
(
!
$event
->
skipOperation
)
{
$stmt
=
$this
->
dbh
->
prepare
(
$statement
);
}
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
on
Prepare
(
$event
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
post
Prepare
(
$event
);
return
new
Doctrine_Connection_Statement
(
$this
,
$stmt
);
}
...
...
@@ -750,7 +750,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*
* @return PDOStatement|Doctrine_Adapter_Statement
*/
public
function
execute
(
$query
,
array
$params
=
array
())
public
function
execute
(
$query
,
array
$params
=
array
())
{
$this
->
connect
();
...
...
@@ -760,15 +760,16 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$stmt
->
execute
(
$params
);
return
$stmt
;
}
else
{
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_E
VENT
::
QUERY
,
$query
,
$params
);
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_E
vent
::
QUERY
,
$query
,
$params
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onP
reQuery
(
$event
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
p
reQuery
(
$event
);
$stmt
=
$this
->
dbh
->
query
(
$query
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onQuery
(
$event
);
$this
->
_count
++
;
if
(
!
$event
->
skipOperation
)
{
$stmt
=
$this
->
dbh
->
query
(
$query
);
$this
->
_count
++
;
}
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
postQuery
(
$event
);
return
$stmt
;
}
...
...
@@ -796,13 +797,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
else
{
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_EVENT
::
EXEC
,
$query
,
$params
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onP
reExec
(
$event
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
p
reExec
(
$event
);
$count
=
$this
->
dbh
->
exec
(
$query
);
if
(
!
$event
->
skipOperation
)
{
$count
=
$this
->
dbh
->
exec
(
$query
);
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onExec
(
$event
)
;
$this
->
_count
++
;
$this
->
_count
++
;
}
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
postExec
(
$event
)
;
return
$count
;
}
...
...
lib/Doctrine/Connection/Profiler.php
View file @
e1fbae22
...
...
@@ -80,12 +80,8 @@ class Doctrine_Connection_Profiler implements Doctrine_Overloadable, IteratorAgg
throw
new
Doctrine_Connection_Profiler_Exception
(
"Couldn't listen event. Event should be an instance of Doctrine_Event."
);
}
// event methods should start with 'on'
if
(
substr
(
$m
,
0
,
2
)
!==
'on'
)
{
throw
new
Doctrine_Connection_Profiler_Exception
(
"Couldn't invoke listener :"
.
$m
);
}
if
(
substr
(
$m
,
2
,
3
)
===
'Pre'
&&
substr
(
$m
,
2
,
7
)
!==
'Prepa
re'
)
{
if
(
substr
(
$m
,
0
,
3
)
===
'p
re'
)
{
// pre-event listener found
$a
[
0
]
->
start
();
...
...
lib/Doctrine/Connection/Statement.php
View file @
e1fbae22
...
...
@@ -37,10 +37,10 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
* statement holds an instance of Doctrine_Connection
*/
protected
$_conn
;
/**
* @var mixed $_stmt PDOStatement object, boolean false or Doctrine_Adapter_Statement object
*/
protected
$_stmt
;
protected
$_executed
=
false
;
/**
* constructor
*
...
...
@@ -54,7 +54,7 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
$this
->
_stmt
=
$stmt
;
if
(
$stmt
===
false
)
{
throw
new
Doctrine_
Db_
Exception
(
'Unknown statement object given.'
);
throw
new
Doctrine_Exception
(
'Unknown statement object given.'
);
}
}
/**
...
...
@@ -215,14 +215,14 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
{
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
EXECUTE
,
$this
->
_stmt
->
queryString
,
$params
);
// print $this->_stmt->queryString . print_r($params, true) . "<br>";
$
skip
=
$this
->
_conn
->
getListener
()
->
onP
reExecute
(
$event
);
$
this
->
_conn
->
getListener
()
->
p
reExecute
(
$event
);
if
(
!
$
skip
)
{
if
(
!
$
event
->
skipOperation
)
{
$this
->
_stmt
->
execute
(
$params
);
$this
->
_conn
->
incrementQueryCount
();
}
$this
->
_conn
->
getListener
()
->
on
Execute
(
$event
);
$this
->
_conn
->
getListener
()
->
post
Execute
(
$event
);
return
$this
;
}
...
...
@@ -253,20 +253,23 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
*
* @return mixed
*/
public
function
fetch
(
$fetch
Styl
e
=
Doctrine
::
FETCH_BOTH
,
public
function
fetch
(
$fetch
Mod
e
=
Doctrine
::
FETCH_BOTH
,
$cursorOrientation
=
Doctrine
::
FETCH_ORI_NEXT
,
$cursorOffset
=
null
)
{
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Db_Event
::
FETCHALL
,
$this
->
_stmt
->
getQuery
(),
array
(
$fetchStyle
,
$cursorOrientation
,
$cursorOffset
));
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Event
::
FETCHALL
,
$this
->
_stmt
->
getQuery
());
$event
->
fetchMode
=
$fetchMode
;
$event
->
cursorOrientation
=
$cursorOrientation
;
$event
->
cursorOffset
=
$cursorOffset
;
$data
=
$this
->
_conn
->
getListener
()
->
onP
reFetch
(
$event
);
$data
=
$this
->
_conn
->
getListener
()
->
p
reFetch
(
$event
);
if
(
$data
===
null
)
{
$data
=
$this
->
_stmt
->
fetch
(
$fetch
Styl
e
,
$cursorOrientation
,
$cursorOffset
);
if
(
!
$event
->
skipOperation
)
{
$data
=
$this
->
_stmt
->
fetch
(
$fetch
Mod
e
,
$cursorOrientation
,
$cursorOffset
);
}
$this
->
_conn
->
getListener
()
->
on
Fetch
(
$event
);
$this
->
_conn
->
getListener
()
->
post
Fetch
(
$event
);
return
$data
;
}
...
...
@@ -274,29 +277,35 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
* fetchAll
* Returns an array containing all of the result set rows
*
*
* @param integer $fetchMode Controls how the next row will be returned to the caller.
* This value must be one of the Doctrine::FETCH_* constants,
* defaulting to Doctrine::FETCH_BOTH
*
* @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
* Doctrine::FETCH_COLUMN. Defaults to 0.
*
* @return array
*/
public
function
fetchAll
(
$fetch
Styl
e
=
Doctrine
::
FETCH_BOTH
,
public
function
fetchAll
(
$fetch
Mod
e
=
Doctrine
::
FETCH_BOTH
,
$columnIndex
=
null
)
{
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Db_Event
::
FETCHALL
,
$this
->
_stmt
->
getQuery
(),
array
(
$fetchStyle
,
$columnIndex
));
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Event
::
FETCHALL
,
$this
->
_stmt
->
getQuery
());
$event
->
fetchMode
=
$fetchMode
;
$event
->
columnIndex
=
$columnIndex
;
$
data
=
$this
->
_conn
->
getListener
()
->
onP
reFetchAll
(
$event
);
$
this
->
_conn
->
getListener
()
->
p
reFetchAll
(
$event
);
if
(
$data
===
null
)
{
if
(
!
$event
->
skipOperation
)
{
if
(
$columnIndex
!==
null
)
{
$data
=
$this
->
_stmt
->
fetchAll
(
$fetch
Styl
e
,
$columnIndex
);
$data
=
$this
->
_stmt
->
fetchAll
(
$fetch
Mod
e
,
$columnIndex
);
}
else
{
$data
=
$this
->
_stmt
->
fetchAll
(
$fetch
Styl
e
);
$data
=
$this
->
_stmt
->
fetchAll
(
$fetch
Mod
e
);
}
$event
->
data
=
$data
;
}
$this
->
_conn
->
getListener
()
->
on
FetchAll
(
$event
);
$this
->
_conn
->
getListener
()
->
post
FetchAll
(
$event
);
return
$data
;
}
...
...
lib/Doctrine/Connection/UnitOfWork.php
View file @
e1fbae22
...
...
@@ -139,13 +139,11 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
*/
public
function
save
(
Doctrine_Record
$record
)
{
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onPreSave
(
$record
);
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
SAVE
);
$record
->
preSave
(
$event
);
if
(
!
$event
->
getOption
(
'skipOperation'
)
)
{
if
(
!
$event
->
skipOperation
)
{
switch
(
$record
->
state
())
{
case
Doctrine_Record
::
STATE_TDIRTY
:
$this
->
insert
(
$record
);
...
...
@@ -162,8 +160,6 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
$record
->
postSave
(
$event
);
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onSave
(
$record
);
}
/**
* deletes this data access object and all the related composites
...
...
@@ -180,21 +176,17 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
$this
->
conn
->
beginTransaction
();
$record
->
getTable
()
->
getListener
()
->
onPreDelete
(
$record
);
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
DELETE
);
$record
->
preDelete
(
$event
);
$this
->
deleteComposites
(
$record
);
if
(
!
$event
->
getOption
(
'skipOperation'
)
)
{
if
(
!
$event
->
skipOperation
)
{
$this
->
conn
->
transaction
->
addDelete
(
$record
);
$record
->
state
(
Doctrine_Record
::
STATE_TCLEAN
);
}
$record
->
getTable
()
->
getListener
()
->
onDelete
(
$record
);
$record
->
postDelete
(
$event
);
$this
->
conn
->
commit
();
...
...
@@ -334,13 +326,11 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
*/
public
function
update
(
Doctrine_Record
$record
)
{
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onPreUpdate
(
$record
);
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
UPDATE
);
$record
->
preUpdate
(
$event
);
if
(
!
$event
->
getOption
(
'skipOperation'
)
)
{
if
(
!
$event
->
skipOperation
)
{
$array
=
$record
->
getPrepared
();
if
(
empty
(
$array
))
{
...
...
@@ -380,8 +370,6 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
$record
->
postUpdate
(
$event
);
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onUpdate
(
$record
);
return
true
;
}
/**
...
...
@@ -393,13 +381,11 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
public
function
insert
(
Doctrine_Record
$record
)
{
// listen the onPreInsert event
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onPreInsert
(
$record
);
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
INSERT
);
$record
->
preInsert
(
$event
);
if
(
!
$event
->
getOption
(
'skipOperation'
)
)
{
if
(
!
$event
->
skipOperation
)
{
$array
=
$record
->
getPrepared
();
if
(
empty
(
$array
))
{
...
...
@@ -440,9 +426,6 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
$record
->
postInsert
(
$event
);
// listen the onInsert event
$table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onInsert
(
$record
);
return
true
;
}
}
lib/Doctrine/Event.php
View file @
e1fbae22
...
...
@@ -144,7 +144,7 @@ class Doctrine_Event
* @param string $option the name of the option
* @return mixed
*/
public
function
getOption
(
$option
)
public
function
__get
(
$option
)
{
if
(
!
isset
(
$this
->
_options
[
$option
]))
{
return
null
;
...
...
@@ -155,13 +155,15 @@ class Doctrine_Event
/**
* skipOperation
* skips the next operation
* an alias for
setOption
('skipOperation', true)
* an alias for
__set
('skipOperation', true)
*
* @return Doctrine_Event this object
*/
public
function
skipOperation
()
{
return
$this
->
setOption
(
'skipOperation'
,
true
);
$this
->
_options
[
'skipOperation'
]
=
true
;
return
$this
;
}
/**
* setOption
...
...
@@ -171,7 +173,7 @@ class Doctrine_Event
* @param mixed $value the value of the given option
* @return Doctrine_Event this object
*/
public
function
setOption
(
$option
,
$value
)
public
function
__set
(
$option
,
$value
)
{
$this
->
_options
[
$option
]
=
$value
;
...
...
lib/Doctrine/EventListener.php
View file @
e1fbae22
...
...
@@ -45,31 +45,6 @@ class Doctrine_EventListener implements Doctrine_EventListener_Interface
public
function
onWakeUp
(
Doctrine_Record
$record
)
{
}
public
function
onUpdate
(
Doctrine_Record
$record
)
{
}
public
function
onPreUpdate
(
Doctrine_Record
$record
)
{
}
public
function
onCreate
(
Doctrine_Record
$record
)
{
}
public
function
onPreCreate
(
Doctrine_Record
$record
)
{
}
public
function
onSave
(
Doctrine_Record
$record
)
{
}
public
function
onPreSave
(
Doctrine_Record
$record
)
{
}
public
function
onInsert
(
Doctrine_Record
$record
)
{
}
public
function
onPreInsert
(
Doctrine_Record
$record
)
{
}
public
function
onDelete
(
Doctrine_Record
$record
)
{
}
public
function
onPreDelete
(
Doctrine_Record
$record
)
{
}
public
function
onEvict
(
Doctrine_Record
$record
)
{
}
public
function
onPreEvict
(
Doctrine_Record
$record
)
...
...
@@ -87,57 +62,54 @@ class Doctrine_EventListener implements Doctrine_EventListener_Interface
public
function
onOpen
(
Doctrine_Connection
$connection
)
{
}
public
function
onTransactionCommit
(
Doctrine_Event
$event
)
public
function
preTransactionCommit
(
Doctrine_Event
$event
)
{
}
public
function
onPre
TransactionCommit
(
Doctrine_Event
$event
)
public
function
post
TransactionCommit
(
Doctrine_Event
$event
)
{
}
public
function
on
TransactionRollback
(
Doctrine_Event
$event
)
public
function
pre
TransactionRollback
(
Doctrine_Event
$event
)
{
}
public
function
onPre
TransactionRollback
(
Doctrine_Event
$event
)
public
function
post
TransactionRollback
(
Doctrine_Event
$event
)
{
}
public
function
on
TransactionBegin
(
Doctrine_Event
$event
)
public
function
pre
TransactionBegin
(
Doctrine_Event
$event
)
{
}
public
function
onPre
TransactionBegin
(
Doctrine_Event
$event
)
public
function
post
TransactionBegin
(
Doctrine_Event
$event
)
{
}
public
function
on
Connect
(
Doctrine_Event
$event
)
public
function
post
Connect
(
Doctrine_Event
$event
)
{
}
public
function
onP
reConnect
(
Doctrine_Event
$event
)
public
function
p
reConnect
(
Doctrine_Event
$event
)
{
}
public
function
onPreQuery
(
Doctrine_Event
$event
)
public
function
preQuery
(
Doctrine_Event
$event
)
{
}
public
function
on
Query
(
Doctrine_Event
$event
)
public
function
post
Query
(
Doctrine_Event
$event
)
{
}
public
function
onP
rePrepare
(
Doctrine_Event
$event
)
public
function
p
rePrepare
(
Doctrine_Event
$event
)
{
}
public
function
on
Prepare
(
Doctrine_Event
$event
)
public
function
post
Prepare
(
Doctrine_Event
$event
)
{
}
public
function
onP
reExec
(
Doctrine_Event
$event
)
public
function
p
reExec
(
Doctrine_Event
$event
)
{
}
public
function
on
Exec
(
Doctrine_Event
$event
)
public
function
post
Exec
(
Doctrine_Event
$event
)
{
}
public
function
onP
reFetch
(
Doctrine_Event
$event
)
public
function
p
reFetch
(
Doctrine_Event
$event
)
{
}
public
function
on
Fetch
(
Doctrine_Event
$event
)
public
function
post
Fetch
(
Doctrine_Event
$event
)
{
}
public
function
onP
reFetchAll
(
Doctrine_Event
$event
)
public
function
p
reFetchAll
(
Doctrine_Event
$event
)
{
}
public
function
on
FetchAll
(
Doctrine_Event
$event
)
public
function
post
FetchAll
(
Doctrine_Event
$event
)
{
}
public
function
onP
reExecute
(
Doctrine_Event
$event
)
public
function
p
reExecute
(
Doctrine_Event
$event
)
{
}
public
function
on
Execute
(
Doctrine_Event
$event
)
public
function
post
Execute
(
Doctrine_Event
$event
)
{
}
}
lib/Doctrine/EventListener/Chain.php
View file @
e1fbae22
This diff is collapsed.
Click to expand it.
lib/Doctrine/EventListener/Interface.php
View file @
e1fbae22
...
...
@@ -34,67 +34,33 @@ Doctrine::autoload('Doctrine_EventListener_Interface');
*/
interface
Doctrine_EventListener_Interface
{
public
function
onLoad
(
Doctrine_Record
$record
);
public
function
onPreLoad
(
Doctrine_Record
$record
);
public
function
preTransactionCommit
(
Doctrine_Event
$event
);
public
function
postTransactionCommit
(
Doctrine_Event
$event
);
public
function
onSleep
(
Doctrine_Record
$record
);
public
function
onWakeUp
(
Doctrine_Record
$record
);
public
function
preTransactionRollback
(
Doctrine_Event
$event
);
public
function
postTransactionRollback
(
Doctrine_Event
$event
);
public
function
onUpdate
(
Doctrine_Record
$record
);
public
function
onPreUpdate
(
Doctrine_Record
$record
);
public
function
preTransactionBegin
(
Doctrine_Event
$event
);
public
function
postTransactionBegin
(
Doctrine_Event
$event
);
public
function
onCreate
(
Doctrine_Record
$record
);
public
function
onPreCreate
(
Doctrine_Record
$record
);
public
function
postConnect
(
Doctrine_Event
$event
);
public
function
preConnect
(
Doctrine_Event
$event
);
public
function
onSave
(
Doctrine_Record
$record
);
public
function
onPreSave
(
Doctrine_Record
$record
);
public
function
preQuery
(
Doctrine_Event
$event
);
public
function
postQuery
(
Doctrine_Event
$event
);
public
function
onInsert
(
Doctrine_Record
$record
);
public
function
onPreInsert
(
Doctrine_Record
$record
);
public
function
prePrepare
(
Doctrine_Event
$event
);
public
function
postPrepare
(
Doctrine_Event
$event
);
public
function
onDelete
(
Doctrine_Record
$record
);
public
function
onPreDelete
(
Doctrine_Record
$record
);
public
function
preExec
(
Doctrine_Event
$event
);
public
function
postExec
(
Doctrine_Event
$event
);
public
function
onEvict
(
Doctrine_Record
$record
);
public
function
onPreEvict
(
Doctrine_Record
$record
);
public
function
preFetch
(
Doctrine_Event
$event
);
public
function
postFetch
(
Doctrine_Event
$event
);
public
function
onClose
(
Doctrine_Event
$event
);
public
function
onPreClose
(
Doctrine_Event
$event
);
public
function
preFetchAll
(
Doctrine_Event
$event
);
public
function
postFetchAll
(
Doctrine_Event
$event
);
public
function
onCollectionDelete
(
Doctrine_Collection
$collection
);
public
function
onPreCollectionDelete
(
Doctrine_Collection
$collection
);
public
function
onOpen
(
Doctrine_Connection
$connection
);
public
function
onConnect
(
Doctrine_Event
$event
);
public
function
onPreConnect
(
Doctrine_Event
$event
);
public
function
onTransactionCommit
(
Doctrine_Event
$event
);
public
function
onPreTransactionCommit
(
Doctrine_Event
$event
);
public
function
onTransactionRollback
(
Doctrine_Event
$event
);
public
function
onPreTransactionRollback
(
Doctrine_Event
$event
);
public
function
onTransactionBegin
(
Doctrine_Event
$event
);
public
function
onPreTransactionBegin
(
Doctrine_Event
$event
);
public
function
onPreQuery
(
Doctrine_Event
$event
);
public
function
onQuery
(
Doctrine_Event
$event
);
public
function
onPrePrepare
(
Doctrine_Event
$event
);
public
function
onPrepare
(
Doctrine_Event
$event
);
public
function
onPreExec
(
Doctrine_Event
$event
);
public
function
onExec
(
Doctrine_Event
$event
);
public
function
onPreFetch
(
Doctrine_Event
$event
);
public
function
onFetch
(
Doctrine_Event
$event
);
public
function
onPreFetchAll
(
Doctrine_Event
$event
);
public
function
onFetchAll
(
Doctrine_Event
$event
);
public
function
onPreExecute
(
Doctrine_Event
$event
);
public
function
onExecute
(
Doctrine_Event
$event
);
public
function
preExecute
(
Doctrine_Event
$event
);
public
function
postExecute
(
Doctrine_Event
$event
);
}
lib/Doctrine/Manager.php
View file @
e1fbae22
...
...
@@ -322,7 +322,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
case
'mock'
:
case
'oracle'
:
if
(
!
isset
(
$parts
[
'path'
])
||
$parts
[
'path'
]
==
'/'
)
{
throw
new
Doctrine_
Db
_Exception
(
'No database availible in data source name'
);
throw
new
Doctrine_
Manager
_Exception
(
'No database availible in data source name'
);
}
if
(
isset
(
$parts
[
'path'
]))
{
$parts
[
'database'
]
=
substr
(
$parts
[
'path'
],
1
);
...
...
@@ -345,7 +345,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
}
break
;
default
:
throw
new
Doctrine_
Db
_Exception
(
'Unknown driver '
.
$parts
[
'scheme'
]);
throw
new
Doctrine_
Manager
_Exception
(
'Unknown driver '
.
$parts
[
'scheme'
]);
}
...
...
lib/Doctrine/Record.php
View file @
e1fbae22
...
...
@@ -157,14 +157,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$keys
=
$this
->
_table
->
getPrimaryKeys
();
if
(
!
$exists
)
{
// listen the onPreCreate event
$this
->
_table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onPreCreate
(
$this
);
}
else
{
// listen the onPreLoad event
$this
->
_table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onPreLoad
(
$this
);
}
// get the data array
$this
->
_data
=
$this
->
_table
->
getData
();
...
...
@@ -185,19 +177,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
// set the default values for this record
$this
->
assignDefaultValues
();
// listen the onCreate event
$this
->
_table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onCreate
(
$this
);
}
else
{
$this
->
_state
=
Doctrine_Record
::
STATE_CLEAN
;
if
(
$count
<
$this
->
_table
->
getColumnCount
())
{
$this
->
_state
=
Doctrine_Record
::
STATE_PROXY
;
}
// listen the onLoad event
$this
->
_table
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onLoad
(
$this
);
}
$this
->
_errorStack
=
new
Doctrine_Validator_ErrorStack
();
...
...
lib/Doctrine/Transaction.php
View file @
e1fbae22
...
...
@@ -224,7 +224,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
if
(
$this
->
transactionLevel
==
0
)
{
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
BEGIN
);
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onP
reTransactionBegin
(
$event
);
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
p
reTransactionBegin
(
$event
);
try
{
$this
->
conn
->
getDbh
()
->
beginTransaction
();
...
...
@@ -232,7 +232,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
throw
new
Doctrine_Transaction_Exception
(
$e
->
getMessage
());
}
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
on
TransactionBegin
(
$event
);
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
post
TransactionBegin
(
$event
);
}
}
...
...
@@ -246,7 +246,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
* progress or release a savepoint. This function may only be called when
* auto-committing is disabled, otherwise it will fail.
*
* Listeners:
onPreTransactionCommit, on
TransactionCommit
* Listeners:
preTransactionCommit, post
TransactionCommit
*
* @param string $savepoint name of a savepoint to release
* @throws Doctrine_Transaction_Exception if the transaction fails at database level
...
...
@@ -268,36 +268,39 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
}
else
{
if
(
$this
->
transactionLevel
==
1
)
{
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
COMMIT
);
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onPreTransactionCommit
(
$event
);
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
preTransactionCommit
(
$event
);
try
{
$this
->
bulkDelete
();
}
catch
(
Exception
$e
)
{
$this
->
rollback
();
throw
new
Doctrine_Transaction_Exception
(
$e
->
getMessage
());
}
if
(
!
empty
(
$this
->
invalid
))
{
$this
->
rollback
();
$tmp
=
$this
->
invalid
;
$this
->
invalid
=
array
();
throw
new
Doctrine_Validator_Exception
(
$tmp
);
}
// take snapshots of all collections used within this transaction
foreach
(
array_unique
(
$this
->
_collections
)
as
$coll
)
{
$coll
->
takeSnapshot
();
if
(
!
$event
->
skipOperation
)
{
try
{
$this
->
bulkDelete
();
}
catch
(
Exception
$e
)
{
$this
->
rollback
();
throw
new
Doctrine_Transaction_Exception
(
$e
->
getMessage
());
}
if
(
!
empty
(
$this
->
invalid
))
{
$this
->
rollback
();
$tmp
=
$this
->
invalid
;
$this
->
invalid
=
array
();
throw
new
Doctrine_Validator_Exception
(
$tmp
);
}
// take snapshots of all collections used within this transaction
foreach
(
array_unique
(
$this
->
_collections
)
as
$coll
)
{
$coll
->
takeSnapshot
();
}
$this
->
_collections
=
array
();
$this
->
conn
->
getDbh
()
->
commit
();
//$this->conn->unitOfWork->reset();
}
$this
->
_collections
=
array
();
$this
->
conn
->
getDbh
()
->
commit
();
//$this->conn->unitOfWork->reset();
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onTransactionCommit
(
$event
);
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
postTransactionCommit
(
$event
);
}
}
...
...
@@ -327,26 +330,28 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
return
false
;
}
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
ROLLBACK
);
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onPreTransactionRollback
(
$event
);
if
(
!
is_null
(
$savepoint
))
{
$this
->
transactionLevel
=
$this
->
removeSavePoints
(
$savepoint
);
$this
->
rollbackSavePoint
(
$savepoint
);
}
else
{
//$this->conn->unitOfWork->reset();
$this
->
deteles
=
array
();
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
ROLLBACK
);
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
preTransactionRollback
(
$event
);
if
(
!
$event
->
skipOperation
)
{
$this
->
deteles
=
array
();
$this
->
transactionLevel
=
0
;
try
{
$this
->
conn
->
getDbh
()
->
rollback
();
}
catch
(
Exception
$e
)
{
throw
new
Doctrine_Transaction_Exception
(
$e
->
getMessage
());
$this
->
transactionLevel
=
0
;
try
{
$this
->
conn
->
getDbh
()
->
rollback
();
}
catch
(
Exception
$e
)
{
throw
new
Doctrine_Transaction_Exception
(
$e
->
getMessage
());
}
}
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
postTransactionRollback
(
$event
);
}
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onTransactionRollback
(
$event
);
return
true
;
}
...
...
tests/Connection/ProfilerTestCase.php
View file @
e1fbae22
...
...
@@ -39,6 +39,7 @@ class Doctrine_Connection_Profiler_TestCase extends Doctrine_UnitTestCase
{}
public
function
setUp
()
{}
public
function
testQuery
()
{
$this
->
conn
=
Doctrine_Manager
::
getInstance
()
->
openConnection
(
array
(
'sqlite::memory:'
));
...
...
@@ -51,12 +52,12 @@ class Doctrine_Connection_Profiler_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'CREATE TABLE test (id INT)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_
Db_
Event
::
EXEC
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
EXEC
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
conn
->
count
(),
1
);
}
/**
public
function
testPrepareAndExecute
()
{
...
...
@@ -65,32 +66,32 @@ class Doctrine_Connection_Profiler_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$event
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_
Db_
Event::PREPARE);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
PREPARE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$stmt
->
execute
(
array
(
1
));
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_
Db_
Event::EXECUTE);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
EXECUTE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
conn
->
count
(),
2
);
}
*/
public
function
testMultiplePrepareAndExecute
()
{
$stmt
=
$this
->
conn
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_
Db_
Event
::
PREPARE
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
PREPARE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$stmt2
=
$this
->
conn
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_
Db_
Event
::
PREPARE
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
PREPARE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
/** TODO: strange errors here
$stmt->execute(array(1));
...
...
@@ -98,7 +99,7 @@ class Doctrine_Connection_Profiler_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_
Db_
Event::EXECUTE);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->conn->count(), 4);
...
...
@@ -117,12 +118,12 @@ class Doctrine_Connection_Profiler_TestCase extends Doctrine_UnitTestCase
}
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_
Db_
Event
::
EXECUTE
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
EXECUTE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_
Db_
Event
::
EXECUTE
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
EXECUTE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
}
public
function
testTransactionRollback
()
...
...
@@ -135,7 +136,7 @@ class Doctrine_Connection_Profiler_TestCase extends Doctrine_UnitTestCase
}
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
null
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_
Db_
Event
::
BEGIN
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
BEGIN
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
try
{
...
...
@@ -147,7 +148,7 @@ class Doctrine_Connection_Profiler_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
null
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_
Db_
Event
::
ROLLBACK
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
ROLLBACK
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
}
public
function
testTransactionCommit
()
...
...
@@ -160,7 +161,7 @@ class Doctrine_Connection_Profiler_TestCase extends Doctrine_UnitTestCase
}
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
null
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_
Db_
Event
::
BEGIN
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
BEGIN
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
try
{
...
...
@@ -173,7 +174,7 @@ class Doctrine_Connection_Profiler_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
null
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_
Db_
Event
::
COMMIT
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getCode
(),
Doctrine_Event
::
COMMIT
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
}
}
...
...
tests/DBTestCase.php
View file @
e1fbae22
...
...
@@ -110,33 +110,33 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
$listener
=
$this
->
dbh
->
getListener
();
$stmt
=
$this
->
dbh
->
prepare
(
'INSERT INTO entity (id) VALUES(?)'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
Prepare'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
rePrepare'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
Prepare'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
rePrepare'
);
$stmt
->
execute
(
array
(
1
));
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
Execute'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reExecute'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
Execute'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reExecute'
);
$this
->
dbh
->
exec
(
'DELETE FROM entity'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
Exec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reExec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
Exec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reExec'
);
$this
->
dbh
->
beginTransaction
();
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
TransactionBegin'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reTransactionBegin'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
TransactionBegin'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reTransactionBegin'
);
$this
->
dbh
->
exec
(
'INSERT INTO entity (id) VALUES (1)'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
Exec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reExec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
Exec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reExec'
);
$this
->
dbh
->
commit
();
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
TransactionCommit'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reTransactionCommit'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
TransactionCommit'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reTransactionCommit'
);
...
...
@@ -152,63 +152,66 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
$listener
=
$this
->
dbh
->
getListener
()
->
get
(
0
);
$listener2
=
$this
->
dbh
->
getListener
()
->
get
(
1
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
Exec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reExec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
Exec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reExec'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
on
Exec'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
onP
reExec'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
post
Exec'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
p
reExec'
);
}
public
function
testListeningPrepareEventsWithListenerChain
()
{
$stmt
=
$this
->
dbh
->
prepare
(
'INSERT INTO entity (id) VALUES(?)'
);
$listener
=
$this
->
dbh
->
getListener
()
->
get
(
0
);
$listener2
=
$this
->
dbh
->
getListener
()
->
get
(
1
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
Prepare'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
rePrepare'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
Prepare'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
rePrepare'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
on
Prepare'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
onP
rePrepare'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
post
Prepare'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
p
rePrepare'
);
$stmt
->
execute
(
array
(
1
));
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
Execute'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reExecute'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
Execute'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reExecute'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
on
Execute'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
onP
reExecute'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
post
Execute'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
p
reExecute'
);
}
public
function
testListeningExecEventsWithListenerChain
()
public
function
testListeningExecEventsWithListenerChain
()
{
$this
->
dbh
->
exec
(
'DELETE FROM entity'
);
$listener
=
$this
->
dbh
->
getListener
()
->
get
(
0
);
$listener2
=
$this
->
dbh
->
getListener
()
->
get
(
1
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
Exec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reExec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
Exec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reExec'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
on
Exec'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
onP
reExec'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
post
Exec'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
p
reExec'
);
}
public
function
testListeningTransactionEventsWithListenerChain
()
{
$this
->
dbh
->
beginTransaction
();
$listener
=
$this
->
dbh
->
getListener
()
->
get
(
0
);
$listener2
=
$this
->
dbh
->
getListener
()
->
get
(
1
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
TransactionBegin'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reTransactionBegin'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
TransactionBegin'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reTransactionBegin'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
on
TransactionBegin'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
onP
reTransactionBegin'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
post
TransactionBegin'
);
$this
->
assertEqual
(
$listener2
->
pop
(),
'
p
reTransactionBegin'
);
$this
->
dbh
->
exec
(
'INSERT INTO entity (id) VALUES (1)'
);
$this
->
dbh
->
commit
();
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
TransactionCommit'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reTransactionCommit'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
TransactionCommit'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reTransactionCommit'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
on
Exec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
onP
reExec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
post
Exec'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'
p
reExec'
);
$this
->
dbh
->
exec
(
'DROP TABLE entity'
);
}
...
...
tests/Record/HookTestCase.php
View file @
e1fbae22
...
...
@@ -36,7 +36,7 @@ class Doctrine_Record_Hook_TestCase extends Doctrine_UnitTestCase
{
}
public
function
prepareTables
()
{
$this
->
tables
=
array
(
'RecordHookTest'
);
$this
->
tables
=
array
(
'RecordHookTest'
,
'SoftDeleteTest'
);
parent
::
prepareTables
();
}
...
...
@@ -78,7 +78,41 @@ class Doctrine_Record_Hook_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$r
->
pop
(),
'postDelete'
);
$this
->
assertEqual
(
$r
->
pop
(),
'preDelete'
);
}
public
function
testSoftDelete
()
{
$r
=
new
SoftDeleteTest
();
$r
->
name
=
'something'
;
$r
->
save
();
$this
->
assertEqual
(
$r
->
name
,
'something'
);
$this
->
assertEqual
(
$r
->
deleted
,
null
);
$this
->
assertEqual
(
$r
->
getState
(),
Doctrine_Record
::
STATE_CLEAN
);
$r
->
delete
();
$this
->
assertEqual
(
$r
->
getState
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertEqual
(
$r
->
deleted
,
true
);
}
}
class
SoftDeleteTest
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'name'
,
'string'
,
null
,
array
(
'primary'
=>
true
));
$this
->
hasColumn
(
'deleted'
,
'boolean'
,
1
);
}
public
function
preDelete
(
$event
)
{
$event
->
skipOperation
();
}
public
function
postDelete
(
$event
)
{
$this
->
deleted
=
true
;
$this
->
save
();
}
}
class
RecordHookTest
extends
Doctrine_Record
{
protected
$_messages
=
array
();
...
...
@@ -87,35 +121,35 @@ class RecordHookTest extends Doctrine_Record
{
$this
->
hasColumn
(
'name'
,
'string'
,
null
,
array
(
'primary'
=>
true
));
}
public
function
preSave
()
public
function
preSave
(
$event
)
{
$this
->
_messages
[]
=
__FUNCTION__
;
}
public
function
postSave
()
public
function
postSave
(
$event
)
{
$this
->
_messages
[]
=
__FUNCTION__
;
}
public
function
preInsert
()
public
function
preInsert
(
$event
)
{
$this
->
_messages
[]
=
__FUNCTION__
;
}
public
function
postInsert
()
public
function
postInsert
(
$event
)
{
$this
->
_messages
[]
=
__FUNCTION__
;
}
public
function
preUpdate
()
public
function
preUpdate
(
$event
)
{
$this
->
_messages
[]
=
__FUNCTION__
;
}
public
function
postUpdate
()
public
function
postUpdate
(
$event
)
{
$this
->
_messages
[]
=
__FUNCTION__
;
}
public
function
preDelete
()
public
function
preDelete
(
$event
)
{
$this
->
_messages
[]
=
__FUNCTION__
;
}
public
function
postDelete
()
public
function
postDelete
(
$event
)
{
$this
->
_messages
[]
=
__FUNCTION__
;
}
...
...
tests/classes.php
View file @
e1fbae22
...
...
@@ -21,7 +21,7 @@ class Entity extends Doctrine_Record
$this
->
hasColumn
(
'created'
,
'integer'
,
11
);
$this
->
hasColumn
(
'updated'
,
'integer'
,
11
);
$this
->
hasColumn
(
'email_id'
,
'integer'
);
$this
->
option
(
'subclasses'
,
array
(
'User'
,
'Group'
));
$this
->
option
(
'subclasses'
,
array
(
'User'
,
'Group'
));
}
}
class
FieldNameTest
extends
Doctrine_Record
...
...
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