Commit 716bb65b authored by lsmith's avatar lsmith

- first round of PEAR CS fixes

parent f6400e01
...@@ -344,9 +344,9 @@ final class Doctrine { ...@@ -344,9 +344,9 @@ final class Doctrine {
* @return string * @return string
*/ */
public static function getPath() { public static function getPath() {
if(! self::$path) if (! self::$path) {
self::$path = dirname(__FILE__); self::$path = dirname(__FILE__);
}
return self::$path; return self::$path;
} }
/** /**
...@@ -358,7 +358,7 @@ final class Doctrine { ...@@ -358,7 +358,7 @@ final class Doctrine {
public static function loadAll() { public static function loadAll() {
$classes = Doctrine_Compiler::getRuntimeClasses(); $classes = Doctrine_Compiler::getRuntimeClasses();
foreach($classes as $class) { foreach ($classes as $class) {
Doctrine::autoload($class); Doctrine::autoload($class);
} }
} }
...@@ -400,17 +400,17 @@ final class Doctrine { ...@@ -400,17 +400,17 @@ final class Doctrine {
* @return boolean * @return boolean
*/ */
public static function autoload($classname) { public static function autoload($classname) {
if(class_exists($classname)) if (class_exists($classname)) {
return false; return false;
}
if(! self::$path) if (! self::$path) {
self::$path = dirname(__FILE__); self::$path = dirname(__FILE__);
}
$class = self::$path.DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR,$classname) . '.php'; $class = self::$path.DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR,$classname) . '.php';
if( ! file_exists($class)) if ( ! file_exists($class)) {
return false; return false;
}
require_once($class); require_once($class);
...@@ -441,7 +441,7 @@ final class Doctrine { ...@@ -441,7 +441,7 @@ final class Doctrine {
* @return boolean * @return boolean
*/ */
public static function isValidClassname($classname) { public static function isValidClassname($classname) {
if(preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname)) if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname))
return false; return false;
return true; return true;
......
...@@ -41,9 +41,9 @@ abstract class Doctrine_Access implements ArrayAccess { ...@@ -41,9 +41,9 @@ abstract class Doctrine_Access implements ArrayAccess {
* @return Doctrine_Access * @return Doctrine_Access
*/ */
public function setArray(array $array) { public function setArray(array $array) {
foreach($array as $k=>$v): foreach ($array as $k=>$v) {
$this->set($k,$v); $this->set($k,$v);
endforeach; };
return $this; return $this;
} }
...@@ -114,11 +114,12 @@ abstract class Doctrine_Access implements ArrayAccess { ...@@ -114,11 +114,12 @@ abstract class Doctrine_Access implements ArrayAccess {
* @return void * @return void
*/ */
public function offsetSet($offset, $value) { public function offsetSet($offset, $value) {
if( ! isset($offset)) { if ( ! isset($offset)) {
$this->add($value); $this->add($value);
} else } else {
$this->set($offset,$value); $this->set($offset,$value);
} }
}
/** /**
* unset a given offset * unset a given offset
* @see set, offsetSet, __set * @see set, offsetSet, __set
...@@ -128,4 +129,3 @@ abstract class Doctrine_Access implements ArrayAccess { ...@@ -128,4 +129,3 @@ abstract class Doctrine_Access implements ArrayAccess {
return $this->remove($offset); return $this->remove($offset);
} }
} }
...@@ -49,19 +49,17 @@ class Doctrine_Cache_Query_Sqlite implements Countable { ...@@ -49,19 +49,17 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
* @param Doctrine_Connection|null $connection * @param Doctrine_Connection|null $connection
*/ */
public function __construct($connection = null) { public function __construct($connection = null) {
if( ! ($connection instanceof Doctrine_Connection)) if ( ! ($connection instanceof Doctrine_Connection)) {
$connection = Doctrine_Manager::getInstance()->getCurrentConnection(); $connection = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->session = $connection; $this->session = $connection;
$dir = 'cache'; $dir = 'cache';
$this->path = $dir.DIRECTORY_SEPARATOR; $this->path = $dir.DIRECTORY_SEPARATOR;
$this->dbh = new PDO("sqlite::memory:"); $this->dbh = new PDO("sqlite::memory:");
try { try {
if($this->session->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true) if ($this->session->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true) {
{
$columns = array(); $columns = array();
$columns['query_md5'] = array('string', 32, 'notnull'); $columns['query_md5'] = array('string', 32, 'notnull');
$columns['query_result'] = array('array', 100000, 'notnull'); $columns['query_result'] = array('array', 100000, 'notnull');
......
This diff is collapsed.
...@@ -53,9 +53,9 @@ class Doctrine_Collection_Batch extends Doctrine_Collection { ...@@ -53,9 +53,9 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
*/ */
public function setBatchSize($batchSize) { public function setBatchSize($batchSize) {
$batchSize = (int) $batchSize; $batchSize = (int) $batchSize;
if($batchSize <= 0) if ($batchSize <= 0) {
return false; return false;
}
$this->batchSize = $batchSize; $this->batchSize = $batchSize;
return true; return true;
} }
...@@ -75,40 +75,39 @@ class Doctrine_Collection_Batch extends Doctrine_Collection { ...@@ -75,40 +75,39 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @return boolean whether or not the load operation was successful * @return boolean whether or not the load operation was successful
*/ */
public function load(Doctrine_Record $record) { public function load(Doctrine_Record $record) {
if(empty($this->data)) if (empty($this->data)) {
return false; return false;
}
$id = $record->obtainIdentifier(); $id = $record->obtainIdentifier();
$identifier = $this->table->getIdentifier(); $identifier = $this->table->getIdentifier();
foreach($this->data as $key => $v) { foreach ($this->data as $key => $v) {
if(is_object($v)) { if (is_object($v)) {
if($v->obtainIdentifier() == $id) if ($v->obtainIdentifier() == $id) {
break; break;
}
} elseif(is_array($v[$identifier])) { } elseif (is_array($v[$identifier])) {
if($v[$identifier] == $id) if ($v[$identifier] == $id) {
break; break;
} }
} }
}
$x = floor($key / $this->batchSize); $x = floor($key / $this->batchSize);
if( ! isset($this->loaded[$x])) { if ( ! isset($this->loaded[$x])) {
$e = $x * $this->batchSize; $e = $x * $this->batchSize;
$e2 = ($x + 1)* $this->batchSize; $e2 = ($x + 1)* $this->batchSize;
$a = array(); $a = array();
$proxies = array(); $proxies = array();
for($i = $e; $i < $e2 && $i < $this->count(); $i++): for ($i = $e; $i < $e2 && $i < $this->count(); $i++) {
if($this->data[$i] instanceof Doctrine_Record) if ($this->data[$i] instanceof Doctrine_Record) {
$id = $this->data[$i]->getIncremented(); $id = $this->data[$i]->getIncremented();
elseif(is_array($this->data[$i])) } elseif (is_array($this->data[$i])) {
$id = $this->data[$i][$identifier]; $id = $this->data[$i][$identifier];
}
$a[$i] = $id; $a[$i] = $id;
endfor; };
$c = count($a); $c = count($a);
...@@ -120,14 +119,14 @@ class Doctrine_Collection_Batch extends Doctrine_Collection { ...@@ -120,14 +119,14 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
$stmt = $this->table->getConnection()->execute($query,array_values($a)); $stmt = $this->table->getConnection()->execute($query,array_values($a));
foreach($a as $k => $id) { foreach ($a as $k => $id) {
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row === false) if ($row === false) {
break; break;
}
$this->table->setData($row); $this->table->setData($row);
if(is_object($this->data[$k])) { if (is_object($this->data[$k])) {
$this->data[$k]->factoryRefresh($this->table); $this->data[$k]->factoryRefresh($this->table);
} else { } else {
$this->data[$k] = $this->table->getRecord(); $this->data[$k] = $this->table->getRecord();
...@@ -148,8 +147,8 @@ class Doctrine_Collection_Batch extends Doctrine_Collection { ...@@ -148,8 +147,8 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @return object Doctrine_Record record * @return object Doctrine_Record record
*/ */
public function get($key) { public function get($key) {
if(isset($this->data[$key])) { if (isset($this->data[$key])) {
switch(gettype($this->data[$key])): switch (gettype($this->data[$key])) {
case "array": case "array":
// Doctrine_Record didn't exist in cache // Doctrine_Record didn't exist in cache
$this->table->setData($this->data[$key]); $this->table->setData($this->data[$key]);
...@@ -157,21 +156,18 @@ class Doctrine_Collection_Batch extends Doctrine_Collection { ...@@ -157,21 +156,18 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
$this->data[$key]->addCollection($this); $this->data[$key]->addCollection($this);
break; break;
endswitch; };
} else { } else {
$this->expand($key); $this->expand($key);
if( ! isset($this->data[$key])) if ( ! isset($this->data[$key])) {
$this->data[$key] = $this->table->create(); $this->data[$key] = $this->table->create();
}
} }
if (isset($this->reference_field)) {
if(isset($this->reference_field))
$this->data[$key]->set($this->reference_field, $this->reference, false); $this->data[$key]->set($this->reference_field, $this->reference, false);
}
return $this->data[$key]; return $this->data[$key];
} }
/** /**
...@@ -181,4 +177,3 @@ class Doctrine_Collection_Batch extends Doctrine_Collection { ...@@ -181,4 +177,3 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
return new Doctrine_Collection_Iterator_Expandable($this); return new Doctrine_Collection_Iterator_Expandable($this);
} }
} }
...@@ -18,4 +18,3 @@ class Doctrine_Collection_Immediate extends Doctrine_Collection { ...@@ -18,4 +18,3 @@ class Doctrine_Collection_Immediate extends Doctrine_Collection {
parent::__construct($table); parent::__construct($table);
} }
} }
...@@ -69,9 +69,10 @@ abstract class Doctrine_Collection_Iterator implements Iterator { ...@@ -69,9 +69,10 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
public function rewind() { public function rewind() {
$this->index = 0; $this->index = 0;
$i = $this->index; $i = $this->index;
if(isset($this->keys[$i])) if (isset($this->keys[$i])) {
$this->key = $this->keys[$i]; $this->key = $this->keys[$i];
} }
}
/** /**
* returns the current key * returns the current key
...@@ -97,10 +98,8 @@ abstract class Doctrine_Collection_Iterator implements Iterator { ...@@ -97,10 +98,8 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
public function next() { public function next() {
$this->index++; $this->index++;
$i = $this->index; $i = $this->index;
if(isset($this->keys[$i])) if (isset($this->keys[$i])) {
$this->key = $this->keys[$i]; $this->key = $this->keys[$i];
} }
}
} }
...@@ -32,15 +32,14 @@ Doctrine::autoload('Doctrine_Collection_Iterator'); ...@@ -32,15 +32,14 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
*/ */
class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterator { class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterator {
public function valid() { public function valid() {
if($this->index < $this->count) if ($this->index < $this->count) {
return true; return true;
elseif($this->index == $this->count) { } elseif ($this->index == $this->count) {
$coll = $this->collection->expand($this->index); $coll = $this->collection->expand($this->index);
if($coll instanceof Doctrine_Collection) { if ($coll instanceof Doctrine_Collection) {
$count = count($coll); $count = count($coll);
if($count > 0) { if ($count > 0) {
$this->keys = array_merge($this->keys, $coll->getKeys()); $this->keys = array_merge($this->keys, $coll->getKeys());
$this->count += $count; $this->count += $count;
return true; return true;
...@@ -51,4 +50,3 @@ class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterat ...@@ -51,4 +50,3 @@ class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterat
} }
} }
} }
...@@ -38,4 +38,3 @@ class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator { ...@@ -38,4 +38,3 @@ class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator {
return ($this->index < $this->count); return ($this->index < $this->count);
} }
} }
...@@ -33,5 +33,3 @@ Doctrine::autoload('Doctrine_Collection_Iterator'); ...@@ -33,5 +33,3 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
class Doctrine_Collection_Iterator_Offset extends Doctrine_Collection_Iterator { class Doctrine_Collection_Iterator_Offset extends Doctrine_Collection_Iterator {
public function valid() { } public function valid() { }
} }
...@@ -22,4 +22,3 @@ class Doctrine_Collection_Lazy extends Doctrine_Collection_Batch { ...@@ -22,4 +22,3 @@ class Doctrine_Collection_Lazy extends Doctrine_Collection_Batch {
parent::setBatchSize(1); parent::setBatchSize(1);
} }
} }
...@@ -56,4 +56,3 @@ class Doctrine_Collection_Offset extends Doctrine_Collection { ...@@ -56,4 +56,3 @@ class Doctrine_Collection_Offset extends Doctrine_Collection {
return new Doctrine_Collection_Iterator_Expandable($this); return new Doctrine_Collection_Iterator_Expandable($this);
} }
} }
...@@ -127,17 +127,17 @@ class Doctrine_Compiler { ...@@ -127,17 +127,17 @@ class Doctrine_Compiler {
$ret = array(); $ret = array();
foreach($classes as $class) { foreach ($classes as $class) {
if($class !== 'Doctrine') if ($class !== 'Doctrine')
$class = 'Doctrine_'.$class; $class = 'Doctrine_'.$class;
$file = $path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php"; $file = $path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php";
echo "Adding $file" . PHP_EOL; echo "Adding $file" . PHP_EOL;
if( ! file_exists($file)) if ( ! file_exists($file)) {
throw new Doctrine_Compiler_Exception("Couldn't compile $file. File $file does not exists."); throw new Doctrine_Compiler_Exception("Couldn't compile $file. File $file does not exists.");
}
Doctrine::autoload($class); Doctrine::autoload($class);
$refl = new ReflectionClass ( $class ); $refl = new ReflectionClass ( $class );
$lines = file( $file ); $lines = file( $file );
...@@ -160,9 +160,9 @@ class Doctrine_Compiler { ...@@ -160,9 +160,9 @@ class Doctrine_Compiler {
// that we can use php_strip_whitespace (which only works on files) // that we can use php_strip_whitespace (which only works on files)
$fp = @fopen($target, 'w'); $fp = @fopen($target, 'w');
if ($fp === false) if ($fp === false) {
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $target"); throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $target");
}
fwrite($fp, "<?php". fwrite($fp, "<?php".
" class InvalidKeyException extends Exception { }". " class InvalidKeyException extends Exception { }".
implode('', $ret) implode('', $ret)
...@@ -171,8 +171,9 @@ class Doctrine_Compiler { ...@@ -171,8 +171,9 @@ class Doctrine_Compiler {
$stripped = php_strip_whitespace($target); $stripped = php_strip_whitespace($target);
$fp = @fopen($target, 'w'); $fp = @fopen($target, 'w');
if ($fp === false) if ($fp === false) {
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $file"); throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $file");
}
fwrite($fp, $stripped); fwrite($fp, $stripped);
fclose($fp); fclose($fp);
} }
......
...@@ -61,29 +61,32 @@ abstract class Doctrine_Configurable { ...@@ -61,29 +61,32 @@ abstract class Doctrine_Configurable {
* @return void * @return void
*/ */
public function setAttribute($attribute,$value) { public function setAttribute($attribute,$value) {
switch($attribute): switch ($attribute) {
case Doctrine::ATTR_BATCH_SIZE: case Doctrine::ATTR_BATCH_SIZE:
if($value < 0) if ($value < 0) {
throw new Doctrine_Exception("Batch size should be greater than or equal to zero"); throw new Doctrine_Exception("Batch size should be greater than or equal to zero");
}
break; break;
case Doctrine::ATTR_FETCHMODE: case Doctrine::ATTR_FETCHMODE:
if($value < 0) if ($value < 0) {
throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants."); throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants.");
}
break; break;
case Doctrine::ATTR_LISTENER: case Doctrine::ATTR_LISTENER:
$this->setEventListener($value); $this->setEventListener($value);
break; break;
case Doctrine::ATTR_LOCKMODE: case Doctrine::ATTR_LOCKMODE:
if($this instanceof Doctrine_Connection) { if ($this instanceof Doctrine_Connection) {
if($this->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) if ($this->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) {
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open."); throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
}
} elseif($this instanceof Doctrine_Manager) { } elseif ($this instanceof Doctrine_Manager) {
foreach($this as $connection) { foreach ($this as $connection) {
if($connection->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) if ($connection->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) {
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open."); throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
} }
}
} else { } else {
throw new Doctrine_Exception("Lockmode attribute can only be set at the global or connection level."); throw new Doctrine_Exception("Lockmode attribute can only be set at the global or connection level.");
} }
...@@ -94,23 +97,23 @@ abstract class Doctrine_Configurable { ...@@ -94,23 +97,23 @@ abstract class Doctrine_Configurable {
case Doctrine::ATTR_ACCESSORS: case Doctrine::ATTR_ACCESSORS:
$accessors = array('none','get','set','both'); $accessors = array('none','get','set','both');
// if( ! in_array($value,$accessors)) // if ( ! in_array($value,$accessors)) {
// throw new Doctrine_Exception(); // throw new Doctrine_Exception();
// }
break; break;
case Doctrine::ATTR_COLL_LIMIT: case Doctrine::ATTR_COLL_LIMIT:
if($value < 1) { if ($value < 1) {
throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1."); throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1.");
} }
break; break;
case Doctrine::ATTR_COLL_KEY: case Doctrine::ATTR_COLL_KEY:
if( ! ($this instanceof Doctrine_Table)) if ( ! ($this instanceof Doctrine_Table)) {
throw new Doctrine_Exception("This attribute can only be set at table level."); throw new Doctrine_Exception("This attribute can only be set at table level.");
}
if( ! $this->hasColumn($value)) if ( ! $this->hasColumn($value)) {
throw new Doctrine_Exception("Couldn't set collection key attribute. No such column '$value'"); throw new Doctrine_Exception("Couldn't set collection key attribute. No such column '$value'");
}
break; break;
case Doctrine::ATTR_VLD: case Doctrine::ATTR_VLD:
case Doctrine::ATTR_AUTO_LENGTH_VLD: case Doctrine::ATTR_AUTO_LENGTH_VLD:
...@@ -124,24 +127,24 @@ abstract class Doctrine_Configurable { ...@@ -124,24 +127,24 @@ abstract class Doctrine_Configurable {
break; break;
case Doctrine::ATTR_SEQCOL_NAME: case Doctrine::ATTR_SEQCOL_NAME:
if( ! is_string($value)) if ( ! is_string($value)) {
throw new Doctrine_Exception('Sequence column name attribute only accepts string values'); throw new Doctrine_Exception('Sequence column name attribute only accepts string values');
}
break; break;
case Doctrine::ATTR_FIELD_CASE: case Doctrine::ATTR_FIELD_CASE:
if($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER) if ($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER)
throw new Doctrine_Exception('Field case attribute should be either 0, CASE_LOWER or CASE_UPPER constant.'); throw new Doctrine_Exception('Field case attribute should be either 0, CASE_LOWER or CASE_UPPER constant.');
break; break;
case Doctrine::ATTR_SEQNAME_FORMAT: case Doctrine::ATTR_SEQNAME_FORMAT:
case Doctrine::ATTR_IDXNAME_FORMAT: case Doctrine::ATTR_IDXNAME_FORMAT:
if($this instanceof Doctrine_Table) { if ($this instanceof Doctrine_Table) {
throw new Doctrine_Exception('Sequence / index name format attributes cannot be set' throw new Doctrine_Exception('Sequence / index name format attributes cannot be set'
. 'at table level (only at connection or global level).'); . 'at table level (only at connection or global level).');
} }
break; break;
default: default:
throw new Doctrine_Exception("Unknown attribute."); throw new Doctrine_Exception("Unknown attribute.");
endswitch; };
$this->attributes[$attribute] = $value; $this->attributes[$attribute] = $value;
...@@ -160,9 +163,9 @@ abstract class Doctrine_Configurable { ...@@ -160,9 +163,9 @@ abstract class Doctrine_Configurable {
* @return Doctrine_Db * @return Doctrine_Db
*/ */
public function addListener($listener, $name = null) { public function addListener($listener, $name = null) {
if( ! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) if ( ! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) {
$this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain(); $this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain();
}
$this->attributes[Doctrine::ATTR_LISTENER]->add($listener, $name); $this->attributes[Doctrine::ATTR_LISTENER]->add($listener, $name);
return $this; return $this;
...@@ -173,10 +176,10 @@ abstract class Doctrine_Configurable { ...@@ -173,10 +176,10 @@ abstract class Doctrine_Configurable {
* @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable * @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable
*/ */
public function getListener() { public function getListener() {
if( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) { if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
if(isset($this->parent)) if (isset($this->parent)) {
return $this->parent->getListener(); return $this->parent->getListener();
}
return null; return null;
} }
return $this->attributes[Doctrine::ATTR_LISTENER]; return $this->attributes[Doctrine::ATTR_LISTENER];
...@@ -188,10 +191,11 @@ abstract class Doctrine_Configurable { ...@@ -188,10 +191,11 @@ abstract class Doctrine_Configurable {
* @return Doctrine_Db * @return Doctrine_Db
*/ */
public function setListener($listener) { public function setListener($listener) {
if( ! ($listener instanceof Doctrine_EventListener_Interface) && if ( ! ($listener instanceof Doctrine_EventListener_Interface)
! ($listener instanceof Doctrine_Overloadable)) && ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable"); throw new Doctrine_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
}
$this->attributes[Doctrine::ATTR_LISTENER] = $listener; $this->attributes[Doctrine::ATTR_LISTENER] = $listener;
return $this; return $this;
...@@ -205,13 +209,13 @@ abstract class Doctrine_Configurable { ...@@ -205,13 +209,13 @@ abstract class Doctrine_Configurable {
public function getAttribute($attribute) { public function getAttribute($attribute) {
$attribute = (int) $attribute; $attribute = (int) $attribute;
if($attribute < 1 || $attribute > 23) if ($attribute < 1 || $attribute > 23)
throw new Doctrine_Exception('Unknown attribute.'); throw new Doctrine_Exception('Unknown attribute.');
if( ! isset($this->attributes[$attribute])) { if ( ! isset($this->attributes[$attribute])) {
if(isset($this->parent)) if (isset($this->parent)) {
return $this->parent->getAttribute($attribute); return $this->parent->getAttribute($attribute);
}
return null; return null;
} }
return $this->attributes[$attribute]; return $this->attributes[$attribute];
...@@ -245,4 +249,3 @@ abstract class Doctrine_Configurable { ...@@ -245,4 +249,3 @@ abstract class Doctrine_Configurable {
return $this->parent; return $this->parent;
} }
} }
This diff is collapsed.
...@@ -19,15 +19,14 @@ class Doctrine_Connection_Common extends Doctrine_Connection { ...@@ -19,15 +19,14 @@ class Doctrine_Connection_Common extends Doctrine_Connection {
* @param mixed $offset * @param mixed $offset
*/ */
public function modifyLimitQuery($query,$limit = false,$offset = false,$isManip=false) { public function modifyLimitQuery($query,$limit = false,$offset = false,$isManip=false) {
if($limit && $offset) { if ($limit && $offset) {
$query .= " LIMIT ".$limit." OFFSET ".$offset; $query .= " LIMIT ".$limit." OFFSET ".$offset;
} elseif($limit && ! $offset) { } elseif ($limit && ! $offset) {
$query .= " LIMIT ".$limit; $query .= " LIMIT ".$limit;
} elseif( ! $limit && $offset) { } elseif ( ! $limit && $offset) {
$query .= " LIMIT 999999999999 OFFSET ".$offset; $query .= " LIMIT 999999999999 OFFSET ".$offset;
} }
return $query; return $query;
} }
} }
...@@ -40,13 +40,12 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection { ...@@ -40,13 +40,12 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection {
* @return string the modified query * @return string the modified query
*/ */
public function modifyLimitQuery($query, $limit, $offset) { public function modifyLimitQuery($query, $limit, $offset) {
if($limit <= 0) if ($limit <= 0)
return $sql; return $sql;
if($offset == 0) { if ($offset == 0) {
return $sql . ' FETCH FIRST '. $count .' ROWS ONLY'; return $sql . ' FETCH FIRST '. $count .' ROWS ONLY';
} else { } else {
$sqlPieces = explode('from', $sql); $sqlPieces = explode('from', $sql);
$select = $sqlPieces[0]; $select = $sqlPieces[0];
$table = $sqlPieces[1]; $table = $sqlPieces[1];
......
...@@ -95,7 +95,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection { ...@@ -95,7 +95,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
* @return string modified query * @return string modified query
*/ */
public function modifyLimitQuery($query, $limit, $offset) { public function modifyLimitQuery($query, $limit, $offset) {
if($limit > 0) { if ($limit > 0) {
$query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i', $query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i',
"SELECT FIRST $limit SKIP $offset", $query); "SELECT FIRST $limit SKIP $offset", $query);
} }
...@@ -112,4 +112,3 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection { ...@@ -112,4 +112,3 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
return $data[0]; return $data[0];
} }
} }
...@@ -118,15 +118,15 @@ class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Excepti ...@@ -118,15 +118,15 @@ class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Excepti
} }
*/ */
foreach(self::$errorRegexps as $regexp => $code) { foreach (self::$errorRegexps as $regexp => $code) {
if (preg_match($regexp, $errorInfo[2])) { if (preg_match($regexp, $errorInfo[2])) {
$errorInfo[3] = $code; $errorInfo[3] = $code;
break; break;
} }
} }
if(isset(self::$errorCodeMap[$errorInfo[1]])) if (isset(self::$errorCodeMap[$errorInfo[1]])) {
$errorInfo[3] = self::$errorCodeMap[$errorInfo[1]]; $errorInfo[3] = self::$errorCodeMap[$errorInfo[1]];
}
return $errorInfo; return $errorInfo;
} }
} }
...@@ -44,9 +44,9 @@ class Doctrine_Connection_Module { ...@@ -44,9 +44,9 @@ class Doctrine_Connection_Module {
* module holds an instance of Doctrine_Connection * module holds an instance of Doctrine_Connection
*/ */
public function __construct($conn = null) { public function __construct($conn = null) {
if( ! ($conn instanceof Doctrine_Connection)) if ( ! ($conn instanceof Doctrine_Connection)) {
$conn = Doctrine_Manager::getInstance()->getCurrentConnection(); $conn = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->conn = $conn; $this->conn = $conn;
$e = explode('_', get_class($this)); $e = explode('_', get_class($this));
......
...@@ -104,13 +104,12 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection { ...@@ -104,13 +104,12 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
* @return string * @return string
*/ */
public function modifyLimitQuery($query, $limit, $offset, $isManip = false) { public function modifyLimitQuery($query, $limit, $offset, $isManip = false) {
if($limit > 0) { if ($limit > 0) {
// we need the starting SELECT clause for later // we need the starting SELECT clause for later
$select = 'SELECT '; $select = 'SELECT ';
if (preg_match('/^[[:space:]*SELECT[[:space:]]*DISTINCT/i', $query, $matches) == 1) if (preg_match('/^[[:space:]*SELECT[[:space:]]*DISTINCT/i', $query, $matches) == 1) {
$select .= 'DISTINCT '; $select .= 'DISTINCT ';
}
$length = strlen($select); $length = strlen($select);
// is there an offset? // is there an offset?
...@@ -168,4 +167,3 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection { ...@@ -168,4 +167,3 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
return $this->queryOne($query); return $this->queryOne($query);
} }
} }
...@@ -63,7 +63,7 @@ class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception ...@@ -63,7 +63,7 @@ class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception
*/ */
public function processErrorInfo(array $errorInfo) { public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1]; $code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) { if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code]; $this->portableCode = self::$errorCodeMap[$code];
return true; return true;
} }
......
...@@ -85,7 +85,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { ...@@ -85,7 +85,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$this->properties['varchar_max_length'] = 255; $this->properties['varchar_max_length'] = 255;
parent::__construct($manager, $adapter); parent::__construct($manager, $adapter);
} }
/** /**
...@@ -118,7 +117,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { ...@@ -118,7 +117,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$value = $this->dbh->lastInsertId(); $value = $this->dbh->lastInsertId();
if(is_numeric($value)) { if (is_numeric($value)) {
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value; $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
$result = $this->dbh->query($query); $result = $this->dbh->query($query);
} }
...@@ -205,17 +204,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { ...@@ -205,17 +204,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$query = $values = ''; $query = $values = '';
$keys = $colnum = 0; $keys = $colnum = 0;
for(reset($fields); $colnum < $count; next($fields), $colnum++) { for (reset($fields); $colnum < $count; next($fields), $colnum++) {
$name = key($fields); $name = key($fields);
if($colnum > 0) { if ($colnum > 0) {
$query .= ','; $query .= ',';
$values.= ','; $values.= ',';
} }
$query .= $name; $query .= $name;
if(isset($fields[$name]['null']) && $fields[$name]['null']) { if (isset($fields[$name]['null']) && $fields[$name]['null']) {
$value = 'NULL'; $value = 'NULL';
} else { } else {
$type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null; $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
...@@ -224,18 +223,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { ...@@ -224,18 +223,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$values .= $value; $values .= $value;
if(isset($fields[$name]['key']) && $fields[$name]['key']) { if (isset($fields[$name]['key']) && $fields[$name]['key']) {
if($value === 'NULL') if ($value === 'NULL') {
throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL'); throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL');
}
$keys++; $keys++;
} }
} }
if($keys == 0) if ($keys == 0) {
throw new Doctrine_Connection_Mysql_Exception('not specified which fields are keys'); throw new Doctrine_Connection_Mysql_Exception('not specified which fields are keys');
}
$query = 'REPLACE INTO ' . $table . ' (' . $query . ') VALUES (' . $values . ')'; $query = 'REPLACE INTO ' . $table . ' (' . $query . ') VALUES (' . $values . ')';
return $this->dbh->exec($query); return $this->dbh->exec($query);
......
...@@ -73,7 +73,7 @@ class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception ...@@ -73,7 +73,7 @@ class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception
*/ */
public function processErrorInfo(array $errorInfo) { public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1]; $code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) { if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code]; $this->portableCode = self::$errorCodeMap[$code];
return true; return true;
} }
......
...@@ -36,7 +36,6 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection { ...@@ -36,7 +36,6 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
*/ */
protected $driverName = 'Oracle'; protected $driverName = 'Oracle';
public function __construct(Doctrine_Manager $manager, $adapter) { public function __construct(Doctrine_Manager $manager, $adapter) {
$this->supported = array( $this->supported = array(
'sequences' => true, 'sequences' => true,
...@@ -127,4 +126,3 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection { ...@@ -127,4 +126,3 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
return $data[0]; return $data[0];
} }
} }
...@@ -68,7 +68,7 @@ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception ...@@ -68,7 +68,7 @@ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception
*/ */
public function processErrorInfo(array $errorInfo) { public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1]; $code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) { if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code]; $this->portableCode = self::$errorCodeMap[$code];
return true; return true;
} }
......
...@@ -132,10 +132,10 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { ...@@ -132,10 +132,10 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
. $from . ' ' . $where . ' LIMIT ' . $limit . ')'; . $from . ' ' . $where . ' LIMIT ' . $limit . ')';
} else { } else {
if($limit !== false) { if ($limit !== false) {
$query .= ' LIMIT ' . $limit; $query .= ' LIMIT ' . $limit;
} }
if($offset !== false) { if ($offset !== false) {
$query .= ' OFFSET ' . $offset; $query .= ' OFFSET ' . $offset;
} }
} }
...@@ -153,12 +153,12 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { ...@@ -153,12 +153,12 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
$serverInfo = $this->fetchOne($query); $serverInfo = $this->fetchOne($query);
if( ! $native) { if ( ! $native) {
$tmp = explode('.', $server_info, 3); $tmp = explode('.', $server_info, 3);
if(empty($tmp[2]) && isset($tmp[1]) if (empty($tmp[2]) && isset($tmp[1])
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)) { && preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)
) {
$serverInfo = array( $serverInfo = array(
'major' => $tmp[0], 'major' => $tmp[0],
'minor' => $tmp2[1], 'minor' => $tmp2[1],
......
...@@ -96,4 +96,3 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common { ...@@ -96,4 +96,3 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
return $data[0]; return $data[0];
} }
} }
...@@ -63,8 +63,8 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception ...@@ -63,8 +63,8 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception
* (the process is successfull if portable error code was found) * (the process is successfull if portable error code was found)
*/ */
public function processErrorInfo(array $errorInfo) { public function processErrorInfo(array $errorInfo) {
foreach(self::$errorRegexps as $regexp => $code) { foreach (self::$errorRegexps as $regexp => $code) {
if(preg_match($regexp, $errorInfo[2])) { if (preg_match($regexp, $errorInfo[2])) {
$this->portableCode = $code; $this->portableCode = $code;
return true; return true;
......
This diff is collapsed.
...@@ -54,7 +54,7 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict { ...@@ -54,7 +54,7 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration($field) { public function getNativeDeclaration($field) {
switch($field['type']) { switch ($field['type']) {
case 'varchar': case 'varchar':
case 'string': case 'string':
case 'array': case 'array':
...@@ -99,7 +99,7 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict { ...@@ -99,7 +99,7 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
public function getPortableDeclaration($field) { public function getPortableDeclaration($field) {
$length = $field['length']; $length = $field['length'];
if((int) $length <= 0) if ((int) $length <= 0)
$length = null; $length = null;
$type = array(); $type = array();
......
...@@ -102,5 +102,4 @@ class Doctrine_DataDict_Informix extends Doctrine_DataDict { ...@@ -102,5 +102,4 @@ class Doctrine_DataDict_Informix extends Doctrine_DataDict {
} }
return ''; return '';
} }
} }
...@@ -143,7 +143,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict { ...@@ -143,7 +143,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
case 'string': case 'string':
if ( ! isset($field['length'])) { if ( ! isset($field['length'])) {
if(array_key_exists('default', $field)) { if (array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length; $field['length'] = $this->conn->varchar_max_length;
} else { } else {
$field['length'] = false; $field['length'] = false;
......
...@@ -561,7 +561,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict { ...@@ -561,7 +561,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
} }
*/ */
if( ! empty($field['autoincrement'])) { if ( ! empty($field['autoincrement'])) {
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
return $name.' '.$this->getNativeDeclaration($field); return $name.' '.$this->getNativeDeclaration($field);
} }
......
...@@ -254,10 +254,10 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict { ...@@ -254,10 +254,10 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
$default = $autoinc = ''; $default = $autoinc = '';
$type = $this->getNativeDeclaration($field); $type = $this->getNativeDeclaration($field);
if(isset($field['autoincrement']) && $field['autoincrement']) { if (isset($field['autoincrement']) && $field['autoincrement']) {
$autoinc = ' PRIMARY KEY AUTOINCREMENT'; $autoinc = ' PRIMARY KEY AUTOINCREMENT';
$type = 'INTEGER'; $type = 'INTEGER';
} elseif(array_key_exists('default', $field)) { } elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') { if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0; $field['default'] = empty($field['notnull']) ? null : 0;
} }
......
...@@ -84,7 +84,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -84,7 +84,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
'sqlite2' => 'sqlite', 'sqlite2' => 'sqlite',
'sqlite3' => 'sqlite'); 'sqlite3' => 'sqlite');
/** /**
* constructor * constructor
* *
...@@ -93,7 +92,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -93,7 +92,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param string $pass database password * @param string $pass database password
*/ */
public function __construct($dsn, $user, $pass) { public function __construct($dsn, $user, $pass) {
if( ! isset($user)) { if ( ! isset($user)) {
$a = self::parseDSN($dsn); $a = self::parseDSN($dsn);
extract($a); extract($a);
...@@ -104,7 +103,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -104,7 +103,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this->listener = new Doctrine_Db_EventListener(); $this->listener = new Doctrine_Db_EventListener();
} }
public function nextQuerySequence() { public function nextQuerySequence() {
return ++$this->querySequence; return ++$this->querySequence;
} }
...@@ -121,9 +119,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -121,9 +119,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
return $this->dbh; return $this->dbh;
} }
public function getOption($name) { public function getOption($name) {
if( ! array_key_exists($name, $this->options)) if ( ! array_key_exists($name, $this->options)) {
throw new Doctrine_Db_Exception('Unknown option ' . $name); throw new Doctrine_Db_Exception('Unknown option ' . $name);
}
return $this->options[$name]; return $this->options[$name];
} }
/** /**
...@@ -133,9 +131,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -133,9 +131,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return Doctrine_Db * @return Doctrine_Db
*/ */
public function addListener($listener, $name = null) { public function addListener($listener, $name = null) {
if( ! ($this->listener instanceof Doctrine_Db_EventListener_Chain)) if ( ! ($this->listener instanceof Doctrine_Db_EventListener_Chain)) {
$this->listener = new Doctrine_Db_EventListener_Chain(); $this->listener = new Doctrine_Db_EventListener_Chain();
}
$this->listener->add($listener, $name); $this->listener->add($listener, $name);
return $this; return $this;
...@@ -155,10 +153,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -155,10 +153,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return Doctrine_Db * @return Doctrine_Db
*/ */
public function setListener($listener) { public function setListener($listener) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) && if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
! ($listener instanceof Doctrine_Overloadable)) && ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't set eventlistener for database handler. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable"); throw new Doctrine_Db_Exception("Couldn't set eventlistener for database handler. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
}
$this->listener = $listener; $this->listener = $listener;
return $this; return $this;
...@@ -171,7 +170,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -171,7 +170,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return boolean * @return boolean
*/ */
public function connect() { public function connect() {
if($this->isConnected) if ($this->isConnected)
return false; return false;
$this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']); $this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']);
...@@ -201,9 +200,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -201,9 +200,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return string * @return string
*/ */
public static function driverName($name) { public static function driverName($name) {
if(isset(self::$driverMap[$name])) if (isset(self::$driverMap[$name])) {
return self::$driverMap[$name]; return self::$driverMap[$name];
}
return $name; return $name;
} }
/** /**
...@@ -218,24 +217,25 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -218,24 +217,25 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$names = array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'); $names = array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment');
foreach($names as $name) { foreach ($names as $name) {
if( ! isset($parts[$name])) if ( ! isset($parts[$name])) {
$parts[$name] = null; $parts[$name] = null;
} }
}
if(count($parts) == 0 || ! isset($parts['scheme'])) if (count($parts) == 0 || ! isset($parts['scheme'])) {
throw new Doctrine_Db_Exception('Empty data source name'); throw new Doctrine_Db_Exception('Empty data source name');
}
$drivers = self::getAvailableDrivers(); $drivers = self::getAvailableDrivers();
$parts['scheme'] = self::driverName($parts['scheme']); $parts['scheme'] = self::driverName($parts['scheme']);
if( ! in_array($parts['scheme'], $drivers)) if ( ! in_array($parts['scheme'], $drivers)) {
throw new Doctrine_Db_Exception('Driver '.$parts['scheme'].' not availible or extension not loaded'); throw new Doctrine_Db_Exception('Driver '.$parts['scheme'].' not availible or extension not loaded');
}
switch($parts['scheme']) { switch ($parts['scheme']) {
case 'sqlite': case 'sqlite':
if(isset($parts['host']) && $parts['host'] == ':memory') { if (isset($parts['host']) && $parts['host'] == ':memory') {
$parts['database'] = ':memory:'; $parts['database'] = ':memory:';
$parts['dsn'] = 'sqlite::memory:'; $parts['dsn'] = 'sqlite::memory:';
} }
...@@ -248,15 +248,15 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -248,15 +248,15 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
case 'firebird': case 'firebird':
case 'pgsql': case 'pgsql':
case 'odbc': case 'odbc':
if( ! isset($parts['path']) || $parts['path'] == '/') if ( ! isset($parts['path']) || $parts['path'] == '/') {
throw new Doctrine_Db_Exception('No database availible in data source name'); throw new Doctrine_Db_Exception('No database availible in data source name');
}
if(isset($parts['path'])) if (isset($parts['path'])) {
$parts['database'] = substr($parts['path'], 1); $parts['database'] = substr($parts['path'], 1);
}
if( ! isset($parts['host'])) if ( ! isset($parts['host'])) {
throw new Doctrine_Db_Exception('No hostname set in data source name'); throw new Doctrine_Db_Exception('No hostname set in data source name');
}
$parts['dsn'] = $parts["scheme"].":host=".$parts["host"].";dbname=".$parts["database"]; $parts['dsn'] = $parts["scheme"].":host=".$parts["host"].";dbname=".$parts["database"];
break; break;
default: default:
...@@ -327,11 +327,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -327,11 +327,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this->listener->onPreQuery($event); $this->listener->onPreQuery($event);
if( ! empty($params)) if ( ! empty($params)) {
$stmt = $this->dbh->query($statement)->execute($params); $stmt = $this->dbh->query($statement)->execute($params);
else } else {
$stmt = $this->dbh->query($statement); $stmt = $this->dbh->query($statement);
}
$this->listener->onQuery($event); $this->listener->onQuery($event);
$this->querySequence++; $this->querySequence++;
...@@ -468,7 +468,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte ...@@ -468,7 +468,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return ArrayIterator * @return ArrayIterator
*/ */
public function getIterator() { public function getIterator() {
if($this->listener instanceof Doctrine_Db_Profiler) if ($this->listener instanceof Doctrine_Db_Profiler)
return $this->listener; return $this->listener;
} }
/** /**
......
...@@ -78,9 +78,9 @@ class Doctrine_Db_Event { ...@@ -78,9 +78,9 @@ class Doctrine_Db_Event {
* @return mixed * @return mixed
*/ */
public function getElapsedSecs() { public function getElapsedSecs() {
if (is_null($this->endedMicrotime)) if (is_null($this->endedMicrotime)) {
return false; return false;
}
return ($this->endedMicrotime - $this->startedMicrotime); return ($this->endedMicrotime - $this->startedMicrotime);
} }
......
...@@ -35,104 +35,107 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin ...@@ -35,104 +35,107 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin
private $listeners = array(); private $listeners = array();
public function add($listener, $name = null) { public function add($listener, $name = null) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) && if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
! ($listener instanceof Doctrine_Overloadable)) && ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't add eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or 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) if ($name === null) {
$this->listeners[] = $listener; $this->listeners[] = $listener;
else } else {
$this->listeners[$name] = $listener; $this->listeners[$name] = $listener;
} }
}
public function get($name) { public function get($name) {
if( ! isset($this->listeners[$name])) if ( ! isset($this->listeners[$name])) {
throw new Doctrine_Db_Exception("Unknown listener $name"); throw new Doctrine_Db_Exception("Unknown listener $name");
}
return $this->listeners[$name]; return $this->listeners[$name];
} }
public function set($name, $listener) { public function set($name, $listener) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) && if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
! ($listener instanceof Doctrine_Overloadable)) && ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or 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; $this->listeners[$name] = $listener;
} }
public function onQuery(Doctrine_Db_Event $event) { public function onQuery(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onQuery($event); $listener->onQuery($event);
} }
} }
public function onPreQuery(Doctrine_Db_Event $event) { public function onPreQuery(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreQuery($event); $listener->onPreQuery($event);
} }
} }
public function onPreExec(Doctrine_Db_Event $event) { public function onPreExec(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreExec($event); $listener->onPreExec($event);
} }
} }
public function onExec(Doctrine_Db_Event $event) { public function onExec(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onExec($event); $listener->onExec($event);
} }
} }
public function onPrePrepare(Doctrine_Db_Event $event) { public function onPrePrepare(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPrePrepare($event); $listener->onPrePrepare($event);
} }
} }
public function onPrepare(Doctrine_Db_Event $event) { public function onPrepare(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPrepare($event); $listener->onPrepare($event);
} }
} }
public function onPreCommit(Doctrine_Db_Event $event) { public function onPreCommit(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreCommit($event); $listener->onPreCommit($event);
} }
} }
public function onCommit(Doctrine_Db_Event $event) { public function onCommit(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onCommit($event); $listener->onCommit($event);
} }
} }
public function onPreRollBack(Doctrine_Db_Event $event) { public function onPreRollBack(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreRollBack($event); $listener->onPreRollBack($event);
} }
} }
public function onRollBack(Doctrine_Db_Event $event) { public function onRollBack(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onRollBack($event); $listener->onRollBack($event);
} }
} }
public function onPreBeginTransaction(Doctrine_Db_Event $event) { public function onPreBeginTransaction(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreBeginTransaction($event); $listener->onPreBeginTransaction($event);
} }
} }
public function onBeginTransaction(Doctrine_Db_Event $event) { public function onBeginTransaction(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onBeginTransaction($event); $listener->onBeginTransaction($event);
} }
} }
public function onPreExecute(Doctrine_Db_Event $event) { public function onPreExecute(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreExecute($event); $listener->onPreExecute($event);
} }
} }
public function onExecute(Doctrine_Db_Event $event) { public function onExecute(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onExecute($event); $listener->onExecute($event);
} }
} }
......
...@@ -62,7 +62,8 @@ class Doctrine_Db_Mock extends Doctrine_Db { ...@@ -62,7 +62,8 @@ class Doctrine_Db_Mock extends Doctrine_Db {
public function getAttribute($attribute) public function getAttribute($attribute)
{ {
if($attribute == PDO::ATTR_DRIVER_NAME) if ($attribute == PDO::ATTR_DRIVER_NAME) {
return 'mock'; return 'mock';
} }
}
} }
...@@ -58,14 +58,15 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable { ...@@ -58,14 +58,15 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable {
*/ */
public function __call($m, $a) { public function __call($m, $a) {
// first argument should be an instance of Doctrine_Db_Event // first argument should be an instance of Doctrine_Db_Event
if( ! ($a[0] instanceof 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."); 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' // event methods should start with 'on'
if(substr($m, 0, 2) !== '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' && in_array(strtolower(substr($m, 3)), $this->listeners)) { if (substr($m, 2, 3) === 'Pre' && in_array(strtolower(substr($m, 3)), $this->listeners)) {
// pre-event listener found // pre-event listener found
$a[0]->start(); $a[0]->start();
} else { } else {
...@@ -76,7 +77,6 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable { ...@@ -76,7 +77,6 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable {
$this->events[] = $a[0]; $this->events[] = $a[0];
} }
/** /**
* Get the Doctrine_Db_Event object for the last query that was run, regardless if it has * 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. * ended or not. If the event has not ended, it's end time will be Null.
......
...@@ -39,7 +39,6 @@ class Doctrine_Db_Profiler_Query { ...@@ -39,7 +39,6 @@ class Doctrine_Db_Profiler_Query {
*/ */
protected $queryType = 0; protected $queryType = 0;
protected $prepareTime; protected $prepareTime;
/** /**
...@@ -54,7 +53,6 @@ class Doctrine_Db_Profiler_Query { ...@@ -54,7 +53,6 @@ class Doctrine_Db_Profiler_Query {
*/ */
protected $endedMicrotime; protected $endedMicrotime;
/** /**
* Class constructor. A query is about to be started, save the query text ($query) and its * Class constructor. A query is about to be started, save the query text ($query) and its
* type (one of the Zend_Db_Profiler::* constants). * type (one of the Zend_Db_Profiler::* constants).
...@@ -64,7 +62,7 @@ class Doctrine_Db_Profiler_Query { ...@@ -64,7 +62,7 @@ class Doctrine_Db_Profiler_Query {
*/ */
public function __construct($query, $prepareTime = null) { public function __construct($query, $prepareTime = null) {
$this->query = $query; $this->query = $query;
if($prepareTime !== null) { if ($prepareTime !== null) {
$this->prepareTime = $prepareTime; $this->prepareTime = $prepareTime;
} else { } else {
$this->startedMicrotime = microtime(true); $this->startedMicrotime = microtime(true);
...@@ -96,7 +94,6 @@ class Doctrine_Db_Profiler_Query { ...@@ -96,7 +94,6 @@ class Doctrine_Db_Profiler_Query {
return ($this->endedMicrotime != null); return ($this->endedMicrotime != null);
} }
/** /**
* Get the original SQL text of the query. * Get the original SQL text of the query.
* *
...@@ -106,7 +103,6 @@ class Doctrine_Db_Profiler_Query { ...@@ -106,7 +103,6 @@ class Doctrine_Db_Profiler_Query {
return $this->query; return $this->query;
} }
/** /**
* Get the type of this query (one of the Zend_Db_Profiler::* constants) * Get the type of this query (one of the Zend_Db_Profiler::* constants)
* *
...@@ -129,4 +125,3 @@ class Doctrine_Db_Profiler_Query { ...@@ -129,4 +125,3 @@ class Doctrine_Db_Profiler_Query {
return ($this->prepareTime + ($this->endedMicrotime - $this->startedMicrotime)); return ($this->prepareTime + ($this->endedMicrotime - $this->startedMicrotime));
} }
} }
...@@ -53,7 +53,7 @@ class Doctrine_Db_Statement extends PDOStatement { ...@@ -53,7 +53,7 @@ class Doctrine_Db_Statement extends PDOStatement {
return $this->queryString; return $this->queryString;
} }
public function isExecuted($executed = null) { public function isExecuted($executed = null) {
if($executed === null) if ($executed === null)
return $this->executed; return $this->executed;
$this->executed = (bool) $executed; $this->executed = (bool) $executed;
...@@ -68,8 +68,6 @@ class Doctrine_Db_Statement extends PDOStatement { ...@@ -68,8 +68,6 @@ class Doctrine_Db_Statement extends PDOStatement {
$this->dbh->getListener()->onExecute($event); $this->dbh->getListener()->onExecute($event);
return $this; return $this;
} }
} }
This diff is collapsed.
...@@ -52,7 +52,6 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener { ...@@ -52,7 +52,6 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
return $this->debug; return $this->debug;
} }
public function onLoad(Doctrine_Record $record) { public function onLoad(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_LOAD); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_LOAD);
} }
...@@ -149,4 +148,3 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener { ...@@ -149,4 +148,3 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
$this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_PRECOLLDELETE); $this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_PRECOLLDELETE);
} }
} }
...@@ -10,4 +10,3 @@ ...@@ -10,4 +10,3 @@
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_EventListener_Empty extends Doctrine_EventListener { } class Doctrine_EventListener_Empty extends Doctrine_EventListener { }
...@@ -130,9 +130,9 @@ class Doctrine_Export extends Doctrine_Connection_Module { ...@@ -130,9 +130,9 @@ class Doctrine_Export extends Doctrine_Connection_Module {
if ( ! $name) if ( ! $name)
throw new Doctrine_Export_Exception('no valid table name specified'); throw new Doctrine_Export_Exception('no valid table name specified');
if (empty($fields)) if (empty($fields)) {
throw new Doctrine_Export_Exception('no fields specified for table '.$name); throw new Doctrine_Export_Exception('no fields specified for table '.$name);
}
$queryFields = $this->getFieldDeclarationList($fields); $queryFields = $this->getFieldDeclarationList($fields);
if (!empty($options['primary'])) { if (!empty($options['primary'])) {
...@@ -522,8 +522,8 @@ class Doctrine_Export extends Doctrine_Connection_Module { ...@@ -522,8 +522,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
public function getDeclaration($name, array $field) { public function getDeclaration($name, array $field) {
$default = ''; $default = '';
if(isset($field['default'])) { if (isset($field['default'])) {
if($field['default'] === '') { if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) $field['default'] = empty($field['notnull'])
? null : $this->valid_default_values[$field['type']]; ? null : $this->valid_default_values[$field['type']];
if ($field['default'] === '' if ($field['default'] === ''
...@@ -537,7 +537,7 @@ class Doctrine_Export extends Doctrine_Connection_Module { ...@@ -537,7 +537,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
} }
/** /**
TODO: is this really needed for portability? TODO: is this really needed for portability?
elseif(empty($field['notnull'])) { elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL'; $default = ' DEFAULT NULL';
} }
*/ */
...@@ -552,11 +552,11 @@ class Doctrine_Export extends Doctrine_Connection_Module { ...@@ -552,11 +552,11 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$method = 'get' . $field['type'] . 'Declaration'; $method = 'get' . $field['type'] . 'Declaration';
if(method_exists($this->conn->dataDict, $method)) if (method_exists($this->conn->dataDict, $method)) {
return $this->conn->dataDict->$method($name, $field); return $this->conn->dataDict->$method($name, $field);
else } else {
$dec = $this->conn->dataDict->getNativeDeclaration($field); $dec = $this->conn->dataDict->getNativeDeclaration($field);
}
return $this->conn->quoteIdentifier($name, true) . ' ' . $dec . $charset . $default . $notnull . $collation; return $this->conn->quoteIdentifier($name, true) . ' ' . $dec . $charset . $default . $notnull . $collation;
} }
/** /**
...@@ -594,39 +594,40 @@ class Doctrine_Export extends Doctrine_Connection_Module { ...@@ -594,39 +594,40 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, true); $conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, true);
foreach(get_declared_classes() as $name) { foreach (get_declared_classes() as $name) {
$class = new ReflectionClass($name); $class = new ReflectionClass($name);
if($class->isSubclassOf($parent) && ! $class->isAbstract()) if ($class->isSubclassOf($parent) && ! $class->isAbstract()) {
$obj = new $class(); $obj = new $class();
} }
}
$conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, $old); $conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, $old);
} }
public function export($record) { public function export($record) {
if( ! $record instanceof Doctrine_Record) if ( ! $record instanceof Doctrine_Record)
$record = new $record(); $record = new $record();
$table = $record->getTable(); $table = $record->getTable();
$reporter = new Doctrine_Reporter(); $reporter = new Doctrine_Reporter();
if( ! Doctrine::isValidClassname($table->getComponentName())) { if ( ! Doctrine::isValidClassname($table->getComponentName())) {
$reporter->add(E_WARNING, 'Badly named class.'); $reporter->add(E_WARNING, 'Badly named class.');
} }
try { try {
$columns = array(); $columns = array();
foreach($table->getColumns() as $name => $column) { foreach ($table->getColumns() as $name => $column) {
$definition = $column[2]; $definition = $column[2];
$definition['type'] = $column[0]; $definition['type'] = $column[0];
$definition['length'] = $column[1]; $definition['length'] = $column[1];
if($definition['type'] == 'enum' && isset($definition['default'])) if ($definition['type'] == 'enum' && isset($definition['default'])) {
$definition['default'] = $table->enumIndex($name, $definition['default']); $definition['default'] = $table->enumIndex($name, $definition['default']);
}
if($definition['type'] == 'boolean' && isset($definition['default'])) if ($definition['type'] == 'boolean' && isset($definition['default'])) {
$definition['default'] = (int) $definition['default']; $definition['default'] = (int) $definition['default'];
}
$columns[$name] = $definition; $columns[$name] = $definition;
} }
......
...@@ -158,8 +158,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export { ...@@ -158,8 +158,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
parent::createTable($name, $fields, $options); parent::createTable($name, $fields, $options);
// TODO ? $this->_silentCommit(); // TODO ? $this->_silentCommit();
foreach($fields as $field_name => $field) { foreach ($fields as $field_name => $field) {
if( ! empty($field['autoincrement'])) { if ( ! empty($field['autoincrement'])) {
//create PK constraint //create PK constraint
$pk_definition = array( $pk_definition = array(
'fields' => array($field_name => array()), 'fields' => array($field_name => array()),
......
...@@ -209,7 +209,6 @@ class Doctrine_Export_Mssql extends Doctrine_Export { ...@@ -209,7 +209,6 @@ class Doctrine_Export_Mssql extends Doctrine_Export {
return true; return true;
} }
$query = 'SET IDENTITY_INSERT $sequence_name ON ' . $query = 'SET IDENTITY_INSERT $sequence_name ON ' .
'INSERT INTO $sequence_name (' . $seqcol_name . ') VALUES ( ' . $start . ')'; 'INSERT INTO $sequence_name (' . $seqcol_name . ') VALUES ( ' . $start . ')';
$res = $db->exec($query); $res = $db->exec($query);
......
...@@ -90,29 +90,28 @@ class Doctrine_Export_Mysql extends Doctrine_Export { ...@@ -90,29 +90,28 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return void * @return void
*/ */
public function createTable($name, array $fields, array $options = array()) { public function createTable($name, array $fields, array $options = array()) {
if( ! $name) if ( ! $name)
throw new Doctrine_Export_Mysql_Exception('no valid table name specified'); throw new Doctrine_Export_Mysql_Exception('no valid table name specified');
if(empty($fields)) if (empty($fields)) {
throw new Doctrine_Export_Mysql_Exception('no fields specified for table "'.$name.'"'); throw new Doctrine_Export_Mysql_Exception('no fields specified for table "'.$name.'"');
}
$query_fields = $this->getFieldDeclarationList($fields); $query_fields = $this->getFieldDeclarationList($fields);
if( ! empty($options['primary'])) if ( ! empty($options['primary'])) {
$query_fields.= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')'; $query_fields.= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')';
}
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
$query = 'CREATE TABLE ' . $name . ' (' . $query_fields . ')'; $query = 'CREATE TABLE ' . $name . ' (' . $query_fields . ')';
$optionStrings = array(); $optionStrings = array();
if(isset($options['comment'])) if (isset($options['comment'])) {
$optionStrings['comment'] = 'COMMENT = '.$this->dbh->quote($options['comment'], 'text'); $optionStrings['comment'] = 'COMMENT = '.$this->dbh->quote($options['comment'], 'text');
}
if (isset($options['charset'])) {
if(isset($options['charset'])) {
$optionsSting['charset'] = 'DEFAULT CHARACTER SET '.$options['charset']; $optionsSting['charset'] = 'DEFAULT CHARACTER SET '.$options['charset'];
if(isset($options['collate'])) { if (isset($options['collate'])) {
$optionStrings['charset'].= ' COLLATE '.$options['collate']; $optionStrings['charset'].= ' COLLATE '.$options['collate'];
} }
} }
...@@ -223,7 +222,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export { ...@@ -223,7 +222,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return boolean * @return boolean
*/ */
public function alterTable($name, array $changes, $check) { public function alterTable($name, array $changes, $check) {
if( ! $name) if ( ! $name)
throw new Doctrine_Export_Mysql_Exception('no valid table name specified'); throw new Doctrine_Export_Mysql_Exception('no valid table name specified');
foreach ($changes as $changeName => $change) { foreach ($changes as $changeName => $change) {
...@@ -239,17 +238,17 @@ class Doctrine_Export_Mysql extends Doctrine_Export { ...@@ -239,17 +238,17 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
} }
if($check) { if ($check) {
return true; return true;
} }
$query = ''; $query = '';
if( ! empty($changes['name'])) { if ( ! empty($changes['name'])) {
$change_name = $this->conn->quoteIdentifier($changes['name'], true); $change_name = $this->conn->quoteIdentifier($changes['name'], true);
$query .= 'RENAME TO ' . $change_name; $query .= 'RENAME TO ' . $change_name;
} }
if( ! empty($changes['add']) && is_array($changes['add'])) { if ( ! empty($changes['add']) && is_array($changes['add'])) {
foreach ($changes['add'] as $field_name => $field) { foreach ($changes['add'] as $field_name => $field) {
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
...@@ -258,7 +257,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export { ...@@ -258,7 +257,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
} }
if( ! empty($changes['remove']) && is_array($changes['remove'])) { if ( ! empty($changes['remove']) && is_array($changes['remove'])) {
foreach ($changes['remove'] as $field_name => $field) { foreach ($changes['remove'] as $field_name => $field) {
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
...@@ -269,13 +268,13 @@ class Doctrine_Export_Mysql extends Doctrine_Export { ...@@ -269,13 +268,13 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
$rename = array(); $rename = array();
if( ! empty($changes['rename']) && is_array($changes['rename'])) { if ( ! empty($changes['rename']) && is_array($changes['rename'])) {
foreach ($changes['rename'] as $field_name => $field) { foreach ($changes['rename'] as $field_name => $field) {
$rename[$field['name']] = $field_name; $rename[$field['name']] = $field_name;
} }
} }
if( ! empty($changes['change']) && is_array($changes['change'])) { if ( ! empty($changes['change']) && is_array($changes['change'])) {
foreach ($changes['change'] as $field_name => $field) { foreach ($changes['change'] as $field_name => $field) {
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
...@@ -291,7 +290,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export { ...@@ -291,7 +290,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
} }
if( ! empty($rename) && is_array($rename)) { if ( ! empty($rename) && is_array($rename)) {
foreach ($rename as $rename_name => $renamed_field) { foreach ($rename as $rename_name => $renamed_field) {
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
...@@ -302,7 +301,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export { ...@@ -302,7 +301,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
} }
if( ! $query) { if ( ! $query) {
return MDB2_OK; return MDB2_OK;
} }
...@@ -329,7 +328,6 @@ class Doctrine_Export_Mysql extends Doctrine_Export { ...@@ -329,7 +328,6 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
if ($start == 1) if ($start == 1)
return true; return true;
$query = 'INSERT INTO ' . $sequenceName $query = 'INSERT INTO ' . $sequenceName
. ' (' . $seqcol_name . ') VALUES (' . ($start-1) . ')'; . ' (' . $seqcol_name . ') VALUES (' . ($start-1) . ')';
...@@ -418,4 +416,4 @@ class Doctrine_Export_Mysql extends Doctrine_Export { ...@@ -418,4 +416,4 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
$this->conn->exec('DROP TABLE ' . $table); $this->conn->exec('DROP TABLE ' . $table);
} }
} }
?>
...@@ -45,7 +45,6 @@ class Doctrine_Export_Oracle extends Doctrine_Export { ...@@ -45,7 +45,6 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE)) if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE))
throw new Doctrine_Export_Oracle_Exception('database creation is only supported if the "emulate_database" attribute is enabled'); throw new Doctrine_Export_Oracle_Exception('database creation is only supported if the "emulate_database" attribute is enabled');
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name); $username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
$password = $this->conn->dsn['password'] ? $this->conn->dsn['password'] : $name; $password = $this->conn->dsn['password'] ? $this->conn->dsn['password'] : $name;
...@@ -81,7 +80,6 @@ class Doctrine_Export_Oracle extends Doctrine_Export { ...@@ -81,7 +80,6 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
throw new Doctrine_Export_Oracle_Exception('database dropping is only supported if the throw new Doctrine_Export_Oracle_Exception('database dropping is only supported if the
"emulate_database" option is enabled'); "emulate_database" option is enabled');
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name); $username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
return $this->conn->query('DROP USER ' . $username . ' CASCADE'); return $this->conn->query('DROP USER ' . $username . ' CASCADE');
...@@ -174,7 +172,7 @@ END; ...@@ -174,7 +172,7 @@ END;
$query.= ' WHERE trigger_name='.$trigger_name_quoted.' OR trigger_name='.strtoupper($trigger_name_quoted); $query.= ' WHERE trigger_name='.$trigger_name_quoted.' OR trigger_name='.strtoupper($trigger_name_quoted);
$trigger = $this->conn->fetchOne($query); $trigger = $this->conn->fetchOne($query);
if($trigger) { if ($trigger) {
$trigger_name = $this->conn->quoteIdentifier($table . '_AI_PK', true); $trigger_name = $this->conn->quoteIdentifier($table . '_AI_PK', true);
$trigger_sql = 'DROP TRIGGER ' . $trigger_name; $trigger_sql = 'DROP TRIGGER ' . $trigger_name;
...@@ -227,8 +225,8 @@ END; ...@@ -227,8 +225,8 @@ END;
$result = parent::createTable($name, $fields, $options); $result = parent::createTable($name, $fields, $options);
foreach($fields as $field_name => $field) { foreach ($fields as $field_name => $field) {
if(isset($field['autoincrement']) && $field['autoincrement']) { if (isset($field['autoincrement']) && $field['autoincrement']) {
$result = $this->_makeAutoincrement($field_name, $name); $result = $this->_makeAutoincrement($field_name, $name);
} }
} }
......
...@@ -182,9 +182,9 @@ class Doctrine_Export_Pgsql extends Doctrine_Export { ...@@ -182,9 +182,9 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
if (!empty($field['type'])) { if (!empty($field['type'])) {
$server_info = $db->getServerVersion(); $server_info = $db->getServerVersion();
if (is_array($server_info) && $server_info['major'] < 8) if (is_array($server_info) && $server_info['major'] < 8) {
throw new Doctrine_Export_Pgsql_Exception('changing column type for "'.$change_name.'\" requires PostgreSQL 8.0 or above'); throw new Doctrine_Export_Pgsql_Exception('changing column type for "'.$change_name.'\" requires PostgreSQL 8.0 or above');
}
$query = "ALTER $field_name TYPE ".$db->datatype->getTypeDeclaration($field['definition']); $query = "ALTER $field_name TYPE ".$db->datatype->getTypeDeclaration($field['definition']);
$this->dbh->query("ALTER TABLE $name $query"); $this->dbh->query("ALTER TABLE $name $query");
} }
...@@ -214,4 +214,4 @@ class Doctrine_Export_Pgsql extends Doctrine_Export { ...@@ -214,4 +214,4 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
} }
} }
} }
?>
...@@ -71,7 +71,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export { ...@@ -71,7 +71,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export {
$fields = array(); $fields = array();
foreach ($definition['fields'] as $fieldName => $field) { foreach ($definition['fields'] as $fieldName => $field) {
$fieldString = $fieldName; $fieldString = $fieldName;
if(isset($field['sorting'])) { if (isset($field['sorting'])) {
switch ($field['sorting']) { switch ($field['sorting']) {
case 'ascending': case 'ascending':
$fieldString .= ' ASC'; $fieldString .= ' ASC';
......
...@@ -284,9 +284,9 @@ class Doctrine_Expression extends Doctrine_Connection_Module { ...@@ -284,9 +284,9 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
*/ */
private function basicMath($type, array $args) { private function basicMath($type, array $args) {
$elements = $this->getIdentifiers($args); $elements = $this->getIdentifiers($args);
if (count($elements) < 1) if (count($elements) < 1) {
return ''; return '';
}
if (count($elements) == 1) { if (count($elements) == 1) {
return $elements[0]; return $elements[0];
} else { } else {
...@@ -539,15 +539,15 @@ class Doctrine_Expression extends Doctrine_Connection_Module { ...@@ -539,15 +539,15 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @return string logical expression * @return string logical expression
*/ */
public function in($column, $values) { public function in($column, $values) {
if( ! is_array($values)) if ( ! is_array($values)) {
$values = array($values); $values = array($values);
}
$values = $this->getIdentifiers($values); $values = $this->getIdentifiers($values);
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
if(count($values) == 0) if (count($values) == 0) {
throw new Doctrine_Expression_Exception('Values array for IN operator should not be empty.'); throw new Doctrine_Expression_Exception('Values array for IN operator should not be empty.');
}
return $column . ' IN (' . implode(', ', $values) . ')'; return $column . ' IN (' . implode(', ', $values) . ')';
} }
/** /**
......
...@@ -56,9 +56,9 @@ class Doctrine_Expression_Mssql extends Doctrine_Expression { ...@@ -56,9 +56,9 @@ class Doctrine_Expression_Mssql extends Doctrine_Expression {
* @return string to call a function to get a substring * @return string to call a function to get a substring
*/ */
public function substring($value, $position, $length = null) { public function substring($value, $position, $length = null) {
if (!is_null($length)) if (!is_null($length)) {
return "SUBSTRING($value, $position, $length)"; return "SUBSTRING($value, $position, $length)";
}
return "SUBSTRING($value, $position, LEN($value) - $position + 1)"; return "SUBSTRING($value, $position, LEN($value) - $position + 1)";
} }
/** /**
......
...@@ -57,7 +57,7 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression { ...@@ -57,7 +57,7 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression {
* @return string SQL substring function with given parameters * @return string SQL substring function with given parameters
*/ */
public function substring($value, $position, $length = null) { public function substring($value, $position, $length = null) {
if($length !== null) if ($length !== null)
return "SUBSTR($value, $position, $length)"; return "SUBSTR($value, $position, $length)";
return "SUBSTR($value, $position)"; return "SUBSTR($value, $position)";
......
...@@ -52,11 +52,12 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression { ...@@ -52,11 +52,12 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
public function md5($column) { public function md5($column) {
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
if ($this->version > 7) if ($this->version > 7) {
return 'MD5(' . $column . ')'; return 'MD5(' . $column . ')';
else } else {
return 'encode(digest(' . $column .', md5), hex)'; return 'encode(digest(' . $column .', md5), hex)';
} }
}
/** /**
* Returns part of a string. * Returns part of a string.
...@@ -74,9 +75,10 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression { ...@@ -74,9 +75,10 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
if ($len === null) { if ($len === null) {
$len = $this->getIdentifier($len); $len = $this->getIdentifier($len);
return 'SUBSTR(' . $value . ', ' . $from . ')'; return 'SUBSTR(' . $value . ', ' . $from . ')';
} else } else {
return 'SUBSTR(' . $value . ', ' . $from . ', ' . $len . ')'; return 'SUBSTR(' . $value . ', ' . $from . ', ' . $len . ')';
} }
}
/** /**
* Returns a series of strings concatinated * Returns a series of strings concatinated
......
...@@ -143,9 +143,9 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression { ...@@ -143,9 +143,9 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* @return string SQL substring function with given parameters * @return string SQL substring function with given parameters
*/ */
public function substring($value, $position, $length = null) { public function substring($value, $position, $length = null) {
if($length !== null) if ($length !== null) {
return 'SUBSTR(' . $value . ', ' . $position . ', ' . $length . ')'; return 'SUBSTR(' . $value . ', ' . $position . ', ' . $length . ')';
}
return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))'; return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))';
} }
} }
...@@ -70,10 +70,10 @@ class Doctrine_Hook { ...@@ -70,10 +70,10 @@ class Doctrine_Hook {
* @param Doctrine_Query $query the base query * @param Doctrine_Query $query the base query
*/ */
public function __construct($query) { public function __construct($query) {
if(is_string($query)) { if (is_string($query)) {
$this->query = new Doctrine_Query(); $this->query = new Doctrine_Query();
$this->query->parseQuery($query); $this->query->parseQuery($query);
} elseif($query instanceof Doctrine_Query) { } elseif ($query instanceof Doctrine_Query) {
$this->query = $query; $this->query = $query;
} }
} }
...@@ -95,21 +95,20 @@ class Doctrine_Hook { ...@@ -95,21 +95,20 @@ class Doctrine_Hook {
* @return boolean whether or not the hooking was * @return boolean whether or not the hooking was
*/ */
public function hookWhere($params) { public function hookWhere($params) {
if( ! is_array($params)) if ( ! is_array($params)) {
return false; return false;
}
foreach($params as $name => $value) { foreach ($params as $name => $value) {
$e = explode('.', $name); $e = explode('.', $name);
if(count($e) == 2) { if (count($e) == 2) {
list($alias, $column) = $e; list($alias, $column) = $e;
$tableAlias = $this->query->getTableAlias($alias); $tableAlias = $this->query->getTableAlias($alias);
$table = $this->query->getTable($tableAlias); $table = $this->query->getTable($tableAlias);
if($def = $table->getDefinitionOf($column)) { if ($def = $table->getDefinitionOf($column)) {
if (isset($this->typeParsers[$def[0]])) {
if(isset($this->typeParsers[$def[0]])) {
$name = $this->typeParsers[$def[0]]; $name = $this->typeParsers[$def[0]];
$parser = new $name; $parser = new $name;
} }
...@@ -134,27 +133,27 @@ class Doctrine_Hook { ...@@ -134,27 +133,27 @@ class Doctrine_Hook {
* @return boolean whether or not the hooking was * @return boolean whether or not the hooking was
*/ */
public function hookOrderby($params) { public function hookOrderby($params) {
if( ! is_array($params)) if ( ! is_array($params)) {
return false; return false;
}
foreach($params as $name) { foreach ($params as $name) {
$e = explode(' ', $name); $e = explode(' ', $name);
$order = 'ASC'; $order = 'ASC';
if(count($e) > 1) { if (count($e) > 1) {
$order = ($e[1] == 'DESC') ? 'DESC' : 'ASC'; $order = ($e[1] == 'DESC') ? 'DESC' : 'ASC';
} }
$e = explode('.', $e[0]); $e = explode('.', $e[0]);
if(count($e) == 2) { if (count($e) == 2) {
list($alias, $column) = $e; list($alias, $column) = $e;
$tableAlias = $this->query->getTableAlias($alias); $tableAlias = $this->query->getTableAlias($alias);
$table = $this->query->getTable($tableAlias); $table = $this->query->getTable($tableAlias);
if($def = $table->getDefinitionOf($column)) { if ($def = $table->getDefinitionOf($column)) {
$this->query->addOrderBy($alias . '.' . $column . ' ' . $order); $this->query->addOrderBy($alias . '.' . $column . ' ' . $order);
} }
} }
......
...@@ -46,14 +46,14 @@ class Doctrine_Hook_Integer extends Doctrine_Hook_Parser_Complex { ...@@ -46,14 +46,14 @@ class Doctrine_Hook_Integer extends Doctrine_Hook_Parser_Complex {
public function parseSingle($alias, $field, $value) { public function parseSingle($alias, $field, $value) {
$e = explode(' ', $value); $e = explode(' ', $value);
foreach($e as $v) { foreach ($e as $v) {
$v = trim($v); $v = trim($v);
$e2 = explode('-', $v); $e2 = explode('-', $v);
$name = $alias. '.' . $field; $name = $alias. '.' . $field;
if(count($e2) == 1) { if (count($e2) == 1) {
// one '-' found // one '-' found
$a[] = $name . ' = ?'; $a[] = $name . ' = ?';
......
...@@ -57,9 +57,9 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser { ...@@ -57,9 +57,9 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser {
public function parseClause($alias, $field, $value) { public function parseClause($alias, $field, $value) {
$parts = Doctrine_Query::bracketExplode($value, ' AND ', '(', ')'); $parts = Doctrine_Query::bracketExplode($value, ' AND ', '(', ')');
if(count($parts) > 1) { if (count($parts) > 1) {
$ret = array(); $ret = array();
foreach($parts as $part) { foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')'); $part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parseSingle($alias, $field, $part); $ret[] = $this->parseSingle($alias, $field, $part);
} }
...@@ -67,16 +67,16 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser { ...@@ -67,16 +67,16 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser {
$r = implode(' AND ', $ret); $r = implode(' AND ', $ret);
} else { } else {
$parts = Doctrine_Query::bracketExplode($value, ' OR ', '(', ')'); $parts = Doctrine_Query::bracketExplode($value, ' OR ', '(', ')');
if(count($parts) > 1) { if (count($parts) > 1) {
$ret = array(); $ret = array();
foreach($parts as $part) { foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')'); $part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parseClause($alias, $field, $part); $ret[] = $this->parseClause($alias, $field, $part);
} }
$r = implode(' OR ', $ret); $r = implode(' OR ', $ret);
} else { } else {
if(substr($parts[0],0,1) == '(' && substr($parts[0],-1) == ')') { if (substr($parts[0],0,1) == '(' && substr($parts[0],-1) == ')') {
return $this->parseClause(substr($parts[0],1,-1)); return $this->parseClause(substr($parts[0],1,-1));
} else { } else {
$ret = $this->parseSingle($alias, $field, $parts[0]); $ret = $this->parseSingle($alias, $field, $parts[0]);
......
...@@ -46,7 +46,7 @@ class Doctrine_Hook_WordLike extends Doctrine_Hook_Parser_Complex { ...@@ -46,7 +46,7 @@ class Doctrine_Hook_WordLike extends Doctrine_Hook_Parser_Complex {
public function parseSingle($alias, $field, $value) { public function parseSingle($alias, $field, $value) {
$e2 = explode(' ',$value); $e2 = explode(' ',$value);
foreach($e2 as $v) { foreach ($e2 as $v) {
$v = trim($v); $v = trim($v);
$a[] = $alias. '.' . $field . ' LIKE ?'; $a[] = $alias. '.' . $field . ' LIKE ?';
$this->params[] = $v . '%'; $this->params[] = $v . '%';
......
This diff is collapsed.
...@@ -42,12 +42,12 @@ class Doctrine_Hydrate_Alias { ...@@ -42,12 +42,12 @@ class Doctrine_Hydrate_Alias {
} }
public function generateNewAlias($alias) { public function generateNewAlias($alias) {
if(isset($this->shortAliases[$alias])) { if (isset($this->shortAliases[$alias])) {
// generate a new alias // generate a new alias
$name = substr($alias, 0, 1); $name = substr($alias, 0, 1);
$i = ((int) substr($alias, 1)); $i = ((int) substr($alias, 1));
if($i == 0) if ($i == 0)
$i = 1; $i = 1;
$newIndex = ($this->shortAliasIndexes[$name] + $i); $newIndex = ($this->shortAliasIndexes[$name] + $i);
...@@ -62,9 +62,9 @@ class Doctrine_Hydrate_Alias { ...@@ -62,9 +62,9 @@ class Doctrine_Hydrate_Alias {
return (isset($this->shortAliases[$tableName])); return (isset($this->shortAliases[$tableName]));
} }
public function getShortAliasIndex($alias) { public function getShortAliasIndex($alias) {
if( ! isset($this->shortAliasIndexes[$alias])) if ( ! isset($this->shortAliasIndexes[$alias])) {
return 0; return 0;
}
return $this->shortAliasIndexes[$alias]; return $this->shortAliasIndexes[$alias];
} }
public function generateShortAlias($tableName) { public function generateShortAlias($tableName) {
...@@ -72,10 +72,10 @@ class Doctrine_Hydrate_Alias { ...@@ -72,10 +72,10 @@ class Doctrine_Hydrate_Alias {
$alias = $char; $alias = $char;
if( ! isset($this->shortAliasIndexes[$alias])) if ( ! isset($this->shortAliasIndexes[$alias])) {
$this->shortAliasIndexes[$alias] = 1; $this->shortAliasIndexes[$alias] = 1;
}
while(isset($this->shortAliases[$alias])) { while (isset($this->shortAliases[$alias])) {
$alias = $char . ++$this->shortAliasIndexes[$alias]; $alias = $char . ++$this->shortAliasIndexes[$alias];
} }
$this->shortAliases[$alias] = $tableName; $this->shortAliases[$alias] = $tableName;
...@@ -86,9 +86,9 @@ class Doctrine_Hydrate_Alias { ...@@ -86,9 +86,9 @@ class Doctrine_Hydrate_Alias {
public function getShortAlias($tableName) { public function getShortAlias($tableName) {
$alias = array_search($tableName, $this->shortAliases); $alias = array_search($tableName, $this->shortAliases);
if($alias !== false) if ($alias !== false) {
return $alias; return $alias;
}
return $this->generateShortAlias($tableName); return $this->generateShortAlias($tableName);
} }
} }
...@@ -47,4 +47,3 @@ class Doctrine_Identifier { ...@@ -47,4 +47,3 @@ class Doctrine_Identifier {
*/ */
const COMPOSITE = 4; const COMPOSITE = 4;
} }
...@@ -44,7 +44,7 @@ class Doctrine_Import extends Doctrine_Connection_Module ...@@ -44,7 +44,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/ */
public function listDatabases() public function listDatabases()
{ {
if( ! isset($this->sql['listDatabases'])) { if ( ! isset($this->sql['listDatabases'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
...@@ -57,7 +57,7 @@ class Doctrine_Import extends Doctrine_Connection_Module ...@@ -57,7 +57,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/ */
public function listFunctions() public function listFunctions()
{ {
if( ! isset($this->sql['listFunctions'])) { if ( ! isset($this->sql['listFunctions'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
...@@ -81,7 +81,7 @@ class Doctrine_Import extends Doctrine_Connection_Module ...@@ -81,7 +81,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/ */
public function listSequences($database = null) public function listSequences($database = null)
{ {
if( ! isset($this->sql['listSequences'])) { if ( ! isset($this->sql['listSequences'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
...@@ -154,7 +154,7 @@ class Doctrine_Import extends Doctrine_Connection_Module ...@@ -154,7 +154,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/ */
public function listUsers() public function listUsers()
{ {
if( ! isset($this->sql['listUsers'])) { if ( ! isset($this->sql['listUsers'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
...@@ -168,7 +168,7 @@ class Doctrine_Import extends Doctrine_Connection_Module ...@@ -168,7 +168,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/ */
public function listViews($database = null) public function listViews($database = null)
{ {
if( ! isset($this->sql['listViews'])) { if ( ! isset($this->sql['listViews'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
......
...@@ -42,13 +42,14 @@ class Doctrine_Import_Builder { ...@@ -42,13 +42,14 @@ class Doctrine_Import_Builder {
private static $tpl; private static $tpl;
public function __construct() { public function __construct() {
if( ! isset(self::$tpl)) if ( ! isset(self::$tpl)) {
self::$tpl = file_get_contents(Doctrine::getPath() self::$tpl = file_get_contents(Doctrine::getPath()
. DIRECTORY_SEPARATOR . 'Doctrine' . DIRECTORY_SEPARATOR . 'Doctrine'
. DIRECTORY_SEPARATOR . 'Import' . DIRECTORY_SEPARATOR . 'Import'
. DIRECTORY_SEPARATOR . 'Builder' . DIRECTORY_SEPARATOR . 'Builder'
. DIRECTORY_SEPARATOR . 'Record.tpl'); . DIRECTORY_SEPARATOR . 'Record.tpl');
} }
}
/** /**
* *
...@@ -57,7 +58,7 @@ class Doctrine_Import_Builder { ...@@ -57,7 +58,7 @@ class Doctrine_Import_Builder {
* @access public * @access public
*/ */
public function setTargetPath($path) { public function setTargetPath($path) {
if( ! file_exists($path)) { if ( ! file_exists($path)) {
mkdir($path, 0777); mkdir($path, 0777);
} }
...@@ -79,14 +80,13 @@ class Doctrine_Import_Builder { ...@@ -79,14 +80,13 @@ class Doctrine_Import_Builder {
return $this->suffix; return $this->suffix;
} }
public function buildRecord(Doctrine_Schema_Table $table) { public function buildRecord(Doctrine_Schema_Table $table) {
if (empty($this->path)) if (empty($this->path)) {
throw new Doctrine_Import_Builder_Exception('No build target directory set.'); throw new Doctrine_Import_Builder_Exception('No build target directory set.');
}
if (is_writable($this->path) === false) if (is_writable($this->path) === false) {
throw new Doctrine_Import_Builder_Exception('Build target directory ' . $this->path . ' is not writable.'); throw new Doctrine_Import_Builder_Exception('Build target directory ' . $this->path . ' is not writable.');
}
$created = date('l dS \of F Y h:i:s A'); $created = date('l dS \of F Y h:i:s A');
$className = Doctrine::classify($table->get('name')); $className = Doctrine::classify($table->get('name'));
$fileName = $this->path . DIRECTORY_SEPARATOR . $className . $this->suffix; $fileName = $this->path . DIRECTORY_SEPARATOR . $className . $this->suffix;
...@@ -94,41 +94,42 @@ class Doctrine_Import_Builder { ...@@ -94,41 +94,42 @@ class Doctrine_Import_Builder {
$i = 0; $i = 0;
foreach($table as $name => $column) { foreach ($table as $name => $column) {
$columns[$i] = ' $this->hasColumn(\'' . $column['name'] . '\', \'' . $column['type'] . '\''; $columns[$i] = ' $this->hasColumn(\'' . $column['name'] . '\', \'' . $column['type'] . '\'';
if($column['length']) if ($column['length']) {
$columns[$i] .= ', ' . $column['length']; $columns[$i] .= ', ' . $column['length'];
else } else {
$columns[$i] .= ', null'; $columns[$i] .= ', null';
}
$a = array(); $a = array();
if($column['default']) { if ($column['default']) {
$a[] = '\'default\' => ' . var_export($column['default'], true); $a[] = '\'default\' => ' . var_export($column['default'], true);
} }
if($column['notnull']) { if ($column['notnull']) {
$a[] = '\'notnull\' => true'; $a[] = '\'notnull\' => true';
} }
if($column['primary']) { if ($column['primary']) {
$a[] = '\'primary\' => true'; $a[] = '\'primary\' => true';
} }
if($column['autoinc']) { if ($column['autoinc']) {
$a[] = '\'autoincrement\' => true'; $a[] = '\'autoincrement\' => true';
} }
if($column['unique']) { if ($column['unique']) {
$a[] = '\'unique\' => true'; $a[] = '\'unique\' => true';
} }
if( ! empty($a)) if ( ! empty($a)) {
$columns[$i] .= ', ' . 'array(' . implode(', $columns[$i] .= ', ' . 'array(' . implode(',
', $a) . ')'; ', $a) . ')';
}
$columns[$i] .= ');'; $columns[$i] .= ');';
if($i < (count($table) - 1)) if ($i < (count($table) - 1)) {
$columns[$i] .= ' $columns[$i] .= '
'; ';
}
$i++; $i++;
} }
...@@ -136,8 +137,7 @@ class Doctrine_Import_Builder { ...@@ -136,8 +137,7 @@ class Doctrine_Import_Builder {
$bytes = file_put_contents($fileName, $content); $bytes = file_put_contents($fileName, $content);
if ($bytes === false)
if($bytes === false)
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName); throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName);
} }
/** /**
...@@ -147,8 +147,8 @@ class Doctrine_Import_Builder { ...@@ -147,8 +147,8 @@ class Doctrine_Import_Builder {
* @return void * @return void
*/ */
public function build(Doctrine_Schema_Object $schema) { public function build(Doctrine_Schema_Object $schema) {
foreach($schema->getDatabases() as $database){ foreach ($schema->getDatabases() as $database){
foreach($database->getTables() as $table){ foreach ($database->getTables() as $table){
$this->buildRecord($table); $this->buildRecord($table);
} }
} }
......
...@@ -109,7 +109,7 @@ class Doctrine_Import_Firebird extends Doctrine_Import { ...@@ -109,7 +109,7 @@ class Doctrine_Import_Firebird extends Doctrine_Import {
WHERE RDB$SYSTEM_FLAG IS NULL WHERE RDB$SYSTEM_FLAG IS NULL
OR RDB$SYSTEM_FLAG = 0'; OR RDB$SYSTEM_FLAG = 0';
if( ! is_null($table)) { if ( ! is_null($table)) {
$table = $db->quote(strtoupper($table), 'text'); $table = $db->quote(strtoupper($table), 'text');
$query .= 'WHERE UPPER(RDB$RELATION_NAME) = ' . $table; $query .= 'WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
} }
......
...@@ -143,7 +143,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import { ...@@ -143,7 +143,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import {
$description = array(); $description = array();
foreach ($result as $key => $val2) { foreach ($result as $key => $val2) {
$val = array(); $val = array();
foreach(array_keys($val2) as $valKey){ // lowercase the key names foreach (array_keys($val2) as $valKey){ // lowercase the key names
$val[strtolower($valKey)] = $val2[$valKey]; $val[strtolower($valKey)] = $val2[$valKey];
} }
$description = array( $description = array(
......
...@@ -46,7 +46,6 @@ abstract class Doctrine_Import_Reader ...@@ -46,7 +46,6 @@ abstract class Doctrine_Import_Reader
/*** Attributes: ***/ /*** Attributes: ***/
/** /**
* *
* @return Doctrine_Schema * @return Doctrine_Schema
...@@ -55,9 +54,4 @@ abstract class Doctrine_Import_Reader ...@@ -55,9 +54,4 @@ abstract class Doctrine_Import_Reader
*/ */
abstract public function read( ); abstract public function read( );
} // end of Doctrine_Import_Reader } // end of Doctrine_Import_Reader
...@@ -52,7 +52,6 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader ...@@ -52,7 +52,6 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
*/ */
private $pdo; private $pdo;
/** /**
* *
* @param object pdo * @return * @param object pdo * @return
...@@ -62,7 +61,6 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader ...@@ -62,7 +61,6 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
} // end of member function setPdo } // end of member function setPdo
/** /**
* *
* @return Doctrine_Schema * @return Doctrine_Schema
...@@ -80,16 +78,16 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader ...@@ -80,16 +78,16 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
$db->set("name",$dbName); $db->set("name",$dbName);
$tableNames = $dataDict->listTables(); $tableNames = $dataDict->listTables();
foreach($tableNames as $tableName){ foreach ($tableNames as $tableName){
$table = new Doctrine_Schema_Table(); $table = new Doctrine_Schema_Table();
$table->set("name",$tableName); $table->set("name",$tableName);
$tableColumns = $dataDict->listTableColumns($tableName); $tableColumns = $dataDict->listTableColumns($tableName);
foreach($tableColumns as $tableColumn){ foreach ($tableColumns as $tableColumn){
$table->addColumn($tableColumn); $table->addColumn($tableColumn);
} }
$db->addTable($table); $db->addTable($table);
if ($fks = $dataDict->listTableConstraints($tableName)){ if ($fks = $dataDict->listTableConstraints($tableName)){
foreach($fks as $fk){ foreach ($fks as $fk){
$relation = new Doctrine_Schema_Relation(); $relation = new Doctrine_Schema_Relation();
$relation->setRelationBetween($fk['referencingColumn'],$fk['referencedTable'],$fk['referencedColumn']); $relation->setRelationBetween($fk['referencingColumn'],$fk['referencedTable'],$fk['referencedColumn']);
$table->setRelation($relation); $table->setRelation($relation);
...@@ -100,7 +98,4 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader ...@@ -100,7 +98,4 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
return $schema; return $schema;
} }
} // end of Doctrine_Import_Reader_Db } // end of Doctrine_Import_Reader_Db
...@@ -44,10 +44,4 @@ class Doctrine_Import_Reader_Exception ...@@ -44,10 +44,4 @@ class Doctrine_Import_Reader_Exception
/*** Attributes: ***/ /*** Attributes: ***/
} // end of Doctrine_Import_Reader_Exception } // end of Doctrine_Import_Reader_Exception
...@@ -50,7 +50,6 @@ class Doctrine_Import_Reader_Xml_Propel extends Doctrine_Import_Reader ...@@ -50,7 +50,6 @@ class Doctrine_Import_Reader_Xml_Propel extends Doctrine_Import_Reader
*/ */
private $xml; private $xml;
/** /**
* *
* @param string xml * @return * @param string xml * @return
...@@ -62,7 +61,4 @@ class Doctrine_Import_Reader_Xml_Propel extends Doctrine_Import_Reader ...@@ -62,7 +61,4 @@ class Doctrine_Import_Reader_Xml_Propel extends Doctrine_Import_Reader
public function read() { } public function read() { }
} // end of Doctrine_Import_Reader_Xml_Propel } // end of Doctrine_Import_Reader_Xml_Propel
...@@ -136,7 +136,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import { ...@@ -136,7 +136,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$description = array(); $description = array();
$columns = array(); $columns = array();
foreach($result as $key => $val) { foreach ($result as $key => $val) {
$description = array( $description = array(
'name' => $val['name'], 'name' => $val['name'],
'type' => $val['type'], 'type' => $val['type'],
...@@ -159,7 +159,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import { ...@@ -159,7 +159,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); $result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$indexes = array(); $indexes = array();
foreach($result as $key => $val) { foreach ($result as $key => $val) {
} }
} }
...@@ -179,7 +179,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import { ...@@ -179,7 +179,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$data = $stmt->fetchAll(PDO::FETCH_COLUMN); $data = $stmt->fetchAll(PDO::FETCH_COLUMN);
foreach($data as $table) { foreach ($data as $table) {
$tables[] = new Doctrine_Schema_Table(array('name' => $table)); $tables[] = new Doctrine_Schema_Table(array('name' => $table));
} }
return $tables; return $tables;
......
...@@ -36,7 +36,7 @@ class Doctrine_Lib { ...@@ -36,7 +36,7 @@ class Doctrine_Lib {
* @return string string representation of given state * @return string string representation of given state
*/ */
public static function getRecordStateAsString($state) { public static function getRecordStateAsString($state) {
switch($state): switch ($state) {
case Doctrine_Record::STATE_PROXY: case Doctrine_Record::STATE_PROXY:
return "proxy"; return "proxy";
break; break;
...@@ -52,7 +52,7 @@ class Doctrine_Lib { ...@@ -52,7 +52,7 @@ class Doctrine_Lib {
case Doctrine_Record::STATE_TCLEAN: case Doctrine_Record::STATE_TCLEAN:
return "transient clean"; return "transient clean";
break; break;
endswitch; };
} }
/** /**
* returns a string representation of Doctrine_Record object * returns a string representation of Doctrine_Record object
...@@ -75,7 +75,7 @@ class Doctrine_Lib { ...@@ -75,7 +75,7 @@ class Doctrine_Lib {
* @param integer $state connection state * @param integer $state connection state
*/ */
public static function getConnectionStateAsString($state) { public static function getConnectionStateAsString($state) {
switch($state): switch ($state) {
case Doctrine_Transaction::STATE_SLEEP: case Doctrine_Transaction::STATE_SLEEP:
return "open"; return "open";
break; break;
...@@ -85,7 +85,7 @@ class Doctrine_Lib { ...@@ -85,7 +85,7 @@ class Doctrine_Lib {
case Doctrine_Transaction::STATE_ACTIVE: case Doctrine_Transaction::STATE_ACTIVE:
return "active"; return "active";
break; break;
endswitch; };
} }
/** /**
* returns a string representation of Doctrine_Connection object * returns a string representation of Doctrine_Connection object
...@@ -100,17 +100,18 @@ class Doctrine_Lib { ...@@ -100,17 +100,18 @@ class Doctrine_Lib {
$r[] = "Table in memory : ".$connection->count(); $r[] = "Table in memory : ".$connection->count();
$queries = false; $queries = false;
if($connection->getDBH() instanceof Doctrine_Db) { if ($connection->getDBH() instanceof Doctrine_Db) {
$handler = "Doctrine Database Handler"; $handler = "Doctrine Database Handler";
$queries = count($connection->getDBH()->getQueries()); $queries = count($connection->getDBH()->getQueries());
$sum = array_sum($connection->getDBH()->getExecTimes()); $sum = array_sum($connection->getDBH()->getExecTimes());
} elseif($connection->getDBH() instanceof PDO) { } elseif ($connection->getDBH() instanceof PDO) {
$handler = "PHP Native PDO Driver"; $handler = "PHP Native PDO Driver";
} else } else {
$handler = "Unknown Database Handler"; $handler = "Unknown Database Handler";
}
$r[] = "DB Handler : ".$handler; $r[] = "DB Handler : ".$handler;
if($queries) { if ($queries) {
$r[] = "Executed Queries : ".$queries; $r[] = "Executed Queries : ".$queries;
$r[] = "Sum of Exec Times : ".$sum; $r[] = "Sum of Exec Times : ".$sum;
} }
...@@ -162,11 +163,10 @@ class Doctrine_Lib { ...@@ -162,11 +163,10 @@ class Doctrine_Lib {
$r[] = "<pre>"; $r[] = "<pre>";
$r[] = get_class($collection); $r[] = get_class($collection);
foreach($collection as $key => $record) { foreach ($collection as $key => $record) {
$r[] = "Key : ".$key." ID : ".$record->obtainIdentifier(); $r[] = "Key : ".$key." ID : ".$record->obtainIdentifier();
} }
$r[] = "</pre>"; $r[] = "</pre>";
return implode("\n",$r); return implode("\n",$r);
} }
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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