This commit is contained in:
parent
0bafdb6694
commit
78b06ef3ae
@ -48,11 +48,14 @@ class Doctrine_Db_Event
|
||||
|
||||
protected $endedMicrotime;
|
||||
|
||||
|
||||
public function __construct($invoker, $type, $query = null)
|
||||
{
|
||||
$this->invoker = $invoker;
|
||||
$this->type = $type;
|
||||
$this->query = $query;
|
||||
|
||||
|
||||
}
|
||||
public function getQuery()
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ Doctrine::autoload('Doctrine_Overloadable');
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_Db_Profiler implements Doctrine_Overloadable
|
||||
class Doctrine_Db_Profiler extends Doctrine_Access implements Doctrine_Overloadable, IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @param array $listeners an array containing all availible listeners
|
||||
@ -47,6 +47,21 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable
|
||||
* @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
|
||||
@ -55,7 +70,7 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable
|
||||
* @param string $m the name of the method
|
||||
* @param array $a method arguments
|
||||
* @see Doctrine_Db_EventListener
|
||||
* @return void
|
||||
* @return boolean
|
||||
*/
|
||||
public function __call($m, $a)
|
||||
{
|
||||
@ -64,21 +79,83 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable
|
||||
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.");
|
||||
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);
|
||||
}
|
||||
if (substr($m, 2, 3) === 'Pre' && in_array(strtolower(substr($m, 3)), $this->listeners)) {
|
||||
// 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();
|
||||
}
|
||||
|
||||
$this->events[] = $a[0];
|
||||
/**
|
||||
* 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)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
|
@ -217,18 +217,26 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
if ($found)
|
||||
break;
|
||||
|
||||
$e2 = explode(":",$option);
|
||||
$e2 = explode(':', $option);
|
||||
|
||||
switch (strtolower($e2[0])) {
|
||||
case "autoincrement":
|
||||
case 'autoincrement':
|
||||
case 'autoinc':
|
||||
$this->identifierType = Doctrine_Identifier::AUTO_INCREMENT;
|
||||
$found = true;
|
||||
break;
|
||||
case "seq":
|
||||
case 'seq':
|
||||
case 'sequence':
|
||||
$this->identifierType = Doctrine_Identifier::SEQUENCE;
|
||||
$found = true;
|
||||
|
||||
if($value) {
|
||||
$this->options['sequenceName'] = $value;
|
||||
} else {
|
||||
$this->options['sequenceName'] = $this->conn->getSequenceName($this->options['tableName']);
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
if ( ! isset($this->identifierType)) {
|
||||
$this->identifierType = Doctrine_Identifier::NORMAL;
|
||||
@ -332,16 +340,19 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
}
|
||||
/**
|
||||
* setColumn
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param integer $length
|
||||
* @param mixed $options
|
||||
* @throws Doctrine_Table_Exception if trying use wrongly typed parameter
|
||||
* @return void
|
||||
*/
|
||||
final public function setColumn($name, $type, $length = null, $options = array()) {
|
||||
if (is_string($options)) {
|
||||
$options = explode('|', $options);
|
||||
}
|
||||
|
||||
foreach ($options as $k => $option) {
|
||||
if (is_numeric($k)) {
|
||||
if ( ! empty($option)) {
|
||||
@ -355,6 +366,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
if ($length == null)
|
||||
$length = 2147483647;
|
||||
|
||||
if((string) (int) $length !== (string) $length) {
|
||||
throw new Doctrine_Table_Exception('Invalid argument given for column length');
|
||||
}
|
||||
|
||||
$this->columns[$name] = array($type, $length, $options);
|
||||
|
||||
if (isset($options['primary'])) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user