5
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
* This software consists of voluntary contributions made by many individuals
18
* and is licensed under the LGPL. For more information, see
19
* <http://www.phpdoctrine.org>.
25
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
26
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
29
* @link www.phpdoctrine.org
36
* CONNECTION EVENT CODES
40
const CONN_PREPARE = 3;
41
const CONN_CONNECT = 4;
45
const STMT_EXECUTE = 10;
46
const STMT_FETCH = 11;
47
const STMT_FETCHALL = 12;
51
const TX_ROLLBACK = 33;
52
const SAVEPOINT_CREATE = 34;
53
const SAVEPOINT_ROLLBACK = 35;
54
const SAVEPOINT_COMMIT = 36;
61
const RECORD_DELETE = 21;
62
const RECORD_SAVE = 22;
63
const RECORD_UPDATE = 23;
64
const RECORD_INSERT = 24;
65
const RECORD_SERIALIZE = 25;
66
const RECORD_UNSERIALIZE = 26;
67
const RECORD_DQL_DELETE = 27;
68
const RECORD_DQL_SELECT = 28;
69
const RECORD_DQL_UPDATE = 29;
70
const RECORD_VALIDATE = 30;
73
* @var mixed $_invoker the handler which invoked this event
78
* @var string $_query the sql query associated with this event (if any)
83
* @var string $_params the parameters associated with the query (if any)
88
* @see Doctrine_Event constants
89
* @var integer $_code the event code
94
* @var integer $_startedMicrotime the time point in which this event was started
96
protected $_startedMicrotime;
99
* @var integer $_endedMicrotime the time point in which this event was ended
101
protected $_endedMicrotime;
104
* @var array $_options an array of options
106
protected $_options = array();
111
* @param Doctrine_Connection|Doctrine_Connection_Statement|
112
Doctrine_Connection_UnitOfWork|Doctrine_Transaction $invoker the handler which invoked this event
113
* @param integer $code the event code
114
* @param string $query the sql query associated with this event (if any)
116
public function __construct($invoker, $code, $query = null, $params = array())
118
$this->_invoker = $invoker;
119
$this->_code = $code;
120
$this->_query = $query;
121
$this->_params = $params;
127
* @return Doctrine_Query returns the query associated with this event (if any)
129
public function getQuery()
131
return $this->_query;
136
* returns the name of this event
138
* @return string the name of this event
140
public function getName()
142
switch ($this->_code) {
143
case self::CONN_QUERY:
145
case self::CONN_EXEC:
147
case self::CONN_PREPARE:
149
case self::CONN_CONNECT:
151
case self::CONN_CLOSE:
153
case self::CONN_ERROR:
156
case self::STMT_EXECUTE:
158
case self::STMT_FETCH:
160
case self::STMT_FETCHALL:
165
case self::TX_COMMIT:
167
case self::TX_ROLLBACK:
170
case self::SAVEPOINT_CREATE:
171
return 'create savepoint';
172
case self::SAVEPOINT_ROLLBACK:
173
return 'rollback savepoint';
174
case self::SAVEPOINT_COMMIT:
175
return 'commit savepoint';
177
case self::RECORD_DELETE:
178
return 'delete record';
179
case self::RECORD_SAVE:
180
return 'save record';
181
case self::RECORD_UPDATE:
182
return 'update record';
183
case self::RECORD_INSERT:
184
return 'insert record';
185
case self::RECORD_SERIALIZE:
186
return 'serialize record';
187
case self::RECORD_UNSERIALIZE:
188
return 'unserialize record';
189
case self::RECORD_DQL_SELECT:
190
return 'select records';
191
case self::RECORD_DQL_DELETE:
192
return 'delete records';
193
case self::RECORD_DQL_UPDATE:
194
return 'update records';
195
case self::RECORD_VALIDATE:
196
return 'validate record';
203
* @return integer returns the code associated with this event
205
public function getCode()
212
* returns the value of an option
214
* @param string $option the name of the option
217
public function __get($option)
219
if ( ! isset($this->_options[$option])) {
223
return $this->_options[$option];
228
* skips the next operation
229
* an alias for __set('skipOperation', true)
231
* @return Doctrine_Event this object
233
public function skipOperation()
235
$this->_options['skipOperation'] = true;
242
* sets the value of an option
244
* @param string $option the name of the option
245
* @param mixed $value the value of the given option
246
* @return Doctrine_Event this object
248
public function __set($option, $value)
250
$this->_options[$option] = $value;
257
* sets the value of an option by reference
259
* @param string $option the name of the option
260
* @param mixed $value the value of the given option
261
* @return Doctrine_Event this object
263
public function set($option, &$value)
265
$this->_options[$option] =& $value;
272
* starts the internal timer of this event
274
* @return Doctrine_Event this object
276
public function start()
278
$this->_startedMicrotime = microtime(true);
283
* whether or not this event has ended
287
public function hasEnded()
289
return ($this->_endedMicrotime != null);
294
* ends the internal timer of this event
296
* @return Doctrine_Event this object
298
public function end()
300
$this->_endedMicrotime = microtime(true);
307
* returns the handler that invoked this event
309
* @return Doctrine_Connection|Doctrine_Connection_Statement|
310
* Doctrine_Connection_UnitOfWork|Doctrine_Transaction the handler that invoked this event
312
public function getInvoker()
314
return $this->_invoker;
319
* Defines new invoker (used in Hydrator)
321
* @param mixed $invoker
324
public function setInvoker($invoker)
326
$this->_invoker = $invoker;
332
* returns the parameters of the query
334
* @return array parameters of the query
336
public function getParams()
338
return $this->_params;
342
* Get the elapsed time (in microseconds) that the event ran. If the event has
343
* not yet ended, return false.
347
public function getElapsedSecs()
349
if (is_null($this->_endedMicrotime)) {
352
return ($this->_endedMicrotime - $this->_startedMicrotime);