Commit 401c3fe9 authored by zYne's avatar zYne

--no commit message

--no commit message
parent 0a2b0735
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Db_EventListener');
/**
* Doctrine_Db_Cache
*
* @package Doctrine
* @subpackage Doctrine_Db
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Db_Cache extends Doctrine_Db_EventListener
{
protected $cache;
public function __construct(Doctrine_Cache $cache)
{
$this->cache = $cache;
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Db_Event
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Db_Event
{
/**
* EVENT CODE CONSTANTS
*/
const QUERY = 1;
const EXEC = 2;
const EXECUTE = 3;
const PREPARE = 4;
const BEGIN = 5;
const COMMIT = 6;
const ROLLBACK = 7;
const CONNECT = 8;
const FETCH = 9;
const FETCHALL = 10;
/**
* @var Doctrine_Db $invoker the handler which invoked this event
*/
protected $invoker;
/**
* @var string $query the sql query associated with this event (if any)
*/
protected $query;
/**
* @var string $params the parameters associated with the query (if any)
*/
protected $params;
/**
* @see Doctrine_Db_Event constants
* @var integer $code the event code
*/
protected $code;
/**
* @var integer $startedMicrotime the time point in which this event was started
*/
protected $startedMicrotime;
/**
* @var integer $endedMicrotime the time point in which this event was ended
*/
protected $endedMicrotime;
/**
* constructor
*
* @param Doctrine_Db $invoker the handler which invoked this event
* @param integer $code the event code
* @param string $query the sql query associated with this event (if any)
*/
public function __construct($invoker, $code, $query = null, $params = array())
{
$this->invoker = $invoker;
$this->code = $code;
$this->query = $query;
$this->params = $params;
}
/**
* getQuery
*
* @return string returns the query associated with this event (if any)
*/
public function getQuery()
{
return $this->query;
}
/**
* getName
* returns the name of this event
*
* @return string the name of this event
*/
public function getName()
{
switch ($this->code) {
case self::QUERY:
return 'query';
case self::EXEC:
return 'exec';
case self::EXECUTE:
return 'execute';
case self::PREPARE:
return 'prepare';
case self::BEGIN:
return 'begin';
case self::COMMIT:
return 'commit';
case self::ROLLBACK:
return 'rollback';
case self::CONNECT:
return 'connect';
}
}
/**
* getCode
*
* @return integer returns the code associated with this event
*/
public function getCode()
{
return $this->code;
}
/**
* start
* starts the internal timer of this event
*
* @return void
*/
public function start()
{
$this->startedMicrotime = microtime(true);
}
/**
* hasEnded
* whether or not this event has ended
*
* @return boolean
*/
public function hasEnded()
{
return ($this->endedMicrotime != null);
}
/**
* end
* ends the internal timer of this event
*
* @return void
*/
public function end()
{
$this->endedMicrotime = microtime(true);
}
/**
* getInvoker
* returns the handler that invoked this event
*
* @return Doctrine_Db the handler that invoked this event
*/
public function getInvoker()
{
return $this->invoker;
}
/**
* getParams
* returns the parameters of the query
*
* @return array parameters of the query
*/
public function getParams()
{
return $this->params;
}
/**
* Get the elapsed time (in microseconds) that the event ran. If the event has
* not yet ended, return false.
*
* @return mixed
*/
public function getElapsedSecs()
{
if (is_null($this->endedMicrotime)) {
return false;
}
return ($this->endedMicrotime - $this->startedMicrotime);
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Db_EventListener
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Db_EventListener implements Doctrine_Db_EventListener_Interface
{
public function onPreConnect(Doctrine_Db_Event $event)
{ }
public function onConnect(Doctrine_Db_Event $event)
{ }
public function onPreQuery(Doctrine_Db_Event $event)
{ }
public function onQuery(Doctrine_Db_Event $event)
{ }
public function onPrePrepare(Doctrine_Db_Event $event)
{ }
public function onPrepare(Doctrine_Db_Event $event)
{ }
public function onPreCommit(Doctrine_Db_Event $event)
{ }
public function onCommit(Doctrine_Db_Event $event)
{ }
public function onPreExec(Doctrine_Db_Event $event)
{ }
public function onExec(Doctrine_Db_Event $event)
{ }
public function onPreFetch(Doctrine_Db_Event $event)
{ }
public function onFetch(Doctrine_Db_Event $event)
{ }
public function onPreFetchAll(Doctrine_Db_Event $event)
{ }
public function onFetchAll(Doctrine_Db_Event $event)
{ }
public function onPreRollBack(Doctrine_Db_Event $event)
{ }
public function onRollBack(Doctrine_Db_Event $event)
{ }
public function onPreBeginTransaction(Doctrine_Db_Event $event)
{ }
public function onBeginTransaction(Doctrine_Db_Event $event)
{ }
public function onPreExecute(Doctrine_Db_Event $event)
{ }
public function onExecute(Doctrine_Db_Event $event)
{ }
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Access');
/**
* Doctrine_Db_EventListener
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrine_Overloadable
{
private $listeners = array();
/**
* add
* adds a listener to the chain of listeners
*
* @param object $listener
* @param string $name
* @return void
*/
public function add($listener, $name = null)
{
if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
&& ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't add eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
}
if ($name === null) {
$this->listeners[] = $listener;
} else {
$this->listeners[$name] = $listener;
}
}
public function get($name)
{
if ( ! isset($this->listeners[$name])) {
throw new Doctrine_Db_Exception("Unknown listener $name");
}
return $this->listeners[$name];
}
public function set($name, $listener)
{
if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
&& ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
}
$this->listeners[$name] = $listener;
}
/**
* method overloader
* delegates the event listening to the listener chain
*
* if listener returns a value that is not null it will be assigned as the
* chain return value
*
* @return mixed
*/
public function __call($m, $a)
{
$return = null;
foreach ($this->listeners as $listener) {
$tmp = $listener->$m($a[0]);
if ($tmp !== null) {
$return = $tmp;
}
}
return $return;
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Db_EventListener
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
interface Doctrine_Db_EventListener_Interface {
public function onPreConnect(Doctrine_Db_Event $event);
public function onConnect(Doctrine_Db_Event $event);
public function onPreQuery(Doctrine_Db_Event $event);
public function onQuery(Doctrine_Db_Event $event);
public function onPrePrepare(Doctrine_Db_Event $event);
public function onPrepare(Doctrine_Db_Event $event);
public function onPreExec(Doctrine_Db_Event $event);
public function onExec(Doctrine_Db_Event $event);
public function onPreFetch(Doctrine_Db_Event $event);
public function onFetch(Doctrine_Db_Event $event);
public function onPreFetchAll(Doctrine_Db_Event $event);
public function onFetchAll(Doctrine_Db_Event $event);
public function onPreCommit(Doctrine_Db_Event $event);
public function onCommit(Doctrine_Db_Event $event);
public function onPreRollBack(Doctrine_Db_Event $event);
public function onRollBack(Doctrine_Db_Event $event);
public function onPreBeginTransaction(Doctrine_Db_Event $event);
public function onBeginTransaction(Doctrine_Db_Event $event);
public function onPreExecute(Doctrine_Db_Event $event);
public function onExecute(Doctrine_Db_Event $event);
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Db_Exception
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Db_Exception extends Doctrine_Exception
{
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Db');
/**
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class Doctrine_Db_Mock extends Doctrine_Db
{
protected static $errorCodeMap = array(
1004 => Doctrine::ERR_CANNOT_CREATE,
1005 => Doctrine::ERR_CANNOT_CREATE,
1006 => Doctrine::ERR_CANNOT_CREATE,
1007 => Doctrine::ERR_ALREADY_EXISTS,
1008 => Doctrine::ERR_CANNOT_DROP,
1022 => Doctrine::ERR_ALREADY_EXISTS,
1044 => Doctrine::ERR_ACCESS_VIOLATION,
1046 => Doctrine::ERR_NODBSELECTED,
1048 => Doctrine::ERR_CONSTRAINT,
1049 => Doctrine::ERR_NOSUCHDB,
1050 => Doctrine::ERR_ALREADY_EXISTS,
1051 => Doctrine::ERR_NOSUCHTABLE,
1054 => Doctrine::ERR_NOSUCHFIELD,
1061 => Doctrine::ERR_ALREADY_EXISTS,
1062 => Doctrine::ERR_ALREADY_EXISTS,
1064 => Doctrine::ERR_SYNTAX,
1091 => Doctrine::ERR_NOT_FOUND,
1100 => Doctrine::ERR_NOT_LOCKED,
1136 => Doctrine::ERR_VALUE_COUNT_ON_ROW,
1142 => Doctrine::ERR_ACCESS_VIOLATION,
1146 => Doctrine::ERR_NOSUCHTABLE,
1216 => Doctrine::ERR_CONSTRAINT,
1217 => Doctrine::ERR_CONSTRAINT,
);
public function connect()
{
return true;
}
public function getAttribute($attribute)
{
if ($attribute == PDO::ATTR_DRIVER_NAME) {
return 'mock';
}
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Overloadable');
/**
* Doctrine_Db_Profiler
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Db_Profiler extends Doctrine_Access implements Doctrine_Overloadable, IteratorAggregate, Countable
{
/**
* @param array $listeners an array containing all availible listeners
*/
private $listeners = array('query',
'prepare',
'commit',
'rollback',
'connect',
'begintransaction',
'exec',
'execute',
);
/**
* @param array $events an array containing all listened events
*/
private $events = array();
/**
* constructor
*/
public function __construct() {
}
/**
* setFilterQueryType
*
* @param integer $filter
* @return boolean
*/
public function setFilterQueryType() {
}
/**
* method overloader
* this method is used for invoking different listeners, for the full
* list of availible listeners, see Doctrine_Db_EventListener
*
* @param string $m the name of the method
* @param array $a method arguments
* @see Doctrine_Db_EventListener
* @return boolean
*/
public function __call($m, $a)
{
// first argument should be an instance of Doctrine_Db_Event
if ( ! ($a[0] instanceof Doctrine_Db_Event)) {
throw new Doctrine_Db_Profiler_Exception("Couldn't listen event. Event should be an instance of Doctrine_Db_Event.");
}
// event methods should start with 'on'
if (substr($m, 0, 2) !== 'on') {
throw new Doctrine_Db_Profiler_Exception("Couldn't invoke listener :" . $m);
}
if (substr($m, 2, 3) === 'Pre' && substr($m, 2, 7) !== 'Prepare') {
if ( ! in_array(strtolower(substr($m, 5)), $this->listeners)) {
throw new Doctrine_Db_Profiler_Exception("Couldn't invoke listener :" . $m);
}
// pre-event listener found
$a[0]->start();
if( ! in_array($a[0], $this->events, true)) {
$this->events[] = $a[0];
}
} else {
if ( ! in_array(strtolower(substr($m, 2)), $this->listeners)) {
throw new Doctrine_Db_Profiler_Exception("Couldn't invoke listener :" . $m);
}
// after-event listener found
$a[0]->end();
}
/**
* If filtering by query type is enabled, only keep the query if
* it was one of the allowed types.
*/
if ( ! is_null($this->filterTypes)) {
if ( ! ($a[0]->getQueryType() & $this->_filterTypes)) {
}
}
}
/**
* get
*
* @param mixed $key
* @return Doctrine_Event
*/
public function get($key)
{
if (isset($this->events[$key])) {
return $this->events[$key];
}
return null;
}
/**
* getAll
* returns all profiled events as an array
*
* @return array all events in an array
*/
public function getAll()
{
return $this->events;
}
/**
* getIterator
* returns an iterator that iterates through the logged events
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->events);
}
/**
* count
*
* @return integer
*/
public function count()
{
return count($this->events);
}
/**
* pop the last event from the event stack
*
* @return Doctrine_Db_Event
*/
public function pop()
{
return array_pop($this->events);
}
/**
* Get the Doctrine_Db_Event object for the last query that was run, regardless if it has
* ended or not. If the event has not ended, it's end time will be Null.
*
* @return Doctrine_Db_Event
*/
public function lastEvent()
{
if (empty($this->events)) {
return false;
}
end($this->events);
return current($this->events);
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Db_Exception');
/**
* Doctrine_Db_Exception
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Db_Profiler_Exception extends Doctrine_Db_Exception
{ }
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Db_Profiler_Query
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Db_Profiler_Query
{
/**
* @var string SQL query string or user comment, set by $query argument in constructor.
*/
protected $query ='';
/**
* @var integer One of the Doctrine_Db_Profiler constants for query type, set by $queryType argument in constructor.
*/
protected $queryType = 0;
protected $prepareTime;
/**
* @var float|null Unix timestamp with microseconds when instantiated.
*/
protected $startedMicrotime;
/**
* Unix timestamp with microseconds when self::queryEnd() was called.
*
* @var null|integer
*/
protected $endedMicrotime;
/**
* Class constructor. A query is about to be started, save the query text ($query) and its
* type (one of the Doctrine_Db_Profiler::* constants).
*
* @param string $query
* @param int $queryType
*/
public function __construct($query, $prepareTime = null)
{
$this->query = $query;
if ($prepareTime !== null) {
$this->prepareTime = $prepareTime;
} else {
$this->startedMicrotime = microtime(true);
}
}
public function start()
{
$this->startedMicrotime = microtime(true);
}
/**
* The query has ended. Record the time so that the elapsed time can be determined later.
*
* @return bool
*/
public function end()
{
$this->endedMicrotime = microtime(true);
return true;
}
public function getPrepareTime()
{
return $this->prepareTime;
}
/**
* Has this query ended?
*
* @return bool
*/
public function hasEnded()
{
return ($this->endedMicrotime != null);
}
/**
* Get the original SQL text of the query.
*
* @return string
*/
public function getQuery()
{
return $this->query;
}
/**
* Get the type of this query (one of the Zend_Db_Profiler::* constants)
*
* @return int
*/
public function getQueryType()
{
return $this->queryType;
}
/**
* Get the elapsed time (in seconds) that the query ran. If the query has
* not yet ended, return false.
*
* @return mixed
*/
public function getElapsedSecs()
{
if (is_null($this->endedMicrotime) && ! $this->prepareTime) {
return false;
}
return ($this->prepareTime + ($this->endedMicrotime - $this->startedMicrotime));
}
}
This diff is collapsed.
......@@ -419,9 +419,20 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
} else {
$this->parts[$name] = $part;
}
return $this;
}
/**
* hasAliasDeclaration
* whether or not this object has a declaration for given component alias
*
* @param string $componentAlias the component alias the retrieve the declaration from
* @return boolean
*/
public function hasAliasDeclaration($componentAlias)
{
return isset($this->_aliasMap[$componentAlias]);
}
/**
* getAliasDeclaration
* get the declaration for given component alias
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment