1
0
mirror of synced 2024-12-13 22:56:04 +03:00

- first round of PEAR CS fixes

This commit is contained in:
lsmith 2006-12-29 14:01:31 +00:00
parent f6400e0119
commit 716bb65b86
166 changed files with 7871 additions and 7978 deletions

View File

@ -344,9 +344,9 @@ final class Doctrine {
* @return string
*/
public static function getPath() {
if(! self::$path)
if (! self::$path) {
self::$path = dirname(__FILE__);
}
return self::$path;
}
/**
@ -358,7 +358,7 @@ final class Doctrine {
public static function loadAll() {
$classes = Doctrine_Compiler::getRuntimeClasses();
foreach($classes as $class) {
foreach ($classes as $class) {
Doctrine::autoload($class);
}
}
@ -400,17 +400,17 @@ final class Doctrine {
* @return boolean
*/
public static function autoload($classname) {
if(class_exists($classname))
if (class_exists($classname)) {
return false;
if(! self::$path)
}
if (! self::$path) {
self::$path = dirname(__FILE__);
}
$class = self::$path.DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR,$classname) . '.php';
if( ! file_exists($class))
if ( ! file_exists($class)) {
return false;
}
require_once($class);
@ -441,7 +441,7 @@ final class Doctrine {
* @return boolean
*/
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 true;

View File

@ -41,9 +41,9 @@ abstract class Doctrine_Access implements ArrayAccess {
* @return Doctrine_Access
*/
public function setArray(array $array) {
foreach($array as $k=>$v):
foreach ($array as $k=>$v) {
$this->set($k,$v);
endforeach;
};
return $this;
}
@ -114,10 +114,11 @@ abstract class Doctrine_Access implements ArrayAccess {
* @return void
*/
public function offsetSet($offset, $value) {
if( ! isset($offset)) {
if ( ! isset($offset)) {
$this->add($value);
} else
} else {
$this->set($offset,$value);
}
}
/**
* unset a given offset
@ -128,4 +129,3 @@ abstract class Doctrine_Access implements ArrayAccess {
return $this->remove($offset);
}
}

View File

@ -92,7 +92,7 @@ class Doctrine_Adapter {
const FETCH_UNIQUE = 196608;
const NULL_EMPTY_STRING = 1;
const NULL_NATURAL = 0;
const NULL_TO_STRING = NULL;
const NULL_TO_STRING = NULL;
const PARAM_BOOL = 5;
const PARAM_INPUT_OUTPUT = -2147483648;
const PARAM_INT = 1;

View File

@ -49,19 +49,17 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
* @param Doctrine_Connection|null $connection
*/
public function __construct($connection = null) {
if( ! ($connection instanceof Doctrine_Connection))
if ( ! ($connection instanceof Doctrine_Connection)) {
$connection = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->session = $connection;
$dir = 'cache';
$this->path = $dir.DIRECTORY_SEPARATOR;
$this->dbh = new PDO("sqlite::memory:");
try {
if($this->session->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true)
{
if ($this->session->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true) {
$columns = array();
$columns['query_md5'] = array('string', 32, 'notnull');
$columns['query_result'] = array('array', 100000, 'notnull');

View File

@ -69,7 +69,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
protected static $null;
protected $aggregateValues = array();
/**
@ -78,15 +77,15 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param Doctrine_Table|string $table
*/
public function __construct($table) {
if( ! ($table instanceof Doctrine_Table))
if ( ! ($table instanceof Doctrine_Table)) {
$table = Doctrine_Manager::getInstance()
->getCurrentConnection()
->getTable($table);
}
$this->table = $table;
$name = $table->getAttribute(Doctrine::ATTR_COLL_KEY);
if($name !== null) {
if ($name !== null) {
$this->keyColumn = $name;
}
}
@ -158,7 +157,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$array = unserialize($serialized);
foreach($array as $name => $values) {
foreach ($array as $name => $values) {
$this->$name = $values;
}
@ -168,7 +167,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->expandable = true;
$name = $this->table->getAttribute(Doctrine::ATTR_COLL_KEY);
if($name !== null) {
if ($name !== null) {
$this->keyColumn = $name;
}
}
@ -250,21 +249,22 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->reference = $record;
$this->relation = $relation;
if($relation instanceof Doctrine_Relation_ForeignKey ||
$relation instanceof Doctrine_Relation_LocalKey) {
if ($relation instanceof Doctrine_Relation_ForeignKey
|| $relation instanceof Doctrine_Relation_LocalKey
) {
$this->reference_field = $relation->getForeign();
$value = $record->get($relation->getLocal());
foreach($this->getNormalIterator() as $record) {
if($value !== null) {
foreach ($this->getNormalIterator() as $record) {
if ($value !== null) {
$record->set($this->reference_field, $value, false);
} else {
$record->set($this->reference_field, $this->reference, false);
}
}
} elseif($relation instanceof Doctrine_Relation_Association) {
} elseif ($relation instanceof Doctrine_Relation_Association) {
}
}
@ -288,48 +288,49 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$limit = null;
$offset = null;
switch(get_class($this)):
case "Doctrine_Collection_Offset":
$limit = $this->getLimit();
$offset = (floor($key / $limit) * $limit);
switch (get_class($this)) {
case "Doctrine_Collection_Offset":
$limit = $this->getLimit();
$offset = (floor($key / $limit) * $limit);
if( ! $this->expandable && isset($this->expanded[$offset]))
return false;
$fields = implode(", ",$this->table->getColumnNames());
if ( ! $this->expandable && isset($this->expanded[$offset])) {
return false;
}
$fields = implode(", ",$this->table->getColumnNames());
break;
default:
if ( ! $this->expandable) {
return false;
}
if ( ! isset($this->reference)) {
return false;
}
$id = $this->reference->obtainIdentifier();
if (empty($id)) {
return false;
}
switch (get_class($this)) {
case "Doctrine_Collection_Immediate":
$fields = implode(", ",$this->table->getColumnNames());
break;
default:
if( ! $this->expandable)
return false;
$fields = implode(", ",$this->table->getPrimaryKeys());
};
};
if( ! isset($this->reference))
return false;
$id = $this->reference->obtainIdentifier();
if(empty($id))
return false;
switch(get_class($this)):
case "Doctrine_Collection_Immediate":
$fields = implode(", ",$this->table->getColumnNames());
break;
default:
$fields = implode(", ",$this->table->getPrimaryKeys());
endswitch;
endswitch;
if(isset($this->relation)) {
if($this->relation instanceof Doctrine_Relation_ForeignKey) {
if (isset($this->relation)) {
if ($this->relation instanceof Doctrine_Relation_ForeignKey) {
$params[] = $this->reference->getIncremented();
$where[] = $this->reference_field." = ?";
if( ! isset($offset)) {
if ( ! isset($offset)) {
$ids = $this->getPrimaryKeys();
if( ! empty($ids)) {
if ( ! empty($ids)) {
$where[] = $this->table->getIdentifier()." NOT IN (".substr(str_repeat("?, ",count($ids)),0,-2).")";
$params = array_merge($params,$ids);
}
@ -337,8 +338,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->expandable = false;
}
} elseif($this->relation instanceof Doctrine_Relation_Association) {
} elseif ($this->relation instanceof Doctrine_Relation_Association) {
$asf = $this->relation->getAssociationFactory();
$query = 'SELECT '.$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented();
@ -354,32 +354,32 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$query = "SELECT ".$fields." FROM ".$this->table->getTableName();
// apply column aggregation inheritance
foreach($this->table->getInheritanceMap() as $k => $v) {
foreach ($this->table->getInheritanceMap() as $k => $v) {
$where[] = $k." = ?";
$params[] = $v;
}
if( ! empty($where)) {
if ( ! empty($where)) {
$query .= " WHERE ".implode(" AND ",$where);
}
$coll = $this->table->execute($query, $params, $limit, $offset);
if( ! isset($offset)) {
foreach($coll as $record) {
if(isset($this->reference_field))
if ( ! isset($offset)) {
foreach ($coll as $record) {
if (isset($this->reference_field)) {
$record->set($this->reference_field,$this->reference, false);
}
$this->reference->addReference($record, $this->relation);
}
} else {
$i = $offset;
foreach($coll as $record) {
if(isset($this->reference)) {
foreach ($coll as $record) {
if (isset($this->reference)) {
$this->reference->addReference($record, $this->relation, $i);
} else
} else {
$this->data[$i] = $record;
}
$i++;
}
@ -388,7 +388,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
// check if the fetched collection's record count is smaller
// than the query limit, if so this collection has been expanded to its max size
if(count($coll) < $limit) {
if (count($coll) < $limit) {
$this->expandable = false;
}
}
@ -403,7 +403,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @return boolean
*/
public function remove($key) {
if( ! isset($this->data[$key])) {
if ( ! isset($this->data[$key])) {
$this->expand($key);
throw new InvalidKeyException();
}
@ -428,16 +428,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @return object Doctrine_Record return a specified record
*/
public function get($key) {
if( ! isset($this->data[$key])) {
if ( ! isset($this->data[$key])) {
$this->expand($key);
if( ! isset($this->data[$key]))
if ( ! isset($this->data[$key])) {
$this->data[$key] = $this->table->create();
if(isset($this->reference_field)) {
}
if (isset($this->reference_field)) {
$value = $this->reference->get($this->relation->getLocal());
if($value !== null) {
if ($value !== null) {
$this->data[$key]->set($this->reference_field, $value, false);
} else {
@ -456,13 +456,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$list = array();
$name = $this->table->getIdentifier();
foreach($this->data as $record):
if(is_array($record) && isset($record[$name])) {
foreach ($this->data as $record) {
if (is_array($record) && isset($record[$name])) {
$list[] = $record[$name];
} else {
$list[] = $record->getIncremented();
}
endforeach;
};
return $list;
}
/**
@ -489,9 +489,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @return void
*/
public function set($key, Doctrine_Record $record) {
if(isset($this->reference_field))
if (isset($this->reference_field)) {
$record->set($this->reference_field, $this->reference, false);
}
$this->data[$key] = $record;
}
/**
@ -501,36 +501,37 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @return boolean
*/
public function add(Doctrine_Record $record,$key = null) {
if(isset($this->reference_field))
if (isset($this->reference_field)) {
$record->set($this->reference_field, $this->reference, false);
}
/**
* for some weird reason in_array cannot be used here (php bug ?)
*
* if used it results in fatal error : [ nesting level too deep ]
*/
foreach($this->data as $val) {
if($val === $record)
foreach ($this->data as $val) {
if ($val === $record) {
return false;
}
}
if(isset($key)) {
if(isset($this->data[$key]))
if (isset($key)) {
if (isset($this->data[$key])) {
return false;
}
$this->data[$key] = $record;
return true;
}
if(isset($this->keyColumn)) {
if (isset($this->keyColumn)) {
$value = $record->get($this->keyColumn);
if($value === null)
if ($value === null) {
throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
}
$this->data[$value] = $record;
} else
} else {
$this->data[] = $record;
}
return true;
}
/**
@ -542,12 +543,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function loadRelated($name = null) {
$query = new Doctrine_Query($this->table->getConnection());
if( ! isset($name)) {
foreach($this->data as $record):
if ( ! isset($name)) {
foreach ($this->data as $record) {
$value = $record->getIncremented();
if($value !== null)
if ($value !== null) {
$list[] = $value;
endforeach;
}
};
$query->from($this->table->getComponentName()."(".implode(", ",$this->table->getPrimaryKeys()).")");
$query->where($this->table->getComponentName().".id IN (".substr(str_repeat("?, ", count($list)),0,-2).")");
@ -560,16 +562,17 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$local = $rel->getLocal();
$list = array();
if($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) {
foreach($this->data as $record):
if ($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) {
foreach ($this->data as $record) {
$list[] = $record[$local];
endforeach;
};
} else {
foreach($this->data as $record):
foreach ($this->data as $record) {
$value = $record->getIncremented();
if($value !== null)
if ($value !== null) {
$list[] = $value;
endforeach;
}
};
}
$this->table->getRelation($name);
$dql = $rel->getRelationDql(count($list), 'collection');
@ -591,24 +594,25 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$foreign = $rel->getForeign();
$local = $rel->getLocal();
if($rel instanceof Doctrine_Relation_LocalKey) {
foreach($this->data as $key => $record) {
foreach($coll as $k => $related) {
if($related[$foreign] == $record[$local]) {
if ($rel instanceof Doctrine_Relation_LocalKey) {
foreach ($this->data as $key => $record) {
foreach ($coll as $k => $related) {
if ($related[$foreign] == $record[$local]) {
$this->data[$key]->setRelated($name, $related);
}
}
}
} elseif($rel instanceof Doctrine_Relation_ForeignKey) {
foreach($this->data as $key => $record) {
if($record->getState() == Doctrine_Record::STATE_TCLEAN ||
$record->getState() == Doctrine_Record::STATE_TDIRTY)
} elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
foreach ($this->data as $key => $record) {
if ($record->getState() == Doctrine_Record::STATE_TCLEAN
|| $record->getState() == Doctrine_Record::STATE_TDIRTY
) {
continue;
}
$sub = new Doctrine_Collection($table);
foreach($coll as $k => $related) {
if($related[$foreign] == $record[$local]) {
foreach ($coll as $k => $related) {
if ($related[$foreign] == $record[$local]) {
$sub->add($related);
$coll->remove($k);
}
@ -616,20 +620,20 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->data[$key]->setRelated($name, $sub);
}
} elseif($rel instanceof Doctrine_Relation_Association) {
} elseif ($rel instanceof Doctrine_Relation_Association) {
$identifier = $this->table->getIdentifier();
$asf = $rel->getAssociationFactory();
$name = $table->getComponentName();
foreach($this->data as $key => $record) {
if($record->getState() == Doctrine_Record::STATE_TCLEAN ||
$record->getState() == Doctrine_Record::STATE_TDIRTY)
foreach ($this->data as $key => $record) {
if ($record->getState() == Doctrine_Record::STATE_TCLEAN
|| $record->getState() == Doctrine_Record::STATE_TDIRTY
) {
continue;
}
$sub = new Doctrine_Collection($table);
foreach($coll as $k => $related) {
if($related->get($local) == $record[$identifier]) {
foreach ($coll as $k => $related) {
if ($related->get($local) == $record[$identifier]) {
$sub->add($related->get($name));
}
}
@ -659,9 +663,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
$conn->beginTransaction();
foreach($this as $key => $record):
foreach ($this as $key => $record) {
$record->save();
endforeach;
};
$conn->commit();
}
@ -679,7 +683,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$conn->beginTransaction();
foreach($this as $key => $record) {
foreach ($this as $key => $record) {
$record->delete();
}
@ -702,4 +706,3 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return Doctrine_Lib::getCollectionAsString($this);
}
}

View File

@ -53,9 +53,9 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
*/
public function setBatchSize($batchSize) {
$batchSize = (int) $batchSize;
if($batchSize <= 0)
if ($batchSize <= 0) {
return false;
}
$this->batchSize = $batchSize;
return true;
}
@ -75,40 +75,39 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @return boolean whether or not the load operation was successful
*/
public function load(Doctrine_Record $record) {
if(empty($this->data))
if (empty($this->data)) {
return false;
}
$id = $record->obtainIdentifier();
$identifier = $this->table->getIdentifier();
foreach($this->data as $key => $v) {
if(is_object($v)) {
if($v->obtainIdentifier() == $id)
foreach ($this->data as $key => $v) {
if (is_object($v)) {
if ($v->obtainIdentifier() == $id) {
break;
} elseif(is_array($v[$identifier])) {
if($v[$identifier] == $id)
}
} elseif (is_array($v[$identifier])) {
if ($v[$identifier] == $id) {
break;
}
}
}
$x = floor($key / $this->batchSize);
if( ! isset($this->loaded[$x])) {
if ( ! isset($this->loaded[$x])) {
$e = $x * $this->batchSize;
$e2 = ($x + 1)* $this->batchSize;
$a = array();
$proxies = array();
for($i = $e; $i < $e2 && $i < $this->count(); $i++):
if($this->data[$i] instanceof Doctrine_Record)
for ($i = $e; $i < $e2 && $i < $this->count(); $i++) {
if ($this->data[$i] instanceof Doctrine_Record) {
$id = $this->data[$i]->getIncremented();
elseif(is_array($this->data[$i]))
} elseif (is_array($this->data[$i])) {
$id = $this->data[$i][$identifier];
}
$a[$i] = $id;
endfor;
};
$c = count($a);
@ -120,14 +119,14 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
$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);
if($row === false)
if ($row === false) {
break;
}
$this->table->setData($row);
if(is_object($this->data[$k])) {
if (is_object($this->data[$k])) {
$this->data[$k]->factoryRefresh($this->table);
} else {
$this->data[$k] = $this->table->getRecord();
@ -148,30 +147,27 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @return object Doctrine_Record record
*/
public function get($key) {
if(isset($this->data[$key])) {
switch(gettype($this->data[$key])):
case "array":
// Doctrine_Record didn't exist in cache
$this->table->setData($this->data[$key]);
$this->data[$key] = $this->table->getProxy();
if (isset($this->data[$key])) {
switch (gettype($this->data[$key])) {
case "array":
// Doctrine_Record didn't exist in cache
$this->table->setData($this->data[$key]);
$this->data[$key] = $this->table->getProxy();
$this->data[$key]->addCollection($this);
$this->data[$key]->addCollection($this);
break;
endswitch;
};
} else {
$this->expand($key);
if( ! isset($this->data[$key]))
if ( ! isset($this->data[$key])) {
$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);
}
return $this->data[$key];
}
/**
@ -181,4 +177,3 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
return new Doctrine_Collection_Iterator_Expandable($this);
}
}

View File

@ -18,4 +18,3 @@ class Doctrine_Collection_Immediate extends Doctrine_Collection {
parent::__construct($table);
}
}

View File

@ -69,8 +69,9 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
public function rewind() {
$this->index = 0;
$i = $this->index;
if(isset($this->keys[$i]))
if (isset($this->keys[$i])) {
$this->key = $this->keys[$i];
}
}
/**
@ -97,10 +98,8 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
public function next() {
$this->index++;
$i = $this->index;
if(isset($this->keys[$i]))
if (isset($this->keys[$i])) {
$this->key = $this->keys[$i];
}
}
}

View File

@ -32,15 +32,14 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
*/
class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterator {
public function valid() {
if($this->index < $this->count)
if ($this->index < $this->count) {
return true;
elseif($this->index == $this->count) {
} elseif ($this->index == $this->count) {
$coll = $this->collection->expand($this->index);
if($coll instanceof Doctrine_Collection) {
if ($coll instanceof Doctrine_Collection) {
$count = count($coll);
if($count > 0) {
if ($count > 0) {
$this->keys = array_merge($this->keys, $coll->getKeys());
$this->count += $count;
return true;
@ -51,4 +50,3 @@ class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterat
}
}
}

View File

@ -38,4 +38,3 @@ class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator {
return ($this->index < $this->count);
}
}

View File

@ -33,5 +33,3 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
class Doctrine_Collection_Iterator_Offset extends Doctrine_Collection_Iterator {
public function valid() { }
}

View File

@ -22,4 +22,3 @@ class Doctrine_Collection_Lazy extends Doctrine_Collection_Batch {
parent::setBatchSize(1);
}
}

View File

@ -56,4 +56,3 @@ class Doctrine_Collection_Offset extends Doctrine_Collection {
return new Doctrine_Collection_Iterator_Expandable($this);
}
}

View File

@ -127,17 +127,17 @@ class Doctrine_Compiler {
$ret = array();
foreach($classes as $class) {
if($class !== 'Doctrine')
foreach ($classes as $class) {
if ($class !== 'Doctrine')
$class = 'Doctrine_'.$class;
$file = $path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php";
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.");
}
Doctrine::autoload($class);
$refl = new ReflectionClass ( $class );
$lines = file( $file );
@ -160,9 +160,9 @@ class Doctrine_Compiler {
// that we can use php_strip_whitespace (which only works on files)
$fp = @fopen($target, 'w');
if ($fp === false)
if ($fp === false) {
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $target");
}
fwrite($fp, "<?php".
" class InvalidKeyException extends Exception { }".
implode('', $ret)
@ -171,8 +171,9 @@ class Doctrine_Compiler {
$stripped = php_strip_whitespace($target);
$fp = @fopen($target, 'w');
if ($fp === false)
if ($fp === false) {
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $file");
}
fwrite($fp, $stripped);
fclose($fp);
}

View File

@ -61,87 +61,90 @@ abstract class Doctrine_Configurable {
* @return void
*/
public function setAttribute($attribute,$value) {
switch($attribute):
case Doctrine::ATTR_BATCH_SIZE:
if($value < 0)
throw new Doctrine_Exception("Batch size should be greater than or equal to zero");
switch ($attribute) {
case Doctrine::ATTR_BATCH_SIZE:
if ($value < 0) {
throw new Doctrine_Exception("Batch size should be greater than or equal to zero");
}
break;
case Doctrine::ATTR_FETCHMODE:
if($value < 0)
throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants.");
case Doctrine::ATTR_FETCHMODE:
if ($value < 0) {
throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants.");
}
break;
case Doctrine::ATTR_LISTENER:
$this->setEventListener($value);
case Doctrine::ATTR_LISTENER:
$this->setEventListener($value);
break;
case Doctrine::ATTR_LOCKMODE:
if($this instanceof Doctrine_Connection) {
if($this->transaction->getState() != Doctrine_Transaction::STATE_SLEEP)
case Doctrine::ATTR_LOCKMODE:
if ($this instanceof Doctrine_Connection) {
if ($this->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) {
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
}
} elseif ($this instanceof Doctrine_Manager) {
foreach ($this as $connection) {
if ($connection->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) {
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
} elseif($this instanceof Doctrine_Manager) {
foreach($this as $connection) {
if($connection->transaction->getState() != Doctrine_Transaction::STATE_SLEEP)
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
}
} else {
throw new Doctrine_Exception("Lockmode attribute can only be set at the global or connection level.");
}
} else {
throw new Doctrine_Exception("Lockmode attribute can only be set at the global or connection level.");
}
break;
case Doctrine::ATTR_CREATE_TABLES:
$value = (bool) $value;
case Doctrine::ATTR_CREATE_TABLES:
$value = (bool) $value;
break;
case Doctrine::ATTR_ACCESSORS:
$accessors = array('none','get','set','both');
case Doctrine::ATTR_ACCESSORS:
$accessors = array('none','get','set','both');
// if( ! in_array($value,$accessors))
// throw new Doctrine_Exception();
// if ( ! in_array($value,$accessors)) {
// throw new Doctrine_Exception();
// }
break;
case Doctrine::ATTR_COLL_LIMIT:
if($value < 1) {
throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1.");
}
case Doctrine::ATTR_COLL_LIMIT:
if ($value < 1) {
throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1.");
}
break;
case Doctrine::ATTR_COLL_KEY:
if( ! ($this instanceof Doctrine_Table))
throw new Doctrine_Exception("This attribute can only be set at table level.");
if( ! $this->hasColumn($value))
throw new Doctrine_Exception("Couldn't set collection key attribute. No such column '$value'");
case Doctrine::ATTR_COLL_KEY:
if ( ! ($this instanceof Doctrine_Table)) {
throw new Doctrine_Exception("This attribute can only be set at table level.");
}
if ( ! $this->hasColumn($value)) {
throw new Doctrine_Exception("Couldn't set collection key attribute. No such column '$value'");
}
break;
case Doctrine::ATTR_VLD:
case Doctrine::ATTR_AUTO_LENGTH_VLD:
case Doctrine::ATTR_AUTO_TYPE_VLD:
case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_QUOTE_IDENTIFIER:
case Doctrine::ATTR_PORTABILITY:
case Doctrine::ATTR_DEFAULT_TABLE_TYPE:
case Doctrine::ATTR_ACCESSOR_PREFIX_GET:
case Doctrine::ATTR_ACCESSOR_PREFIX_SET:
break;
case Doctrine::ATTR_VLD:
case Doctrine::ATTR_AUTO_LENGTH_VLD:
case Doctrine::ATTR_AUTO_TYPE_VLD:
case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_QUOTE_IDENTIFIER:
case Doctrine::ATTR_PORTABILITY:
case Doctrine::ATTR_DEFAULT_TABLE_TYPE:
case Doctrine::ATTR_ACCESSOR_PREFIX_GET:
case Doctrine::ATTR_ACCESSOR_PREFIX_SET:
case Doctrine::ATTR_SEQCOL_NAME:
if ( ! is_string($value)) {
throw new Doctrine_Exception('Sequence column name attribute only accepts string values');
}
break;
case Doctrine::ATTR_SEQCOL_NAME:
if( ! is_string($value))
throw new Doctrine_Exception('Sequence column name attribute only accepts string values');
case Doctrine::ATTR_FIELD_CASE:
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.');
break;
case Doctrine::ATTR_FIELD_CASE:
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.');
case Doctrine::ATTR_SEQNAME_FORMAT:
case Doctrine::ATTR_IDXNAME_FORMAT:
if ($this instanceof Doctrine_Table) {
throw new Doctrine_Exception('Sequence / index name format attributes cannot be set'
. 'at table level (only at connection or global level).');
}
break;
case Doctrine::ATTR_SEQNAME_FORMAT:
case Doctrine::ATTR_IDXNAME_FORMAT:
if($this instanceof Doctrine_Table) {
throw new Doctrine_Exception('Sequence / index name format attributes cannot be set'
. 'at table level (only at connection or global level).');
}
break;
default:
throw new Doctrine_Exception("Unknown attribute.");
endswitch;
default:
throw new Doctrine_Exception("Unknown attribute.");
};
$this->attributes[$attribute] = $value;
@ -160,9 +163,9 @@ abstract class Doctrine_Configurable {
* @return Doctrine_Db
*/
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]->add($listener, $name);
return $this;
@ -173,10 +176,10 @@ abstract class Doctrine_Configurable {
* @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable
*/
public function getListener() {
if( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
if(isset($this->parent))
if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
if (isset($this->parent)) {
return $this->parent->getListener();
}
return null;
}
return $this->attributes[Doctrine::ATTR_LISTENER];
@ -188,10 +191,11 @@ abstract class Doctrine_Configurable {
* @return Doctrine_Db
*/
public function setListener($listener) {
if( ! ($listener instanceof Doctrine_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
if ( ! ($listener instanceof Doctrine_EventListener_Interface)
&& ! ($listener instanceof 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;
return $this;
@ -205,13 +209,13 @@ abstract class Doctrine_Configurable {
public function getAttribute($attribute) {
$attribute = (int) $attribute;
if($attribute < 1 || $attribute > 23)
if ($attribute < 1 || $attribute > 23)
throw new Doctrine_Exception('Unknown attribute.');
if( ! isset($this->attributes[$attribute])) {
if(isset($this->parent))
if ( ! isset($this->attributes[$attribute])) {
if (isset($this->parent)) {
return $this->parent->getAttribute($attribute);
}
return null;
}
return $this->attributes[$attribute];
@ -245,4 +249,3 @@ abstract class Doctrine_Configurable {
return $this->parent;
}
}

View File

@ -110,9 +110,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param PDO|Doctrine_Adapter_Interface $adapter database driver
*/
public function __construct(Doctrine_Manager $manager, $adapter) {
if( ! ($adapter instanceof PDO) && ! in_array('Doctrine_Adapter_Interface', class_implements($adapter)))
if ( ! ($adapter instanceof PDO) && ! in_array('Doctrine_Adapter_Interface', class_implements($adapter))) {
throw new Doctrine_Connection_Exception("First argument should be an instance of PDO or implement Doctrine_Adapter_Interface");
}
$this->dbh = $adapter;
//$this->modules['transaction'] = new Doctrine_Connection_Transaction($this);
@ -148,20 +148,20 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return Doctrine_Connection_Module connection module
*/
public function __get($name) {
if(isset($this->properties[$name]))
if (isset($this->properties[$name]))
return $this->properties[$name];
if( ! isset($this->modules[$name]))
if ( ! isset($this->modules[$name])) {
throw new Doctrine_Connection_Exception('Unknown module / property ' . $name);
if($this->modules[$name] === false) {
switch($name) {
case 'unitOfWork':
$this->modules[$name] = new Doctrine_Connection_UnitOfWork($this);
}
if ($this->modules[$name] === false) {
switch ($name) {
case 'unitOfWork':
$this->modules[$name] = new Doctrine_Connection_UnitOfWork($this);
break;
default:
$class = 'Doctrine_' . ucwords($name) . '_' . $this->getName();
$this->modules[$name] = new $class($this);
default:
$class = 'Doctrine_' . ucwords($name) . '_' . $this->getName();
$this->modules[$name] = new $class($this);
}
}
@ -261,9 +261,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return boolean whether or not this drivers supports given feature
*/
public function supports($feature) {
return (isset($this->supported[$feature]) &&
$this->supported[$feature] === 'emulated' ||
$this->supported[$feature]);
return (isset($this->supported[$feature])
&& ($this->supported[$feature] === 'emulated'
|| $this->supported[$feature]
)
);
}
/**
* quote
@ -274,25 +276,25 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return mixed
*/
public function quote($input, $type = null) {
if($type == null) {
if ($type == null) {
$type = gettype($input);
}
switch($type) {
case 'integer':
case 'enum':
case 'boolean':
return $input;
case 'array':
case 'object':
$input = serialize($input);
case 'string':
case 'char':
case 'varchar':
case 'text':
case 'gzip':
case 'blob':
case 'clob':
return $this->dbh->quote($input);
switch ($type) {
case 'integer':
case 'enum':
case 'boolean':
return $input;
case 'array':
case 'object':
$input = serialize($input);
case 'string':
case 'char':
case 'varchar':
case 'text':
case 'gzip':
case 'blob':
case 'clob':
return $this->dbh->quote($input);
}
}
/**
@ -380,20 +382,19 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return integer number of rows affected
*/
public function replace($table, array $fields, array $keys) {
//if( ! $this->supports('replace'))
//if ( ! $this->supports('replace'))
// throw new Doctrine_Connection_Exception('replace query is not supported');
if(empty($keys))
if (empty($keys)) {
throw new Doctrine_Connection_Exception('Not specified which fields are keys');
}
$condition = $values = array();
foreach($fields as $name => $value) {
foreach ($fields as $name => $value) {
$values[$name] = $value;
if(in_array($name, $keys)) {
if($value === null)
if (in_array($name, $keys)) {
if ($value === null)
throw new Doctrine_Connection_Exception('key value '.$name.' may not be null');
$condition[] = $name . ' = ?';
@ -419,9 +420,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return boolean
*/
public function insert($table, array $values = array()) {
if(empty($values))
if (empty($values)) {
return false;
}
// column names are specified as array keys
$cols = array_keys($values);
@ -505,9 +506,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function fetchColumn($statement, array $params = array()) {
$result = $this->query($statement, $params)->fetchAll(PDO::FETCH_COLUMN);
if($this->options['portability'] & Doctrine::PORTABILITY_FIX_CASE)
if ($this->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result;
}
/**
@ -530,8 +531,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function fetchBoth($statement, array $params = array()) {
return $this->query($statement, $params)->fetchAll(PDO::FETCH_BOTH);
}
/**
* query
* queries the database using Doctrine Query Language
@ -576,9 +575,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$parser = new Doctrine_Query($this);
$coll = $parser->query($query, $params);
if( ! $coll->contains(0))
if ( ! $coll->contains(0)) {
return false;
}
return $coll[0];
}
/**
@ -591,9 +590,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return PDOStatement
*/
public function select($query,$limit = 0,$offset = 0) {
if($limit > 0 || $offset > 0)
if ($limit > 0 || $offset > 0) {
$query = $this->modifyLimitQuery($query, $limit, $offset);
}
return $this->dbh->query($query);
}
/**
@ -605,7 +604,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/
public function execute($query, array $params = array()) {
try {
if( ! empty($params)) {
if ( ! empty($params)) {
$stmt = $this->dbh->prepare($query);
$stmt->execute($params);
return $stmt;
@ -626,7 +625,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/
public function exec($query, array $params = array()) {
try {
if( ! empty($params)) {
if ( ! empty($params)) {
$stmt = $this->dbh->prepare($query);
$stmt->execute($params);
return $stmt;
@ -647,9 +646,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$name = 'Doctrine_Connection_' . $this->driverName . '_Exception';
$exc = new $name($e->getMessage(), (int) $e->getCode());
if( ! is_array($e->errorInfo))
if ( ! is_array($e->errorInfo)) {
$e->errorInfo = array(null, null, null, null);
}
$exc->processErrorInfo($e->errorInfo);
throw $exc;
@ -671,15 +670,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return object Doctrine_Table
*/
public function getTable($name) {
if(isset($this->tables[$name]))
if (isset($this->tables[$name])) {
return $this->tables[$name];
}
$class = $name."Table";
if(class_exists($class) && in_array("Doctrine_Table", class_parents($class))) {
if (class_exists($class) && in_array("Doctrine_Table", class_parents($class))) {
return new $class($name, $this);
} else {
return new Doctrine_Table($name, $this);
}
}
@ -696,7 +694,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* initialized table objects
*
* <code>
* foreach($conn as $index => $table) {
* foreach ($conn as $index => $table) {
* print $table; // get a string representation of each table object
* }
* </code>
@ -724,9 +722,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function addTable(Doctrine_Table $objTable) {
$name = $objTable->getComponentName();
if(isset($this->tables[$name]))
if (isset($this->tables[$name])) {
return false;
}
$this->tables[$name] = $objTable;
return true;
}
@ -761,7 +759,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return void
*/
public function clear() {
foreach($this->tables as $k => $table) {
foreach ($this->tables as $k => $table) {
$table->getRepository()->evictAll();
$table->clear();
}
@ -839,20 +837,19 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function save(Doctrine_Record $record) {
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record);
switch($record->getState()):
case Doctrine_Record::STATE_TDIRTY:
$this->unitOfWork->insert($record);
switch ($record->getState()) {
case Doctrine_Record::STATE_TDIRTY:
$this->unitOfWork->insert($record);
break;
case Doctrine_Record::STATE_DIRTY:
case Doctrine_Record::STATE_PROXY:
$this->unitOfWork->update($record);
case Doctrine_Record::STATE_DIRTY:
case Doctrine_Record::STATE_PROXY:
$this->unitOfWork->update($record);
break;
case Doctrine_Record::STATE_CLEAN:
case Doctrine_Record::STATE_TCLEAN:
// do nothing
case Doctrine_Record::STATE_CLEAN:
case Doctrine_Record::STATE_TCLEAN:
// do nothing
break;
endswitch;
};
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record);
}
@ -865,9 +862,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return boolean true on success, false on failure
*/
public function delete(Doctrine_Record $record) {
if( ! $record->exists())
if ( ! $record->exists()) {
return false;
}
$this->beginTransaction();
$record->getTable()->getListener()->onPreDelete($record);

View File

@ -19,15 +19,14 @@ class Doctrine_Connection_Common extends Doctrine_Connection {
* @param mixed $offset
*/
public function modifyLimitQuery($query,$limit = false,$offset = false,$isManip=false) {
if($limit && $offset) {
if ($limit && $offset) {
$query .= " LIMIT ".$limit." OFFSET ".$offset;
} elseif($limit && ! $offset) {
} elseif ($limit && ! $offset) {
$query .= " LIMIT ".$limit;
} elseif( ! $limit && $offset) {
} elseif ( ! $limit && $offset) {
$query .= " LIMIT 999999999999 OFFSET ".$offset;
}
return $query;
}
}

View File

@ -40,24 +40,23 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection {
* @return string the modified query
*/
public function modifyLimitQuery($query, $limit, $offset) {
if($limit <= 0)
return $sql;
if ($limit <= 0)
return $sql;
if($offset == 0) {
return $sql . ' FETCH FIRST '. $count .' ROWS ONLY';
} else {
if ($offset == 0) {
return $sql . ' FETCH FIRST '. $count .' ROWS ONLY';
} else {
$sqlPieces = explode('from', $sql);
$select = $sqlPieces[0];
$table = $sqlPieces[1];
$sqlPieces = explode('from', $sql);
$select = $sqlPieces[0];
$table = $sqlPieces[1];
$col = explode('select', $select);
$col = explode('select', $select);
$sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' .
'OVER(ORDER BY ' . $col[1] . ') AS dctrn_rownum FROM ' . $table . ')' .
$select . 'FROM OFFSET WHERE dctrn_rownum BETWEEN ' . $offset .
'AND ' . ($offset + $count - 1);
return $sql;
}
$sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' .
'OVER(ORDER BY ' . $col[1] . ') AS dctrn_rownum FROM ' . $table . ')' .
$select . 'FROM OFFSET WHERE dctrn_rownum BETWEEN ' . $offset .
'AND ' . ($offset + $count - 1);
return $sql;
}
}
}

View File

@ -95,7 +95,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
* @return string modified query
*/
public function modifyLimitQuery($query, $limit, $offset) {
if($limit > 0) {
if ($limit > 0) {
$query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i',
"SELECT FIRST $limit SKIP $offset", $query);
}
@ -112,4 +112,3 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
return $data[0];
}
}

View File

@ -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])) {
$errorInfo[3] = $code;
break;
}
}
if(isset(self::$errorCodeMap[$errorInfo[1]]))
if (isset(self::$errorCodeMap[$errorInfo[1]])) {
$errorInfo[3] = self::$errorCodeMap[$errorInfo[1]];
}
return $errorInfo;
}
}

View File

@ -44,9 +44,9 @@ class Doctrine_Connection_Module {
* module holds an instance of Doctrine_Connection
*/
public function __construct($conn = null) {
if( ! ($conn instanceof Doctrine_Connection))
if ( ! ($conn instanceof Doctrine_Connection)) {
$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->conn = $conn;
$e = explode('_', get_class($this));

View File

@ -104,13 +104,12 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
* @return string
*/
public function modifyLimitQuery($query, $limit, $offset, $isManip = false) {
if($limit > 0) {
if ($limit > 0) {
// we need the starting SELECT clause for later
$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 ';
}
$length = strlen($select);
// is there an offset?
@ -168,4 +167,3 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
return $this->queryOne($query);
}
}

View File

@ -63,7 +63,7 @@ class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception
*/
public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) {
if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code];
return true;
}

View File

@ -85,7 +85,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$this->properties['varchar_max_length'] = 255;
parent::__construct($manager, $adapter);
}
/**
@ -118,7 +117,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$value = $this->dbh->lastInsertId();
if(is_numeric($value)) {
if (is_numeric($value)) {
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
$result = $this->dbh->query($query);
}
@ -205,17 +204,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$query = $values = '';
$keys = $colnum = 0;
for(reset($fields); $colnum < $count; next($fields), $colnum++) {
for (reset($fields); $colnum < $count; next($fields), $colnum++) {
$name = key($fields);
if($colnum > 0) {
if ($colnum > 0) {
$query .= ',';
$values.= ',';
}
$query .= $name;
if(isset($fields[$name]['null']) && $fields[$name]['null']) {
if (isset($fields[$name]['null']) && $fields[$name]['null']) {
$value = 'NULL';
} else {
$type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
@ -224,18 +223,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$values .= $value;
if(isset($fields[$name]['key']) && $fields[$name]['key']) {
if($value === 'NULL')
if (isset($fields[$name]['key']) && $fields[$name]['key']) {
if ($value === 'NULL') {
throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL');
}
$keys++;
}
}
if($keys == 0)
if ($keys == 0) {
throw new Doctrine_Connection_Mysql_Exception('not specified which fields are keys');
}
$query = 'REPLACE INTO ' . $table . ' (' . $query . ') VALUES (' . $values . ')';
return $this->dbh->exec($query);

View File

@ -73,7 +73,7 @@ class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception
*/
public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) {
if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code];
return true;
}

View File

@ -36,7 +36,6 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
*/
protected $driverName = 'Oracle';
public function __construct(Doctrine_Manager $manager, $adapter) {
$this->supported = array(
'sequences' => true,
@ -127,4 +126,3 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
return $data[0];
}
}

View File

@ -68,7 +68,7 @@ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception
*/
public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) {
if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code];
return true;
}

View File

@ -132,10 +132,10 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
. $from . ' ' . $where . ' LIMIT ' . $limit . ')';
} else {
if($limit !== false) {
if ($limit !== false) {
$query .= ' LIMIT ' . $limit;
}
if($offset !== false) {
if ($offset !== false) {
$query .= ' OFFSET ' . $offset;
}
}
@ -153,12 +153,12 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
$serverInfo = $this->fetchOne($query);
if( ! $native) {
if ( ! $native) {
$tmp = explode('.', $server_info, 3);
if(empty($tmp[2]) && isset($tmp[1])
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)) {
if (empty($tmp[2]) && isset($tmp[1])
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)
) {
$serverInfo = array(
'major' => $tmp[0],
'minor' => $tmp2[1],

View File

@ -96,4 +96,3 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
return $data[0];
}
}

View File

@ -63,8 +63,8 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception
* (the process is successfull if portable error code was found)
*/
public function processErrorInfo(array $errorInfo) {
foreach(self::$errorRegexps as $regexp => $code) {
if(preg_match($regexp, $errorInfo[2])) {
foreach (self::$errorRegexps as $regexp => $code) {
if (preg_match($regexp, $errorInfo[2])) {
$this->portableCode = $code;
return true;

View File

@ -44,16 +44,16 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
*/
public function buildFlushTree(array $tables) {
$tree = array();
foreach($tables as $k => $table) {
foreach ($tables as $k => $table) {
$k = $k.$table;
if( ! ($table instanceof Doctrine_Table))
if ( ! ($table instanceof Doctrine_Table)) {
$table = $this->conn->getTable($table);
}
$nm = $table->getComponentName();
$index = array_search($nm,$tree);
if($index === false) {
if ($index === false) {
$tree[] = $nm;
$index = max(array_keys($tree));
}
@ -62,25 +62,25 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
// group relations
foreach($rels as $key => $rel) {
if($rel instanceof Doctrine_Relation_ForeignKey) {
foreach ($rels as $key => $rel) {
if ($rel instanceof Doctrine_Relation_ForeignKey) {
unset($rels[$key]);
array_unshift($rels, $rel);
}
}
foreach($rels as $rel) {
foreach ($rels as $rel) {
$name = $rel->getTable()->getComponentName();
$index2 = array_search($name,$tree);
$type = $rel->getType();
// skip self-referenced relations
if($name === $nm)
if ($name === $nm)
continue;
if($rel instanceof Doctrine_Relation_ForeignKey) {
if($index2 !== false) {
if($index2 >= $index)
if ($rel instanceof Doctrine_Relation_ForeignKey) {
if ($index2 !== false) {
if ($index2 >= $index)
continue;
unset($tree[$index]);
@ -90,9 +90,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$tree[] = $name;
}
} elseif($rel instanceof Doctrine_Relation_LocalKey) {
if($index2 !== false) {
if($index2 <= $index)
} elseif ($rel instanceof Doctrine_Relation_LocalKey) {
if ($index2 !== false) {
if ($index2 <= $index)
continue;
unset($tree[$index2]);
@ -101,11 +101,11 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
array_unshift($tree,$name);
$index++;
}
} elseif($rel instanceof Doctrine_Relation_Association) {
} elseif ($rel instanceof Doctrine_Relation_Association) {
$t = $rel->getAssociationFactory();
$n = $t->getComponentName();
if($index2 !== false)
if ($index2 !== false)
unset($tree[$index2]);
array_splice($tree,$index, 0,$name);
@ -113,8 +113,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$index3 = array_search($n,$tree);
if($index3 !== false) {
if($index3 >= $index)
if ($index3 !== false) {
if ($index3 >= $index)
continue;
unset($tree[$index]);
@ -137,29 +137,30 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
*/
public function saveRelated(Doctrine_Record $record) {
$saveLater = array();
foreach($record->getReferences() as $k=>$v) {
foreach ($record->getReferences() as $k=>$v) {
$fk = $record->getTable()->getRelation($k);
if($fk instanceof Doctrine_Relation_ForeignKey ||
if ($fk instanceof Doctrine_Relation_ForeignKey ||
$fk instanceof Doctrine_Relation_LocalKey) {
if($fk->isComposite()) {
if ($fk->isComposite()) {
$local = $fk->getLocal();
$foreign = $fk->getForeign();
if($record->getTable()->hasPrimaryKey($fk->getLocal())) {
if( ! $record->exists())
if ($record->getTable()->hasPrimaryKey($fk->getLocal())) {
if ( ! $record->exists()) {
$saveLater[$k] = $fk;
else
} else {
$v->save();
}
} else {
// ONE-TO-ONE relationship
$obj = $record->get($fk->getTable()->getComponentName());
if($obj->getState() != Doctrine_Record::STATE_TCLEAN)
if ($obj->getState() != Doctrine_Record::STATE_TCLEAN) {
$obj->save();
}
}
}
} elseif($fk instanceof Doctrine_Relation_Association) {
} elseif ($fk instanceof Doctrine_Relation_Association) {
$v->save();
}
}
@ -181,7 +182,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @return void
*/
public function saveAssociations(Doctrine_Record $record) {
foreach($record->getTable()->getRelations() as $rel) {
foreach ($record->getTable()->getRelations() as $rel) {
$table = $rel->getTable();
$alias = $rel->getAlias();
@ -196,14 +197,14 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @return void
*/
public function deleteComposites(Doctrine_Record $record) {
foreach($record->getTable()->getRelations() as $fk) {
switch($fk->getType()):
case Doctrine_Relation::ONE_COMPOSITE:
case Doctrine_Relation::MANY_COMPOSITE:
$obj = $record->get($fk->getAlias());
$obj->delete();
foreach ($record->getTable()->getRelations() as $fk) {
switch ($fk->getType()) {
case Doctrine_Relation::ONE_COMPOSITE:
case Doctrine_Relation::MANY_COMPOSITE:
$obj = $record->get($fk->getAlias());
$obj->delete();
break;
endswitch;
};
}
}
/**
@ -218,19 +219,19 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$tree = $this->buildFlushTree($this->conn->getTables());
// save all records
foreach($tree as $name) {
foreach ($tree as $name) {
$table = $this->conn->getTable($name);
foreach($table->getRepository() as $record) {
foreach ($table->getRepository() as $record) {
$this->conn->save($record);
}
}
// save all associations
foreach($tree as $name) {
foreach ($tree as $name) {
$table = $this->conn->getTable($name);
foreach($table->getRepository() as $record) {
foreach ($table->getRepository() as $record) {
$this->saveAssociations($record);
}
}
@ -246,36 +247,34 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$array = $record->getPrepared();
if(empty($array))
if (empty($array)) {
return false;
}
$set = array();
foreach($array as $name => $value):
foreach ($array as $name => $value) {
$set[] = $name." = ?";
if($value instanceof Doctrine_Record) {
switch($value->getState()):
case Doctrine_Record::STATE_TCLEAN:
case Doctrine_Record::STATE_TDIRTY:
$record->save();
default:
$array[$name] = $value->getIncremented();
$record->set($name, $value->getIncremented());
endswitch;
if ($value instanceof Doctrine_Record) {
switch ($value->getState()) {
case Doctrine_Record::STATE_TCLEAN:
case Doctrine_Record::STATE_TDIRTY:
$record->save();
default:
$array[$name] = $value->getIncremented();
$record->set($name, $value->getIncremented());
};
}
endforeach;
};
$params = array_values($array);
$id = $record->obtainIdentifier();
if( ! is_array($id))
if ( ! is_array($id)) {
$id = array($id);
}
$id = array_values($id);
$params = array_merge($params, $id);
$sql = 'UPDATE ' . $record->getTable()->getTableName()
. ' SET ' . implode(', ', $set)
. ' WHERE ' . implode(' = ? AND ', $record->getTable()->getPrimaryKeys())
@ -302,16 +301,15 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$array = $record->getPrepared();
if(empty($array))
if (empty($array)) {
return false;
}
$table = $record->getTable();
$keys = $table->getPrimaryKeys();
$seq = $record->getTable()->getSequenceName();
if( ! empty($seq)) {
if ( ! empty($seq)) {
$id = $this->nextId($seq);
$name = $record->getTable()->getIdentifier();
$array[$name] = $id;
@ -319,15 +317,16 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$this->conn->insert($table->getTableName(), $array);
if(count($keys) == 1 && $keys[0] == $table->getIdentifier()) {
if (count($keys) == 1 && $keys[0] == $table->getIdentifier()) {
$id = $this->conn->getDBH()->lastInsertID();
if( ! $id)
if ( ! $id)
$id = $table->getMaxIdentifier();
$record->assignIdentifier($id);
} else
} else {
$record->assignIdentifier(true);
}
// listen the onInsert event
$table->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record);

View File

@ -54,39 +54,39 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
* declare the specified field.
*/
public function getNativeDeclaration($field) {
switch($field['type']) {
case 'varchar':
case 'string':
case 'array':
case 'object':
case 'char':
case 'text':
$length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length'];
switch ($field['type']) {
case 'varchar':
case 'string':
case 'array':
case 'object':
case 'char':
case 'text':
$length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')';
case 'clob':
return 'BLOB SUB_TYPE 1';
case 'blob':
return 'BLOB SUB_TYPE 0';
case 'integer':
case 'enum':
return 'INT';
case 'boolean':
return 'SMALLINT';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'TIMESTAMP';
case 'float':
return 'DOUBLE PRECISION';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')';
case 'clob':
return 'BLOB SUB_TYPE 1';
case 'blob':
return 'BLOB SUB_TYPE 0';
case 'integer':
case 'enum':
return 'INT';
case 'boolean':
return 'SMALLINT';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'TIMESTAMP';
case 'float':
return 'DOUBLE PRECISION';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
}
return '';
}
@ -99,7 +99,7 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
public function getPortableDeclaration($field) {
$length = $field['length'];
if((int) $length <= 0)
if ((int) $length <= 0)
$length = null;
$type = array();
@ -108,67 +108,67 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
$field['field_sub_type'] = !empty($field['field_sub_type'])
? strtolower($field['field_sub_type']) : null;
switch ($db_type) {
case 'smallint':
case 'integer':
case 'int64':
//these may be 'numeric' or 'decimal'
if (isset($field['field_sub_type'])) {
$field['type'] = $field['field_sub_type'];
return $this->mapNativeDatatype($field);
case 'smallint':
case 'integer':
case 'int64':
//these may be 'numeric' or 'decimal'
if (isset($field['field_sub_type'])) {
$field['type'] = $field['field_sub_type'];
return $this->mapNativeDatatype($field);
}
case 'bigint':
case 'quad':
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
case 'bigint':
case 'quad':
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
break;
case 'varchar':
$fixed = false;
case 'char':
case 'cstring':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
break;
case 'varchar':
$fixed = false;
case 'char':
case 'cstring':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'double precision':
case 'd_float':
$type[] = 'float';
break;
case 'decimal':
case 'numeric':
$type[] = 'decimal';
break;
case 'blob':
$type[] = ($field['field_sub_type'] == 'text') ? 'clob' : 'blob';
$length = null;
break;
default:
throw new Doctrine_DataDict_Firebird_Exception('unknown database attribute type: '.$db_type);
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'double precision':
case 'd_float':
$type[] = 'float';
break;
case 'decimal':
case 'numeric':
$type[] = 'decimal';
break;
case 'blob':
$type[] = ($field['field_sub_type'] == 'text') ? 'clob' : 'blob';
$length = null;
break;
default:
throw new Doctrine_DataDict_Firebird_Exception('unknown database attribute type: '.$db_type);
}
return array($type, $length, $unsigned, $fixed);

View File

@ -55,52 +55,51 @@ class Doctrine_DataDict_Informix extends Doctrine_DataDict {
*/
public function getNativeDeclaration($field) {
switch ($field['type']) {
case 'char':
case 'varchar':
case 'array':
case 'object':
case 'string':
if (empty($field['length']) && array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length;
}
case 'char':
case 'varchar':
case 'array':
case 'object':
case 'string':
if (empty($field['length']) && array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length;
}
$length = (! empty($field['length'])) ? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
$length = (! empty($field['length'])) ? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR('.$length.')' : 'NVARCHAR');
case 'clob':
return 'TEXT';
case 'blob':
return 'BLOB';
case 'integer':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 1) {
return 'SMALLINT';
} elseif ($length == 2) {
return 'SMALLINT';
} elseif ($length == 3 || $length == 4) {
return 'INTEGER';
} elseif ($length > 4) {
return 'DECIMAL(20)';
}
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR('.$length.')' : 'NVARCHAR');
case 'clob':
return 'TEXT';
case 'blob':
return 'BLOB';
case 'integer':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 1) {
return 'SMALLINT';
} elseif ($length == 2) {
return 'SMALLINT';
} elseif ($length == 3 || $length == 4) {
return 'INTEGER';
} elseif ($length > 4) {
return 'DECIMAL(20)';
}
return 'INT';
case 'boolean':
return 'SMALLINT';
case 'date':
return 'DATE';
case 'time':
return 'DATETIME YEAR TO SECOND';
case 'timestamp':
return 'DATETIME';
case 'float':
return 'FLOAT';
case 'decimal':
return 'DECIMAL';
}
return 'INT';
case 'boolean':
return 'SMALLINT';
case 'date':
return 'DATE';
case 'time':
return 'DATETIME YEAR TO SECOND';
case 'timestamp':
return 'DATETIME';
case 'float':
return 'FLOAT';
case 'decimal':
return 'DECIMAL';
}
return '';
}
}

View File

@ -57,51 +57,51 @@ class Doctrine_DataDict_Mssql extends Doctrine_DataDict {
*/
public function getNativeDeclaration($field) {
switch ($field['type']) {
case 'array':
case 'object':
case 'text':
case 'char':
case 'varchar':
case 'string':
$length = !empty($field['length'])
? $field['length'] : false;
case 'array':
case 'object':
case 'text':
case 'char':
case 'varchar':
case 'string':
$length = !empty($field['length'])
? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return 'VARCHAR('.$length.')';
}
}
return 'TEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return "VARBINARY($length)";
}
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return 'VARCHAR('.$length.')';
}
return 'IMAGE';
case 'integer':
case 'enum':
return 'INT';
case 'boolean':
return 'BIT';
case 'date':
return 'CHAR(' . strlen('YYYY-MM-DD') . ')';
case 'time':
return 'CHAR(' . strlen('HH:MM:SS') . ')';
case 'timestamp':
return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
case 'float':
return 'FLOAT';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
}
return 'TEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return "VARBINARY($length)";
}
}
return 'IMAGE';
case 'integer':
case 'enum':
return 'INT';
case 'boolean':
return 'BIT';
case 'date':
return 'CHAR(' . strlen('YYYY-MM-DD') . ')';
case 'time':
return 'CHAR(' . strlen('HH:MM:SS') . ')';
case 'timestamp':
return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
case 'float':
return 'FLOAT';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
}
return '';
}
@ -121,48 +121,48 @@ class Doctrine_DataDict_Mssql extends Doctrine_DataDict {
// todo: unsigned handling seems to be missing
$unsigned = $fixed = null;
switch ($db_type) {
case 'bit':
$type[0] = 'boolean';
break;
case 'int':
$type[0] = 'integer';
break;
case 'datetime':
$type[0] = 'timestamp';
break;
case 'float':
case 'real':
case 'numeric':
$type[0] = 'float';
break;
case 'decimal':
case 'money':
$type[0] = 'decimal';
break;
case 'text':
case 'varchar':
$fixed = false;
case 'char':
$type[0] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^[is|has]/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
case 'bit':
$type[0] = 'boolean';
break;
case 'int':
$type[0] = 'integer';
break;
case 'datetime':
$type[0] = 'timestamp';
break;
case 'float':
case 'real':
case 'numeric':
$type[0] = 'float';
break;
case 'decimal':
case 'money':
$type[0] = 'decimal';
break;
case 'text':
case 'varchar':
$fixed = false;
case 'char':
$type[0] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^[is|has]/', $field['name'])) {
$type = array_reverse($type);
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'image':
case 'varbinary':
$type[] = 'blob';
$length = null;
break;
default:
throw new Doctrine_DataDict_Mssql_Exception('unknown database attribute type: '.$db_type);
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'image':
case 'varbinary':
$type[] = 'blob';
$length = null;
break;
default:
throw new Doctrine_DataDict_Mssql_Exception('unknown database attribute type: '.$db_type);
}
return array($type, $length, $unsigned, $fixed);

View File

@ -133,82 +133,82 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
public function getNativeDeclaration($field)
{
switch ($field['type']) {
case 'char':
$length = (! empty($field['length'])) ? $field['length'] : false;
case 'char':
$length = (! empty($field['length'])) ? $field['length'] : false;
return $length ? 'CHAR('.$length.')' : 'CHAR(255)';
case 'varchar':
case 'array':
case 'object':
case 'string':
return $length ? 'CHAR('.$length.')' : 'CHAR(255)';
case 'varchar':
case 'array':
case 'object':
case 'string':
if ( ! isset($field['length'])) {
if(array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length;
} else {
$field['length'] = false;
}
if ( ! isset($field['length'])) {
if (array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length;
} else {
$field['length'] = false;
}
}
$length = ($field['length'] < $this->conn->varchar_max_length) ? $field['length'] : false;
$fixed = (isset($field['fixed'])) ? $field['fixed'] : false;
$length = ($field['length'] < $this->conn->varchar_max_length) ? $field['length'] : false;
$fixed = (isset($field['fixed'])) ? $field['fixed'] : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
case 'clob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYTEXT';
} elseif ($length <= 65532) {
return 'TEXT';
} elseif ($length <= 16777215) {
return 'MEDIUMTEXT';
}
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
case 'clob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYTEXT';
} elseif ($length <= 65532) {
return 'TEXT';
} elseif ($length <= 16777215) {
return 'MEDIUMTEXT';
}
return 'LONGTEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYBLOB';
} elseif ($length <= 65532) {
return 'BLOB';
} elseif ($length <= 16777215) {
return 'MEDIUMBLOB';
}
}
return 'LONGTEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYBLOB';
} elseif ($length <= 65532) {
return 'BLOB';
} elseif ($length <= 16777215) {
return 'MEDIUMBLOB';
}
return 'LONGBLOB';
case 'integer':
case 'enum':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 1) {
return 'TINYINT';
} elseif ($length == 2) {
return 'SMALLINT';
} elseif ($length == 3) {
return 'MEDIUMINT';
} elseif ($length == 4) {
return 'INT';
} elseif ($length > 4) {
return 'BIGINT';
}
}
return 'LONGBLOB';
case 'integer':
case 'enum':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 1) {
return 'TINYINT';
} elseif ($length == 2) {
return 'SMALLINT';
} elseif ($length == 3) {
return 'MEDIUMINT';
} elseif ($length == 4) {
return 'INT';
} elseif ($length > 4) {
return 'BIGINT';
}
return 'INT';
case 'boolean':
return 'TINYINT(1)';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'DATETIME';
case 'float':
return 'DOUBLE';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL(' . $length . ',' . 0 . ')'; //$this->dbh->options['decimal_places'] . ')';
}
return 'INT';
case 'boolean':
return 'TINYINT(1)';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'DATETIME';
case 'float':
return 'DOUBLE';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL(' . $length . ',' . 0 . ')'; //$this->dbh->options['decimal_places'] . ')';
}
return '';
}
@ -234,122 +234,122 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
$type = array();
$unsigned = $fixed = null;
switch ($dbType) {
case 'tinyint':
$type[] = 'integer';
case 'tinyint':
$type[] = 'integer';
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 1;
break;
case 'smallint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 2;
break;
case 'mediumint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 3;
break;
case 'int':
case 'integer':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 4;
break;
case 'bigint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8;
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
case 'text':
case 'varchar':
$fixed = false;
case 'string':
case 'char':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 1;
break;
case 'smallint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 2;
break;
case 'mediumint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 3;
break;
case 'int':
case 'integer':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 4;
break;
case 'bigint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8;
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
case 'text':
case 'varchar':
$fixed = false;
case 'string':
case 'char':
$type[] = 'text';
if ($length == '1') {
} elseif (strstr($dbType, 'text')) {
$type[] = 'clob';
if ($decimal == 'binary') {
$type[] = 'blob';
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'enum':
$type[] = 'text';
preg_match_all('/\'.+\'/U', $field['type'], $matches);
$length = 0;
$fixed = false;
if (is_array($matches)) {
foreach ($matches[0] as $value) {
$length = max($length, strlen($value)-2);
}
if ($length == '1' && count($matches[0]) == 2) {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($dbType, 'text')) {
$type[] = 'clob';
if ($decimal == 'binary') {
$type[] = 'blob';
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'enum':
$type[] = 'text';
preg_match_all('/\'.+\'/U', $field['type'], $matches);
$length = 0;
$fixed = false;
if (is_array($matches)) {
foreach ($matches[0] as $value) {
$length = max($length, strlen($value)-2);
}
if ($length == '1' && count($matches[0]) == 2) {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
}
$type[] = 'integer';
case 'set':
$fixed = false;
$type[] = 'text';
$type[] = 'integer';
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'real':
$type[] = 'float';
$unsigned = preg_match('/ unsigned/i', $field['type']);
break;
case 'unknown':
case 'decimal':
case 'numeric':
$type[] = 'decimal';
$unsigned = preg_match('/ unsigned/i', $field['type']);
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
$type[] = 'blob';
$length = null;
break;
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
throw new Doctrine_DataDict_Mysql_Exception('unknown database attribute type: '.$dbType);
}
$type[] = 'integer';
case 'set':
$fixed = false;
$type[] = 'text';
$type[] = 'integer';
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'real':
$type[] = 'float';
$unsigned = preg_match('/ unsigned/i', $field['type']);
break;
case 'unknown':
case 'decimal':
case 'numeric':
$type[] = 'decimal';
$unsigned = preg_match('/ unsigned/i', $field['type']);
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
$type[] = 'blob';
$length = null;
break;
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
throw new Doctrine_DataDict_Mysql_Exception('unknown database attribute type: '.$dbType);
}
return array($type, $length, $unsigned, $fixed);

View File

@ -52,38 +52,38 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
*/
public function getNativeDeclaration(array $field) {
switch ($field['type']) {
case 'string':
case 'array':
case 'object':
case 'gzip':
case 'char':
case 'varchar':
$length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length'];
case 'string':
case 'array':
case 'object':
case 'gzip':
case 'char':
case 'varchar':
$length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR2('.$length.')';
case 'clob':
return 'CLOB';
case 'blob':
return 'BLOB';
case 'integer':
case 'enum':
if (!empty($field['length'])) {
return 'NUMBER('.$field['length'].')';
}
return 'INT';
case 'boolean':
return 'NUMBER(1)';
case 'date':
case 'time':
case 'timestamp':
return 'DATE';
case 'float':
return 'NUMBER';
case 'decimal':
return 'NUMBER(*,'.$db->options['decimal_places'].')';
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR2('.$length.')';
case 'clob':
return 'CLOB';
case 'blob':
return 'BLOB';
case 'integer':
case 'enum':
if (!empty($field['length'])) {
return 'NUMBER('.$field['length'].')';
}
return 'INT';
case 'boolean':
return 'NUMBER(1)';
case 'date':
case 'time':
case 'timestamp':
return 'DATE';
case 'float':
return 'NUMBER';
case 'decimal':
return 'NUMBER(*,'.$db->options['decimal_places'].')';
}
}
/**
@ -101,9 +101,46 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
$length = $field['length'];
}
switch ($db_type) {
case 'integer':
case 'pls_integer':
case 'binary_integer':
case 'integer':
case 'pls_integer':
case 'binary_integer':
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
break;
case 'varchar':
case 'varchar2':
case 'nvarchar2':
$fixed = false;
case 'char':
case 'nchar':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'float':
$type[] = 'float';
break;
case 'number':
if (!empty($field['scale'])) {
$type[] = 'decimal';
} else {
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
@ -111,62 +148,25 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
$type = array_reverse($type);
}
}
break;
case 'varchar':
case 'varchar2':
case 'nvarchar2':
$fixed = false;
case 'char':
case 'nchar':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'float':
$type[] = 'float';
break;
case 'number':
if (!empty($field['scale'])) {
$type[] = 'decimal';
} else {
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
}
break;
case 'long':
$type[] = 'text';
case 'clob':
case 'nclob':
$type[] = 'clob';
break;
case 'blob':
case 'raw':
case 'long raw':
case 'bfile':
$type[] = 'blob';
$length = null;
}
break;
case 'rowid':
case 'urowid':
default:
throw new Doctrine_DataDict_Oracle_Exception('unknown database attribute type: '.$db_type);
case 'long':
$type[] = 'text';
case 'clob':
case 'nclob':
$type[] = 'clob';
break;
case 'blob':
case 'raw':
case 'long raw':
case 'bfile':
$type[] = 'blob';
$length = null;
break;
case 'rowid':
case 'urowid':
default:
throw new Doctrine_DataDict_Oracle_Exception('unknown database attribute type: '.$db_type);
}
return array($type, $length, $unsigned, $fixed);

View File

@ -357,60 +357,60 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
*/
public function getNativeDeclaration(array $field) {
switch ($field['type']) {
case 'char':
case 'string':
case 'array':
case 'object':
case 'varchar':
$length = (isset($field['length']) && $field['length']) ? $field['length'] : null;
// TODO: $db->options['default_text_field_length'];
case 'char':
case 'string':
case 'array':
case 'object':
case 'varchar':
$length = (isset($field['length']) && $field['length']) ? $field['length'] : null;
// TODO: $db->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
return 'TEXT';
case 'blob':
return 'BYTEA';
case 'enum':
case 'integer':
if (!empty($field['autoincrement'])) {
if (!empty($field['length'])) {
$length = $field['length'];
if ($length > 4) {
return 'BIGSERIAL PRIMARY KEY';
}
}
return 'SERIAL PRIMARY KEY';
}
case 'clob':
return 'TEXT';
case 'blob':
return 'BYTEA';
case 'enum':
case 'integer':
if (!empty($field['autoincrement'])) {
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 2) {
return 'SMALLINT';
} elseif ($length == 3 || $length == 4) {
return 'INT';
} elseif ($length > 4) {
return 'BIGINT';
if ($length > 4) {
return 'BIGSERIAL PRIMARY KEY';
}
}
return 'INT';
case 'boolean':
return 'BOOLEAN';
case 'date':
return 'DATE';
case 'time':
return 'TIME without time zone';
case 'timestamp':
return 'TIMESTAMP without time zone';
case 'float':
return 'FLOAT8';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'NUMERIC(' . $length . ',' . $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES) . ')';
default:
throw new Doctrine_DataDict_Pgsql_Exception('Unknown field type '. $field['type']);
return 'SERIAL PRIMARY KEY';
}
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 2) {
return 'SMALLINT';
} elseif ($length == 3 || $length == 4) {
return 'INT';
} elseif ($length > 4) {
return 'BIGINT';
}
}
return 'INT';
case 'boolean':
return 'BOOLEAN';
case 'date':
return 'DATE';
case 'time':
return 'TIME without time zone';
case 'timestamp':
return 'TIMESTAMP without time zone';
case 'float':
return 'FLOAT8';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'NUMERIC(' . $length . ',' . $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES) . ')';
default:
throw new Doctrine_DataDict_Pgsql_Exception('Unknown field type '. $field['type']);
}
}
/**
@ -432,102 +432,102 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
$type = array();
$unsigned = $fixed = null;
switch (strtolower($field['type'])) {
case 'smallint':
case 'int2':
$type[] = 'integer';
$unsigned = false;
$length = 2;
if ($length == '2') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
break;
case 'int':
case 'int4':
case 'integer':
case 'serial':
case 'serial4':
$type[] = 'integer';
$unsigned = false;
$length = 4;
break;
case 'bigint':
case 'int8':
case 'bigserial':
case 'serial8':
$type[] = 'integer';
$unsigned = false;
$length = 8;
break;
case 'bool':
case 'boolean':
case 'smallint':
case 'int2':
$type[] = 'integer';
$unsigned = false;
$length = 2;
if ($length == '2') {
$type[] = 'boolean';
$length = 1;
break;
case 'text':
case 'varchar':
$fixed = false;
case 'unknown':
case 'char':
case 'bpchar':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'int':
case 'int4':
case 'integer':
case 'serial':
case 'serial4':
$type[] = 'integer';
$unsigned = false;
$length = 4;
break;
case 'bigint':
case 'int8':
case 'bigserial':
case 'serial8':
$type[] = 'integer';
$unsigned = false;
$length = 8;
break;
case 'bool':
case 'boolean':
$type[] = 'boolean';
$length = 1;
break;
case 'text':
case 'varchar':
$fixed = false;
case 'unknown':
case 'char':
case 'bpchar':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'real':
$type[] = 'float';
break;
case 'decimal':
case 'money':
case 'numeric':
$type[] = 'decimal';
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
case 'bytea':
$type[] = 'blob';
$length = null;
break;
case 'oid':
$type[] = 'blob';
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
$length = null;
break;
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
throw new Doctrine_DataDict_Pgsql_Exception('unknown database attribute type: '.$db_type);
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'real':
$type[] = 'float';
break;
case 'decimal':
case 'money':
case 'numeric':
$type[] = 'decimal';
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
case 'bytea':
$type[] = 'blob';
$length = null;
break;
case 'oid':
$type[] = 'blob';
$type[] = 'clob';
$length = null;
break;
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
throw new Doctrine_DataDict_Pgsql_Exception('unknown database attribute type: '.$db_type);
}
return array($type, $length, $unsigned, $fixed);
@ -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);
return $name.' '.$this->getNativeDeclaration($field);
}

View File

@ -55,60 +55,60 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
*/
public function getNativeDeclaration(array $field) {
switch ($field['type']) {
case 'text':
case 'object':
case 'array':
case 'string':
case 'char':
case 'gzip':
case 'varchar':
$length = (isset($field['length']) && $field['length']) ? $field['length'] : null;
case 'text':
case 'object':
case 'array':
case 'string':
case 'char':
case 'gzip':
case 'varchar':
$length = (isset($field['length']) && $field['length']) ? $field['length'] : null;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$this->conn->getAttribute(Doctrine::ATTR_DEFAULT_TEXTFLD_LENGTH).')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYTEXT';
} elseif ($length <= 65535) {
return 'TEXT';
} elseif ($length <= 16777215) {
return 'MEDIUMTEXT';
}
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$this->conn->getAttribute(Doctrine::ATTR_DEFAULT_TEXTFLD_LENGTH).')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYTEXT';
} elseif ($length <= 65535) {
return 'TEXT';
} elseif ($length <= 16777215) {
return 'MEDIUMTEXT';
}
return 'LONGTEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYBLOB';
} elseif ($length <= 65535) {
return 'BLOB';
} elseif ($length <= 16777215) {
return 'MEDIUMBLOB';
}
}
return 'LONGTEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYBLOB';
} elseif ($length <= 65535) {
return 'BLOB';
} elseif ($length <= 16777215) {
return 'MEDIUMBLOB';
}
return 'LONGBLOB';
case 'enum':
case 'integer':
case 'boolean':
return 'INTEGER';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'DATETIME';
case 'float':
case 'double':
return 'DOUBLE';//($db->options['fixed_float'] ? '('.
//($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : '');
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
}
return 'LONGBLOB';
case 'enum':
case 'integer':
case 'boolean':
return 'INTEGER';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'DATETIME';
case 'float':
case 'double':
return 'DOUBLE';//($db->options['fixed_float'] ? '('.
//($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : '');
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
}
throw new Doctrine_DataDict_Sqlite_Exception('Unknown datatype ' . $field['type']);
}
@ -125,101 +125,101 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
$fixed = null;
$type = array();
switch ($dbType) {
case 'boolean':
$type[] = 'boolean';
break;
case 'tinyint':
$type[] = 'integer';
case 'boolean':
$type[] = 'boolean';
break;
case 'tinyint':
$type[] = 'integer';
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 1;
break;
case 'smallint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 2;
break;
case 'mediumint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 3;
break;
case 'int':
case 'integer':
case 'serial':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 4;
break;
case 'bigint':
case 'bigserial':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8;
break;
case 'clob':
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
case 'varchar':
case 'varchar2':
$fixed = false;
case 'char':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 1;
break;
case 'smallint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 2;
break;
case 'mediumint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 3;
break;
case 'int':
case 'integer':
case 'serial':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 4;
break;
case 'bigint':
case 'bigserial':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8;
break;
case 'clob':
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
case 'varchar':
case 'varchar2':
$fixed = false;
case 'char':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($dbType, 'text')) {
$type[] = 'clob';
}
if ($fixed !== false) {
$fixed = true;
}
} elseif (strstr($dbType, 'text')) {
$type[] = 'clob';
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type[] = 'date';
$length = null;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
case 'datetime':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'real':
$type[] = 'float';
$length = null;
case 'float':
case 'double':
case 'real':
$type[] = 'float';
$length = null;
break;
case 'decimal':
case 'numeric':
$type[] = 'decimal';
$length = null;
case 'decimal':
case 'numeric':
$type[] = 'decimal';
$length = null;
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
$type[] = 'blob';
$length = null;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
$type[] = 'blob';
$length = null;
break;
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
throw new Doctrine_DataDict_Sqlite_Exception('unknown database attribute type: '.$dbType);
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
throw new Doctrine_DataDict_Sqlite_Exception('unknown database attribute type: '.$dbType);
}
return array($type, $length, $unsigned, $fixed);
@ -254,10 +254,10 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
$default = $autoinc = '';
$type = $this->getNativeDeclaration($field);
if(isset($field['autoincrement']) && $field['autoincrement']) {
if (isset($field['autoincrement']) && $field['autoincrement']) {
$autoinc = ' PRIMARY KEY AUTOINCREMENT';
$type = 'INTEGER';
} elseif(array_key_exists('default', $field)) {
} elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
}

View File

@ -84,7 +84,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
'sqlite2' => 'sqlite',
'sqlite3' => 'sqlite');
/**
* constructor
*
@ -93,7 +92,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param string $pass database password
*/
public function __construct($dsn, $user, $pass) {
if( ! isset($user)) {
if ( ! isset($user)) {
$a = self::parseDSN($dsn);
extract($a);
@ -104,7 +103,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this->listener = new Doctrine_Db_EventListener();
}
public function nextQuerySequence() {
return ++$this->querySequence;
}
@ -121,9 +119,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
return $this->dbh;
}
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);
}
return $this->options[$name];
}
/**
@ -133,9 +131,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return Doctrine_Db
*/
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->add($listener, $name);
return $this;
@ -155,10 +153,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return Doctrine_Db
*/
public function setListener($listener) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
&& ! ($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");
}
$this->listener = $listener;
return $this;
@ -171,7 +170,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return boolean
*/
public function connect() {
if($this->isConnected)
if ($this->isConnected)
return false;
$this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']);
@ -201,70 +200,71 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return string
*/
public static function driverName($name) {
if(isset(self::$driverMap[$name]))
if (isset(self::$driverMap[$name])) {
return self::$driverMap[$name];
}
return $name;
}
/**
* parseDSN
*
* @param string $dsn
* @return array Parsed contents of DSN
* @param string $dsn
* @return array Parsed contents of DSN
*/
function parseDSN($dsn) {
// silence any warnings
$parts = @parse_url($dsn);
$parts = @parse_url($dsn);
$names = array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment');
foreach($names as $name) {
if( ! isset($parts[$name]))
foreach ($names as $name) {
if ( ! isset($parts[$name])) {
$parts[$name] = null;
}
}
if(count($parts) == 0 || ! isset($parts['scheme']))
throw new Doctrine_Db_Exception('Empty data source name');
if (count($parts) == 0 || ! isset($parts['scheme'])) {
throw new Doctrine_Db_Exception('Empty data source name');
}
$drivers = self::getAvailableDrivers();
$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');
switch($parts['scheme']) {
case 'sqlite':
if(isset($parts['host']) && $parts['host'] == ':memory') {
$parts['database'] = ':memory:';
$parts['dsn'] = 'sqlite::memory:';
}
}
switch ($parts['scheme']) {
case 'sqlite':
if (isset($parts['host']) && $parts['host'] == ':memory') {
$parts['database'] = ':memory:';
$parts['dsn'] = 'sqlite::memory:';
}
break;
case 'mysql':
case 'informix':
case 'oci8':
case 'mssql':
case 'firebird':
case 'pgsql':
case 'odbc':
if( ! isset($parts['path']) || $parts['path'] == '/')
throw new Doctrine_Db_Exception('No database availible in data source name');
if(isset($parts['path']))
$parts['database'] = substr($parts['path'], 1);
if( ! isset($parts['host']))
throw new Doctrine_Db_Exception('No hostname set in data source name');
$parts['dsn'] = $parts["scheme"].":host=".$parts["host"].";dbname=".$parts["database"];
case 'mysql':
case 'informix':
case 'oci8':
case 'mssql':
case 'firebird':
case 'pgsql':
case 'odbc':
if ( ! isset($parts['path']) || $parts['path'] == '/') {
throw new Doctrine_Db_Exception('No database availible in data source name');
}
if (isset($parts['path'])) {
$parts['database'] = substr($parts['path'], 1);
}
if ( ! isset($parts['host'])) {
throw new Doctrine_Db_Exception('No hostname set in data source name');
}
$parts['dsn'] = $parts["scheme"].":host=".$parts["host"].";dbname=".$parts["database"];
break;
default:
throw new Doctrine_Db_Exception('Unknown driver '.$parts['scheme']);
default:
throw new Doctrine_Db_Exception('Unknown driver '.$parts['scheme']);
}
return $parts;
}
return $parts;
}
/**
* clear
* clears all instances from the memory
@ -327,11 +327,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this->listener->onPreQuery($event);
if( ! empty($params))
if ( ! empty($params)) {
$stmt = $this->dbh->query($statement)->execute($params);
else
} else {
$stmt = $this->dbh->query($statement);
}
$this->listener->onQuery($event);
$this->querySequence++;
@ -468,7 +468,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return ArrayIterator
*/
public function getIterator() {
if($this->listener instanceof Doctrine_Db_Profiler)
if ($this->listener instanceof Doctrine_Db_Profiler)
return $this->listener;
}
/**

View File

@ -78,9 +78,9 @@ class Doctrine_Db_Event {
* @return mixed
*/
public function getElapsedSecs() {
if (is_null($this->endedMicrotime))
if (is_null($this->endedMicrotime)) {
return false;
}
return ($this->endedMicrotime - $this->startedMicrotime);
}

View File

@ -35,104 +35,107 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin
private $listeners = array();
public function add($listener, $name = null) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
&& ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't add eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
if($name === null)
}
if ($name === null) {
$this->listeners[] = $listener;
else
} else {
$this->listeners[$name] = $listener;
}
}
public function get($name) {
if( ! isset($this->listeners[$name]))
if ( ! isset($this->listeners[$name])) {
throw new Doctrine_Db_Exception("Unknown listener $name");
}
return $this->listeners[$name];
}
public function set($name, $listener) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
&& ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
}
$this->listeners[$name] = $listener;
}
public function onQuery(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onQuery($event);
}
}
public function onPreQuery(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreQuery($event);
}
}
public function onPreExec(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreExec($event);
}
}
public function onExec(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onExec($event);
}
}
public function onPrePrepare(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPrePrepare($event);
}
}
public function onPrepare(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPrepare($event);
}
}
public function onPreCommit(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreCommit($event);
}
}
public function onCommit(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onCommit($event);
}
}
public function onPreRollBack(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreRollBack($event);
}
}
public function onRollBack(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onRollBack($event);
}
}
public function onPreBeginTransaction(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreBeginTransaction($event);
}
}
public function onBeginTransaction(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onBeginTransaction($event);
}
}
public function onPreExecute(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreExecute($event);
}
}
public function onExecute(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onExecute($event);
}
}

View File

@ -62,7 +62,8 @@ class Doctrine_Db_Mock extends Doctrine_Db {
public function getAttribute($attribute)
{
if($attribute == PDO::ATTR_DRIVER_NAME)
return 'mock';
if ($attribute == PDO::ATTR_DRIVER_NAME) {
return 'mock';
}
}
}

View File

@ -58,14 +58,15 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable {
*/
public function __call($m, $a) {
// 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.");
}
// 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.");
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
$a[0]->start();
} else {
@ -76,7 +77,6 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable {
$this->events[] = $a[0];
}
/**
* 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.

View File

@ -39,7 +39,6 @@ class Doctrine_Db_Profiler_Query {
*/
protected $queryType = 0;
protected $prepareTime;
/**
@ -54,7 +53,6 @@ class Doctrine_Db_Profiler_Query {
*/
protected $endedMicrotime;
/**
* Class constructor. A query is about to be started, save the query text ($query) and its
* type (one of the Zend_Db_Profiler::* constants).
@ -64,7 +62,7 @@ class Doctrine_Db_Profiler_Query {
*/
public function __construct($query, $prepareTime = null) {
$this->query = $query;
if($prepareTime !== null) {
if ($prepareTime !== null) {
$this->prepareTime = $prepareTime;
} else {
$this->startedMicrotime = microtime(true);
@ -96,7 +94,6 @@ class Doctrine_Db_Profiler_Query {
return ($this->endedMicrotime != null);
}
/**
* Get the original SQL text of the query.
*
@ -106,7 +103,6 @@ class Doctrine_Db_Profiler_Query {
return $this->query;
}
/**
* Get the type of this query (one of the Zend_Db_Profiler::* constants)
*
@ -129,4 +125,3 @@ class Doctrine_Db_Profiler_Query {
return ($this->prepareTime + ($this->endedMicrotime - $this->startedMicrotime));
}
}

View File

@ -53,7 +53,7 @@ class Doctrine_Db_Statement extends PDOStatement {
return $this->queryString;
}
public function isExecuted($executed = null) {
if($executed === null)
if ($executed === null)
return $this->executed;
$this->executed = (bool) $executed;
@ -68,8 +68,6 @@ class Doctrine_Db_Statement extends PDOStatement {
$this->dbh->getListener()->onExecute($event);
return $this;
}
}

View File

@ -55,9 +55,9 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return mixed
*/
public function get($key) {
if( ! isset($this->listeners[$key]))
if ( ! isset($this->listeners[$key])) {
return null;
}
return $this->listeners[$key];
}
/**
@ -78,7 +78,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onLoad(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onLoad($record);
}
}
@ -91,7 +91,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreLoad(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreLoad($record);
}
}
@ -103,7 +103,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onSleep(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onSleep($record);
}
}
@ -115,7 +115,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onWakeUp(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onWakeUp($record);
}
}
@ -127,7 +127,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onUpdate(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onUpdate($record);
}
}
@ -139,7 +139,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreUpdate(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreUpdate($record);
}
}
@ -151,7 +151,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onCreate(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onCreate($record);
}
}
@ -164,7 +164,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreCreate(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreCreate($record);
}
}
@ -176,7 +176,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onSave(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onSave($record);
}
}
@ -188,7 +188,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreSave(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreSave($record);
}
}
@ -202,7 +202,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return mixed
*/
public function onGetProperty(Doctrine_Record $record, $property, $value) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$value = $listener->onGetProperty($record, $property, $value);
}
return $value;
@ -217,7 +217,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return mixed
*/
public function onSetProperty(Doctrine_Record $record, $property, $value) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$value = $listener->onSetProperty($record, $property, $value);
}
return $value;
@ -230,7 +230,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onInsert(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onInsert($record);
}
}
@ -242,7 +242,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreInsert(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreInsert($record);
}
}
@ -254,7 +254,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onDelete(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onDelete($record);
}
}
@ -266,7 +266,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreDelete(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreDelete($record);
}
}
@ -278,7 +278,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onEvict(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onEvict($record);
}
}
@ -290,7 +290,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreEvict(Doctrine_Record $record) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreEvict($record);
}
}
@ -302,7 +302,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onClose(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onClose($connection);
}
}
@ -314,7 +314,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreClose(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreClose($connection);
}
}
@ -326,7 +326,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onOpen(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onOpen($connection);
}
}
@ -338,7 +338,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onTransactionCommit(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onTransactionCommit($connection);
}
}
@ -350,7 +350,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreTransactionCommit(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreTransactionCommit($connection);
}
}
@ -362,7 +362,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onTransactionRollback(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onTransactionRollback($connection);
}
}
@ -374,7 +374,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreTransactionRollback(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreTransactionRollback($connection);
}
}
@ -386,7 +386,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onTransactionBegin(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onTransactionBegin($connection);
}
}
@ -398,7 +398,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreTransactionBegin(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreTransactionBegin($connection);
}
}
@ -410,7 +410,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onCollectionDelete(Doctrine_Collection $collection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onCollectionDelete($record);
}
}
@ -422,9 +422,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void
*/
public function onPreCollectionDelete(Doctrine_Collection $collection) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreCollectionDelete($collection);
}
}
}

View File

@ -52,7 +52,6 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
return $this->debug;
}
public function onLoad(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_LOAD);
}
@ -149,4 +148,3 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
$this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_PRECOLLDELETE);
}
}

View File

@ -10,4 +10,3 @@
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_EventListener_Empty extends Doctrine_EventListener { }

View File

@ -130,9 +130,9 @@ class Doctrine_Export extends Doctrine_Connection_Module {
if ( ! $name)
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);
}
$queryFields = $this->getFieldDeclarationList($fields);
if (!empty($options['primary'])) {
@ -522,8 +522,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
public function getDeclaration($name, array $field) {
$default = '';
if(isset($field['default'])) {
if($field['default'] === '') {
if (isset($field['default'])) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull'])
? null : $this->valid_default_values[$field['type']];
if ($field['default'] === ''
@ -537,7 +537,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
}
/**
TODO: is this really needed for portability?
elseif(empty($field['notnull'])) {
elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
}
*/
@ -552,11 +552,11 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$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);
else
} else {
$dec = $this->conn->dataDict->getNativeDeclaration($field);
}
return $this->conn->quoteIdentifier($name, true) . ' ' . $dec . $charset . $default . $notnull . $collation;
}
/**
@ -594,39 +594,40 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, true);
foreach(get_declared_classes() as $name) {
foreach (get_declared_classes() as $name) {
$class = new ReflectionClass($name);
if($class->isSubclassOf($parent) && ! $class->isAbstract())
if ($class->isSubclassOf($parent) && ! $class->isAbstract()) {
$obj = new $class();
}
}
$conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, $old);
}
public function export($record) {
if( ! $record instanceof Doctrine_Record)
if ( ! $record instanceof Doctrine_Record)
$record = new $record();
$table = $record->getTable();
$reporter = new Doctrine_Reporter();
if( ! Doctrine::isValidClassname($table->getComponentName())) {
if ( ! Doctrine::isValidClassname($table->getComponentName())) {
$reporter->add(E_WARNING, 'Badly named class.');
}
try {
$columns = array();
foreach($table->getColumns() as $name => $column) {
foreach ($table->getColumns() as $name => $column) {
$definition = $column[2];
$definition['type'] = $column[0];
$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']);
if($definition['type'] == 'boolean' && isset($definition['default']))
}
if ($definition['type'] == 'boolean' && isset($definition['default'])) {
$definition['default'] = (int) $definition['default'];
}
$columns[$name] = $definition;
}

View File

@ -158,8 +158,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
parent::createTable($name, $fields, $options);
// TODO ? $this->_silentCommit();
foreach($fields as $field_name => $field) {
if( ! empty($field['autoincrement'])) {
foreach ($fields as $field_name => $field) {
if ( ! empty($field['autoincrement'])) {
//create PK constraint
$pk_definition = array(
'fields' => array($field_name => array()),

View File

@ -209,7 +209,6 @@ class Doctrine_Export_Mssql extends Doctrine_Export {
return true;
}
$query = 'SET IDENTITY_INSERT $sequence_name ON ' .
'INSERT INTO $sequence_name (' . $seqcol_name . ') VALUES ( ' . $start . ')';
$res = $db->exec($query);

View File

@ -90,29 +90,28 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return void
*/
public function createTable($name, array $fields, array $options = array()) {
if( ! $name)
if ( ! $name)
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.'"');
}
$query_fields = $this->getFieldDeclarationList($fields);
if( ! empty($options['primary']))
if ( ! empty($options['primary'])) {
$query_fields.= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')';
}
$name = $this->conn->quoteIdentifier($name, true);
$query = 'CREATE TABLE ' . $name . ' (' . $query_fields . ')';
$optionStrings = array();
if(isset($options['comment']))
if (isset($options['comment'])) {
$optionStrings['comment'] = 'COMMENT = '.$this->dbh->quote($options['comment'], 'text');
if(isset($options['charset'])) {
}
if (isset($options['charset'])) {
$optionsSting['charset'] = 'DEFAULT CHARACTER SET '.$options['charset'];
if(isset($options['collate'])) {
if (isset($options['collate'])) {
$optionStrings['charset'].= ' COLLATE '.$options['collate'];
}
}
@ -223,7 +222,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return boolean
*/
public function alterTable($name, array $changes, $check) {
if( ! $name)
if ( ! $name)
throw new Doctrine_Export_Mysql_Exception('no valid table name specified');
foreach ($changes as $changeName => $change) {
@ -239,17 +238,17 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
}
if($check) {
if ($check) {
return true;
}
$query = '';
if( ! empty($changes['name'])) {
if ( ! empty($changes['name'])) {
$change_name = $this->conn->quoteIdentifier($changes['name'], true);
$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) {
if ($query) {
$query.= ', ';
@ -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) {
if ($query) {
$query.= ', ';
@ -269,13 +268,13 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
$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) {
$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) {
if ($query) {
$query.= ', ';
@ -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) {
if ($query) {
$query.= ', ';
@ -302,7 +301,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
}
if( ! $query) {
if ( ! $query) {
return MDB2_OK;
}
@ -329,7 +328,6 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
if ($start == 1)
return true;
$query = 'INSERT INTO ' . $sequenceName
. ' (' . $seqcol_name . ') VALUES (' . ($start-1) . ')';
@ -418,4 +416,4 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
$this->conn->exec('DROP TABLE ' . $table);
}
}
?>

View File

@ -45,7 +45,6 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
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');
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
$password = $this->conn->dsn['password'] ? $this->conn->dsn['password'] : $name;
@ -81,7 +80,6 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
throw new Doctrine_Export_Oracle_Exception('database dropping is only supported if the
"emulate_database" option is enabled');
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
return $this->conn->query('DROP USER ' . $username . ' CASCADE');
@ -174,7 +172,7 @@ END;
$query.= ' WHERE trigger_name='.$trigger_name_quoted.' OR trigger_name='.strtoupper($trigger_name_quoted);
$trigger = $this->conn->fetchOne($query);
if($trigger) {
if ($trigger) {
$trigger_name = $this->conn->quoteIdentifier($table . '_AI_PK', true);
$trigger_sql = 'DROP TRIGGER ' . $trigger_name;
@ -227,8 +225,8 @@ END;
$result = parent::createTable($name, $fields, $options);
foreach($fields as $field_name => $field) {
if(isset($field['autoincrement']) && $field['autoincrement']) {
foreach ($fields as $field_name => $field) {
if (isset($field['autoincrement']) && $field['autoincrement']) {
$result = $this->_makeAutoincrement($field_name, $name);
}
}

View File

@ -182,9 +182,9 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
if (!empty($field['type'])) {
$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');
}
$query = "ALTER $field_name TYPE ".$db->datatype->getTypeDeclaration($field['definition']);
$this->dbh->query("ALTER TABLE $name $query");
}
@ -214,4 +214,4 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
}
}
}
?>

View File

@ -71,7 +71,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export {
$fields = array();
foreach ($definition['fields'] as $fieldName => $field) {
$fieldString = $fieldName;
if(isset($field['sorting'])) {
if (isset($field['sorting'])) {
switch ($field['sorting']) {
case 'ascending':
$fieldString .= ' ASC';

View File

@ -284,9 +284,9 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
*/
private function basicMath($type, array $args) {
$elements = $this->getIdentifiers($args);
if (count($elements) < 1)
if (count($elements) < 1) {
return '';
}
if (count($elements) == 1) {
return $elements[0];
} else {
@ -539,15 +539,15 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @return string logical expression
*/
public function in($column, $values) {
if( ! is_array($values))
if ( ! is_array($values)) {
$values = array($values);
}
$values = $this->getIdentifiers($values);
$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.');
}
return $column . ' IN (' . implode(', ', $values) . ')';
}
/**

View File

@ -56,9 +56,9 @@ class Doctrine_Expression_Mssql extends Doctrine_Expression {
* @return string to call a function to get a substring
*/
public function substring($value, $position, $length = null) {
if (!is_null($length))
if (!is_null($length)) {
return "SUBSTRING($value, $position, $length)";
}
return "SUBSTRING($value, $position, LEN($value) - $position + 1)";
}
/**

View File

@ -57,7 +57,7 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression {
* @return string SQL substring function with given parameters
*/
public function substring($value, $position, $length = null) {
if($length !== null)
if ($length !== null)
return "SUBSTR($value, $position, $length)";
return "SUBSTR($value, $position)";

View File

@ -52,10 +52,11 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
public function md5($column) {
$column = $this->getIdentifier($column);
if ($this->version > 7)
if ($this->version > 7) {
return 'MD5(' . $column . ')';
else
} else {
return 'encode(digest(' . $column .', md5), hex)';
}
}
/**
@ -74,8 +75,9 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
if ($len === null) {
$len = $this->getIdentifier($len);
return 'SUBSTR(' . $value . ', ' . $from . ')';
} else
} else {
return 'SUBSTR(' . $value . ', ' . $from . ', ' . $len . ')';
}
}
/**

View File

@ -143,9 +143,9 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* @return string SQL substring function with given parameters
*/
public function substring($value, $position, $length = null) {
if($length !== null)
if ($length !== null) {
return 'SUBSTR(' . $value . ', ' . $position . ', ' . $length . ')';
}
return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))';
}
}

View File

@ -70,10 +70,10 @@ class Doctrine_Hook {
* @param Doctrine_Query $query the base query
*/
public function __construct($query) {
if(is_string($query)) {
if (is_string($query)) {
$this->query = new Doctrine_Query();
$this->query->parseQuery($query);
} elseif($query instanceof Doctrine_Query) {
} elseif ($query instanceof Doctrine_Query) {
$this->query = $query;
}
}
@ -95,21 +95,20 @@ class Doctrine_Hook {
* @return boolean whether or not the hooking was
*/
public function hookWhere($params) {
if( ! is_array($params))
if ( ! is_array($params)) {
return false;
foreach($params as $name => $value) {
}
foreach ($params as $name => $value) {
$e = explode('.', $name);
if(count($e) == 2) {
if (count($e) == 2) {
list($alias, $column) = $e;
$tableAlias = $this->query->getTableAlias($alias);
$table = $this->query->getTable($tableAlias);
if($def = $table->getDefinitionOf($column)) {
if(isset($this->typeParsers[$def[0]])) {
if ($def = $table->getDefinitionOf($column)) {
if (isset($this->typeParsers[$def[0]])) {
$name = $this->typeParsers[$def[0]];
$parser = new $name;
}
@ -134,27 +133,27 @@ class Doctrine_Hook {
* @return boolean whether or not the hooking was
*/
public function hookOrderby($params) {
if( ! is_array($params))
if ( ! is_array($params)) {
return false;
foreach($params as $name) {
}
foreach ($params as $name) {
$e = explode(' ', $name);
$order = 'ASC';
if(count($e) > 1) {
if (count($e) > 1) {
$order = ($e[1] == 'DESC') ? 'DESC' : 'ASC';
}
$e = explode('.', $e[0]);
if(count($e) == 2) {
if (count($e) == 2) {
list($alias, $column) = $e;
$tableAlias = $this->query->getTableAlias($alias);
$table = $this->query->getTable($tableAlias);
if($def = $table->getDefinitionOf($column)) {
if ($def = $table->getDefinitionOf($column)) {
$this->query->addOrderBy($alias . '.' . $column . ' ' . $order);
}
}

View File

@ -46,15 +46,15 @@ class Doctrine_Hook_Integer extends Doctrine_Hook_Parser_Complex {
public function parseSingle($alias, $field, $value) {
$e = explode(' ', $value);
foreach($e as $v) {
$v = trim($v);
foreach ($e as $v) {
$v = trim($v);
$e2 = explode('-', $v);
$e2 = explode('-', $v);
$name = $alias. '.' . $field;
if(count($e2) == 1) {
// one '-' found
if (count($e2) == 1) {
// one '-' found
$a[] = $name . ' = ?';

View File

@ -57,9 +57,9 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser {
public function parseClause($alias, $field, $value) {
$parts = Doctrine_Query::bracketExplode($value, ' AND ', '(', ')');
if(count($parts) > 1) {
if (count($parts) > 1) {
$ret = array();
foreach($parts as $part) {
foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parseSingle($alias, $field, $part);
}
@ -67,16 +67,16 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser {
$r = implode(' AND ', $ret);
} else {
$parts = Doctrine_Query::bracketExplode($value, ' OR ', '(', ')');
if(count($parts) > 1) {
if (count($parts) > 1) {
$ret = array();
foreach($parts as $part) {
foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parseClause($alias, $field, $part);
}
$r = implode(' OR ', $ret);
} 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));
} else {
$ret = $this->parseSingle($alias, $field, $parts[0]);

View File

@ -46,8 +46,8 @@ class Doctrine_Hook_WordLike extends Doctrine_Hook_Parser_Complex {
public function parseSingle($alias, $field, $value) {
$e2 = explode(' ',$value);
foreach($e2 as $v) {
$v = trim($v);
foreach ($e2 as $v) {
$v = trim($v);
$a[] = $alias. '.' . $field . ' LIKE ?';
$this->params[] = $v . '%';
}

View File

@ -111,9 +111,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @param Doctrine_Connection|null $connection
*/
public function __construct($connection = null) {
if( ! ($connection instanceof Doctrine_Connection))
if ( ! ($connection instanceof Doctrine_Connection)) {
$connection = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->conn = $connection;
$this->aliasHandler = new Doctrine_Hydrate_Alias();
}
@ -164,7 +164,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
public function getPathAlias($path) {
$s = array_search($path, $this->compAliases);
if($s === false)
if ($s === false)
return $path;
return $s;
@ -203,15 +203,16 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
*
* @param $name
*/
public function remove($name) {
if(isset($this->parts[$name])) {
if($name == "limit" || $name == "offset")
$this->parts[$name] = false;
else
$this->parts[$name] = array();
}
return $this;
}
public function remove($name) {
if (isset($this->parts[$name])) {
if ($name == "limit" || $name == "offset") {
$this->parts[$name] = false;
} else {
$this->parts[$name] = array();
}
}
return $this;
}
/**
* clear
* resets all the variables
@ -284,12 +285,12 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @return string
*/
final public function getTableAlias($path) {
if(isset($this->compAliases[$path]))
if (isset($this->compAliases[$path])) {
$path = $this->compAliases[$path];
if( ! isset($this->tableAliases[$path]))
}
if ( ! isset($this->tableAliases[$path])) {
return false;
}
return $this->tableAliases[$path];
}
/**
@ -300,28 +301,28 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
*/
private function getCollection($name) {
$table = $this->tables[$name];
if( ! isset($this->fetchModes[$name]))
if ( ! isset($this->fetchModes[$name])) {
return new Doctrine_Collection($table);
switch($this->fetchModes[$name]):
case Doctrine::FETCH_BATCH:
$coll = new Doctrine_Collection_Batch($table);
}
switch ($this->fetchModes[$name]) {
case Doctrine::FETCH_BATCH:
$coll = new Doctrine_Collection_Batch($table);
break;
case Doctrine::FETCH_LAZY:
$coll = new Doctrine_Collection_Lazy($table);
case Doctrine::FETCH_LAZY:
$coll = new Doctrine_Collection_Lazy($table);
break;
case Doctrine::FETCH_OFFSET:
$coll = new Doctrine_Collection_Offset($table);
case Doctrine::FETCH_OFFSET:
$coll = new Doctrine_Collection_Offset($table);
break;
case Doctrine::FETCH_IMMEDIATE:
$coll = new Doctrine_Collection_Immediate($table);
case Doctrine::FETCH_IMMEDIATE:
$coll = new Doctrine_Collection_Immediate($table);
break;
case Doctrine::FETCH_LAZY_OFFSET:
$coll = new Doctrine_Collection_LazyOffset($table);
case Doctrine::FETCH_LAZY_OFFSET:
$coll = new Doctrine_Collection_LazyOffset($table);
break;
default:
throw new Doctrine_Exception("Unknown fetchmode");
endswitch;
default:
throw new Doctrine_Exception("Unknown fetchmode");
};
return $coll;
}
@ -333,8 +334,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @return void
*/
public static function convertBoolean(&$item) {
if(is_bool($item))
if (is_bool($item)) {
$item = (int) $item;
}
}
/**
* setParams
@ -358,23 +360,25 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
array_walk($params, array(__CLASS__, 'convertBoolean'));
if( ! $this->view)
if ( ! $this->view) {
$query = $this->getQuery($params);
else
} else {
$query = $this->view->getSelectSql();
}
if($this->isLimitSubqueryUsed() &&
$this->conn->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) !== 'mysql')
if ($this->isLimitSubqueryUsed()
&& $this->conn->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) !== 'mysql'
) {
$params = array_merge($params, $params);
}
$stmt = $this->conn->execute($query, $params);
if($this->aggregate)
if ($this->aggregate)
return $stmt->fetchAll(PDO::FETCH_ASSOC);
if(count($this->tables) == 0)
if (count($this->tables) == 0) {
throw new Doctrine_Query_Exception("No components selected");
}
$keys = array_keys($this->tables);
$root = $keys[0];
@ -383,50 +387,48 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$coll = $this->getCollection($root);
$prev[$root] = $coll;
if($this->aggregate)
if ($this->aggregate)
$return = Doctrine::FETCH_ARRAY;
$array = $this->parseData($stmt);
if($return == Doctrine::FETCH_ARRAY)
if ($return == Doctrine::FETCH_ARRAY)
return $array;
foreach($array as $data) {
foreach ($array as $data) {
/**
* remove duplicated data rows and map data into objects
*/
foreach($data as $key => $row) {
if(empty($row))
foreach ($data as $key => $row) {
if (empty($row)) {
continue;
}
//$key = array_search($key, $this->shortAliases);
foreach($this->tables as $k => $t) {
if ( ! strcasecmp($key, $k))
foreach ($this->tables as $k => $t) {
if ( ! strcasecmp($key, $k)) {
$key = $k;
}
}
if ( !isset($this->tables[$key]) )
if ( !isset($this->tables[$key]) ) {
throw new Doctrine_Exception('No table named ' . $key . ' found.');
}
$ids = $this->tables[$key]->getIdentifier();
$name = $key;
if($this->isIdentifiable($row, $ids)) {
if($name !== $root) {
if ($this->isIdentifiable($row, $ids)) {
if ($name !== $root) {
$prev = $this->initRelated($prev, $name);
}
// aggregate values have numeric keys
if(isset($row[0])) {
if (isset($row[0])) {
$component = $this->tables[$name]->getComponentName();
// if the collection already has objects, get the last object
// otherwise create a new one where the aggregate values are being mapped
if($prev[$name]->count() > 0) {
if ($prev[$name]->count() > 0) {
$record = $prev[$name]->getLast();
} else {
$record = new $component();
@ -437,10 +439,10 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$alias = $this->getPathAlias($path);
// map each aggregate value
foreach($row as $index => $value) {
foreach ($row as $index => $value) {
$agg = false;
if(isset($this->pendingAggregates[$alias][$index])) {
if (isset($this->pendingAggregates[$alias][$index])) {
$agg = $this->pendingAggregates[$alias][$index][3];
}
@ -452,11 +454,10 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
}
if( ! isset($previd[$name]))
$previd[$name] = array();
if($previd[$name] !== $row) {
if ( ! isset($previd[$name])) {
$previd[$name] = array();
}
if ($previd[$name] !== $row) {
// set internal data
$this->tables[$name]->setData($row);
@ -465,23 +466,22 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$record = $this->tables[$name]->getRecord();
// aggregate values have numeric keys
if(isset($row[0])) {
if (isset($row[0])) {
$path = array_search($name, $this->tableAliases);
$alias = $this->getPathAlias($path);
// map each aggregate value
foreach($row as $index => $value) {
foreach ($row as $index => $value) {
$agg = false;
if(isset($this->pendingAggregates[$alias][$index]))
if (isset($this->pendingAggregates[$alias][$index])) {
$agg = $this->pendingAggregates[$alias][$index][3];
}
$record->mapValue($agg, $value);
}
}
if($name == $root) {
if ($name == $root) {
// add record into root collection
$coll->add($record);
unset($previd);
@ -495,7 +495,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
// are being done properly when the result set doesn't
// contain the rows in 'right order'
if($prev[$name] !== $record)
if ($prev[$name] !== $record)
$prev[$name] = $record;
}
@ -518,18 +518,19 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$tmp = explode('.', $path);
$alias = end($tmp);
if( ! isset($prev[$pointer]) )
if ( ! isset($prev[$pointer]) ) {
return $prev;
}
$fk = $this->tables[$pointer]->getRelation($alias);
if( ! $fk->isOneToOne()) {
if($prev[$pointer]->getLast() instanceof Doctrine_Record) {
if( ! $prev[$pointer]->getLast()->hasReference($alias)) {
if ( ! $fk->isOneToOne()) {
if ($prev[$pointer]->getLast() instanceof Doctrine_Record) {
if ( ! $prev[$pointer]->getLast()->hasReference($alias)) {
$prev[$name] = $this->getCollection($name);
$prev[$pointer]->getLast()->initReference($prev[$name],$fk);
} else
} else {
$prev[$name] = $prev[$pointer]->getLast()->get($alias);
}
}
}
@ -551,14 +552,14 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$fk = $this->tables[$pointer]->getRelation($alias);
if($fk->isOneToOne()) {
if ($fk->isOneToOne()) {
$prev[$pointer]->getLast()->set($fk->getAlias(), $record);
$prev[$name] = $record;
} else {
// one-to-many relation or many-to-many relation
if( ! $prev[$pointer]->getLast()->hasReference($alias)) {
if ( ! $prev[$pointer]->getLast()->hasReference($alias)) {
$prev[$name] = $this->getCollection($name);
$prev[$pointer]->getLast()->initReference($prev[$name], $fk);
@ -581,14 +582,15 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @return boolean
*/
public function isIdentifiable(array $row, $ids) {
if(is_array($ids)) {
foreach($ids as $id) {
if($row[$id] == null)
if (is_array($ids)) {
foreach ($ids as $id) {
if ($row[$id] == null)
return true;
}
} else {
if( ! isset($row[$ids]))
if ( ! isset($row[$ids])) {
return true;
}
}
return false;
}
@ -602,34 +604,35 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
// get the inheritance maps
$array = array();
foreach($this->tables as $alias => $table):
foreach ($this->tables as $alias => $table) {
$array[$alias][] = $table->getInheritanceMap();
endforeach;
};
// apply inheritance maps
$str = "";
$c = array();
$index = 0;
foreach($array as $tableAlias => $maps) {
foreach ($array as $tableAlias => $maps) {
$a = array();
foreach($maps as $map) {
foreach ($maps as $map) {
$b = array();
foreach($map as $field => $value) {
if($index > 0)
foreach ($map as $field => $value) {
if ($index > 0) {
$b[] = '(' . $tableAlias . '.' . $field . ' = ' . $value . ' OR ' . $tableAlias . '.' . $field . ' IS NULL)';
else
} else {
$b[] = $tableAlias . '.' . $field . ' = ' . $value;
}
}
if( ! empty($b))
if ( ! empty($b)) {
$a[] = implode(' AND ', $b);
}
}
if( ! empty($a))
if ( ! empty($a)) {
$c[] = implode(' AND ', $a);
}
$index++;
}
@ -647,11 +650,11 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
public function parseData(PDOStatement $stmt) {
$array = array();
while($data = $stmt->fetch(PDO::FETCH_ASSOC)):
while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
/**
* parse the data into two-dimensional array
*/
foreach($data as $key => $value):
foreach ($data as $key => $value) {
$e = explode('__', $key);
$field = strtolower(array_pop($e));
@ -660,9 +663,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$data[$component][$field] = $value;
unset($data[$key]);
endforeach;
};
$array[] = $data;
endwhile;
};
$stmt->closeCursor();
return $array;
@ -674,9 +677,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @return Doctrine_Table|boolean
*/
public function getTable($name) {
if(isset($this->tables[$name]))
if (isset($this->tables[$name])) {
return $this->tables[$name];
}
return false;
}
/**
@ -686,4 +689,3 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
return Doctrine_Lib::formatSql($this->getQuery());
}
}

View File

@ -42,12 +42,12 @@ class Doctrine_Hydrate_Alias {
}
public function generateNewAlias($alias) {
if(isset($this->shortAliases[$alias])) {
if (isset($this->shortAliases[$alias])) {
// generate a new alias
$name = substr($alias, 0, 1);
$i = ((int) substr($alias, 1));
if($i == 0)
if ($i == 0)
$i = 1;
$newIndex = ($this->shortAliasIndexes[$name] + $i);
@ -62,9 +62,9 @@ class Doctrine_Hydrate_Alias {
return (isset($this->shortAliases[$tableName]));
}
public function getShortAliasIndex($alias) {
if( ! isset($this->shortAliasIndexes[$alias]))
if ( ! isset($this->shortAliasIndexes[$alias])) {
return 0;
}
return $this->shortAliasIndexes[$alias];
}
public function generateShortAlias($tableName) {
@ -72,10 +72,10 @@ class Doctrine_Hydrate_Alias {
$alias = $char;
if( ! isset($this->shortAliasIndexes[$alias]))
if ( ! isset($this->shortAliasIndexes[$alias])) {
$this->shortAliasIndexes[$alias] = 1;
while(isset($this->shortAliases[$alias])) {
}
while (isset($this->shortAliases[$alias])) {
$alias = $char . ++$this->shortAliasIndexes[$alias];
}
$this->shortAliases[$alias] = $tableName;
@ -86,9 +86,9 @@ class Doctrine_Hydrate_Alias {
public function getShortAlias($tableName) {
$alias = array_search($tableName, $this->shortAliases);
if($alias !== false)
if ($alias !== false) {
return $alias;
}
return $this->generateShortAlias($tableName);
}
}

View File

@ -47,4 +47,3 @@ class Doctrine_Identifier {
*/
const COMPOSITE = 4;
}

View File

@ -44,7 +44,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/
public function listDatabases()
{
if( ! isset($this->sql['listDatabases'])) {
if ( ! isset($this->sql['listDatabases'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
@ -57,7 +57,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/
public function listFunctions()
{
if( ! isset($this->sql['listFunctions'])) {
if ( ! isset($this->sql['listFunctions'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
@ -81,7 +81,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/
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.');
}
@ -154,7 +154,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/
public function listUsers()
{
if( ! isset($this->sql['listUsers'])) {
if ( ! isset($this->sql['listUsers'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
@ -168,7 +168,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/
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.');
}

View File

@ -42,12 +42,13 @@ class Doctrine_Import_Builder {
private static $tpl;
public function __construct() {
if( ! isset(self::$tpl))
if ( ! isset(self::$tpl)) {
self::$tpl = file_get_contents(Doctrine::getPath()
. DIRECTORY_SEPARATOR . 'Doctrine'
. DIRECTORY_SEPARATOR . 'Import'
. DIRECTORY_SEPARATOR . 'Builder'
. DIRECTORY_SEPARATOR . 'Record.tpl');
}
}
/**
@ -57,7 +58,7 @@ class Doctrine_Import_Builder {
* @access public
*/
public function setTargetPath($path) {
if( ! file_exists($path)) {
if ( ! file_exists($path)) {
mkdir($path, 0777);
}
@ -79,14 +80,13 @@ class Doctrine_Import_Builder {
return $this->suffix;
}
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.');
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.');
}
$created = date('l dS \of F Y h:i:s A');
$className = Doctrine::classify($table->get('name'));
$fileName = $this->path . DIRECTORY_SEPARATOR . $className . $this->suffix;
@ -94,41 +94,42 @@ class Doctrine_Import_Builder {
$i = 0;
foreach($table as $name => $column) {
foreach ($table as $name => $column) {
$columns[$i] = ' $this->hasColumn(\'' . $column['name'] . '\', \'' . $column['type'] . '\'';
if($column['length'])
if ($column['length']) {
$columns[$i] .= ', ' . $column['length'];
else
} else {
$columns[$i] .= ', null';
}
$a = array();
if($column['default']) {
if ($column['default']) {
$a[] = '\'default\' => ' . var_export($column['default'], true);
}
if($column['notnull']) {
if ($column['notnull']) {
$a[] = '\'notnull\' => true';
}
if($column['primary']) {
if ($column['primary']) {
$a[] = '\'primary\' => true';
}
if($column['autoinc']) {
if ($column['autoinc']) {
$a[] = '\'autoincrement\' => true';
}
if($column['unique']) {
if ($column['unique']) {
$a[] = '\'unique\' => true';
}
if( ! empty($a))
if ( ! empty($a)) {
$columns[$i] .= ', ' . 'array(' . implode(',
', $a) . ')';
}
$columns[$i] .= ');';
if($i < (count($table) - 1))
if ($i < (count($table) - 1)) {
$columns[$i] .= '
';
}
$i++;
}
@ -136,8 +137,7 @@ class Doctrine_Import_Builder {
$bytes = file_put_contents($fileName, $content);
if($bytes === false)
if ($bytes === false)
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName);
}
/**
@ -147,8 +147,8 @@ class Doctrine_Import_Builder {
* @return void
*/
public function build(Doctrine_Schema_Object $schema) {
foreach($schema->getDatabases() as $database){
foreach($database->getTables() as $table){
foreach ($schema->getDatabases() as $database){
foreach ($database->getTables() as $table){
$this->buildRecord($table);
}
}

View File

@ -109,7 +109,7 @@ class Doctrine_Import_Firebird extends Doctrine_Import {
WHERE RDB$SYSTEM_FLAG IS NULL
OR RDB$SYSTEM_FLAG = 0';
if( ! is_null($table)) {
if ( ! is_null($table)) {
$table = $db->quote(strtoupper($table), 'text');
$query .= 'WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
}

View File

@ -143,7 +143,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import {
$description = array();
foreach ($result as $key => $val2) {
$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];
}
$description = array(

View File

@ -46,7 +46,6 @@ abstract class Doctrine_Import_Reader
/*** Attributes: ***/
/**
*
* @return Doctrine_Schema
@ -55,9 +54,4 @@ abstract class Doctrine_Import_Reader
*/
abstract public function read( );
} // end of Doctrine_Import_Reader

View File

@ -52,7 +52,6 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
*/
private $pdo;
/**
*
* @param object pdo * @return
@ -62,7 +61,6 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
} // end of member function setPdo
/**
*
* @return Doctrine_Schema
@ -70,37 +68,34 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
*/
public function read( )
{
$dataDict = Doctrine_Manager::getInstance()->getCurrentConnection()->getDataDict();
$dataDict = Doctrine_Manager::getInstance()->getCurrentConnection()->getDataDict();
$schema = new Doctrine_Schema(); /* @todo FIXME i am incomplete*/
$db = new Doctrine_Schema_Database();
$schema->addDatabase($db);
$schema = new Doctrine_Schema(); /* @todo FIXME i am incomplete*/
$db = new Doctrine_Schema_Database();
$schema->addDatabase($db);
$dbName = 'XXtest'; // @todo FIXME where should we get
$dbName = 'XXtest'; // @todo FIXME where should we get
$db->set("name",$dbName);
$tableNames = $dataDict->listTables();
foreach($tableNames as $tableName){
$table = new Doctrine_Schema_Table();
$table->set("name",$tableName);
$tableColumns = $dataDict->listTableColumns($tableName);
foreach($tableColumns as $tableColumn){
$table->addColumn($tableColumn);
}
$db->addTable($table);
if ($fks = $dataDict->listTableConstraints($tableName)){
foreach($fks as $fk){
$relation = new Doctrine_Schema_Relation();
$relation->setRelationBetween($fk['referencingColumn'],$fk['referencedTable'],$fk['referencedColumn']);
$table->setRelation($relation);
$db->set("name",$dbName);
$tableNames = $dataDict->listTables();
foreach ($tableNames as $tableName){
$table = new Doctrine_Schema_Table();
$table->set("name",$tableName);
$tableColumns = $dataDict->listTableColumns($tableName);
foreach ($tableColumns as $tableColumn){
$table->addColumn($tableColumn);
}
$db->addTable($table);
if ($fks = $dataDict->listTableConstraints($tableName)){
foreach ($fks as $fk){
$relation = new Doctrine_Schema_Relation();
$relation->setRelationBetween($fk['referencingColumn'],$fk['referencedTable'],$fk['referencedColumn']);
$table->setRelation($relation);
}
}
}
return $schema;
}
return $schema;
}
} // end of Doctrine_Import_Reader_Db

View File

@ -44,10 +44,4 @@ class Doctrine_Import_Reader_Exception
/*** Attributes: ***/
} // end of Doctrine_Import_Reader_Exception

View File

@ -50,7 +50,6 @@ class Doctrine_Import_Reader_Xml_Propel extends Doctrine_Import_Reader
*/
private $xml;
/**
*
* @param string xml * @return
@ -62,7 +61,4 @@ class Doctrine_Import_Reader_Xml_Propel extends Doctrine_Import_Reader
public function read() { }
} // end of Doctrine_Import_Reader_Xml_Propel

View File

@ -136,7 +136,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$description = array();
$columns = array();
foreach($result as $key => $val) {
foreach ($result as $key => $val) {
$description = array(
'name' => $val['name'],
'type' => $val['type'],
@ -159,7 +159,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$indexes = array();
foreach($result as $key => $val) {
foreach ($result as $key => $val) {
}
}
@ -179,7 +179,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$data = $stmt->fetchAll(PDO::FETCH_COLUMN);
foreach($data as $table) {
foreach ($data as $table) {
$tables[] = new Doctrine_Schema_Table(array('name' => $table));
}
return $tables;

View File

@ -36,23 +36,23 @@ class Doctrine_Lib {
* @return string string representation of given state
*/
public static function getRecordStateAsString($state) {
switch($state):
case Doctrine_Record::STATE_PROXY:
return "proxy";
switch ($state) {
case Doctrine_Record::STATE_PROXY:
return "proxy";
break;
case Doctrine_Record::STATE_CLEAN:
return "persistent clean";
case Doctrine_Record::STATE_CLEAN:
return "persistent clean";
break;
case Doctrine_Record::STATE_DIRTY:
return "persistent dirty";
case Doctrine_Record::STATE_DIRTY:
return "persistent dirty";
break;
case Doctrine_Record::STATE_TDIRTY:
return "transient dirty";
case Doctrine_Record::STATE_TDIRTY:
return "transient dirty";
break;
case Doctrine_Record::STATE_TCLEAN:
return "transient clean";
case Doctrine_Record::STATE_TCLEAN:
return "transient clean";
break;
endswitch;
};
}
/**
* returns a string representation of Doctrine_Record object
@ -75,17 +75,17 @@ class Doctrine_Lib {
* @param integer $state connection state
*/
public static function getConnectionStateAsString($state) {
switch($state):
case Doctrine_Transaction::STATE_SLEEP:
return "open";
switch ($state) {
case Doctrine_Transaction::STATE_SLEEP:
return "open";
break;
case Doctrine_Transaction::STATE_BUSY:
return "busy";
case Doctrine_Transaction::STATE_BUSY:
return "busy";
break;
case Doctrine_Transaction::STATE_ACTIVE:
return "active";
case Doctrine_Transaction::STATE_ACTIVE:
return "active";
break;
endswitch;
};
}
/**
* returns a string representation of Doctrine_Connection object
@ -100,17 +100,18 @@ class Doctrine_Lib {
$r[] = "Table in memory : ".$connection->count();
$queries = false;
if($connection->getDBH() instanceof Doctrine_Db) {
if ($connection->getDBH() instanceof Doctrine_Db) {
$handler = "Doctrine Database Handler";
$queries = count($connection->getDBH()->getQueries());
$sum = array_sum($connection->getDBH()->getExecTimes());
} elseif($connection->getDBH() instanceof PDO) {
} elseif ($connection->getDBH() instanceof PDO) {
$handler = "PHP Native PDO Driver";
} else
} else {
$handler = "Unknown Database Handler";
}
$r[] = "DB Handler : ".$handler;
if($queries) {
if ($queries) {
$r[] = "Executed Queries : ".$queries;
$r[] = "Sum of Exec Times : ".$sum;
}
@ -162,11 +163,10 @@ class Doctrine_Lib {
$r[] = "<pre>";
$r[] = get_class($collection);
foreach($collection as $key => $record) {
foreach ($collection as $key => $record) {
$r[] = "Key : ".$key." ID : ".$record->obtainIdentifier();
}
$r[] = "</pre>";
return implode("\n",$r);
}
}

View File

@ -13,4 +13,3 @@
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Locking_Exception extends Doctrine_Exception {}

View File

@ -279,6 +279,3 @@ class Doctrine_Locking_Manager_Pessimistic {
}
}

View File

@ -85,7 +85,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*/
final public function setDefaultAttributes() {
static $init = false;
if( ! $init) {
if ( ! $init) {
$init = true;
$attributes = array(
Doctrine::ATTR_FETCHMODE => Doctrine::FETCH_IMMEDIATE,
@ -104,10 +104,11 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
Doctrine::ATTR_SEQCOL_NAME => 'id',
Doctrine::ATTR_PORTABILITY => Doctrine::PORTABILITY_ALL,
);
foreach($attributes as $attribute => $value) {
foreach ($attributes as $attribute => $value) {
$old = $this->getAttribute($attribute);
if($old === null)
if ($old === null) {
$this->setAttribute($attribute,$value);
}
}
return true;
}
@ -130,9 +131,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*/
public static function getInstance() {
static $instance;
if( ! isset($instance))
if ( ! isset($instance)) {
$instance = new self();
}
return $instance;
}
/**
@ -150,7 +151,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* @return Doctrine_Connection
*/
public static function connection($adapter = null, $name = null) {
if($adapter == null) {
if ($adapter == null) {
return Doctrine_Manager::getInstance()->getCurrentConnection();
} else {
return Doctrine_Manager::getInstance()->openConnection($adapter, $name);
@ -166,52 +167,51 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* @return Doctrine_Connection
*/
public function openConnection($adapter, $name = null) {
if( ! ($adapter instanceof PDO) && ! in_array('Doctrine_Adapter_Interface', class_implements($adapter)))
if ( ! ($adapter instanceof PDO) && ! in_array('Doctrine_Adapter_Interface', class_implements($adapter))) {
throw new Doctrine_Manager_Exception("First argument should be an instance of PDO or implement Doctrine_Adapter_Interface");
}
// initialize the default attributes
$this->setDefaultAttributes();
if($name !== null) {
if ($name !== null) {
$name = (string) $name;
if(isset($this->connections[$name]))
if (isset($this->connections[$name])) {
throw new Doctrine_Manager_Exception("Connection with $name already exists!");
}
} else {
$name = $this->index;
$this->index++;
}
switch($adapter->getAttribute(PDO::ATTR_DRIVER_NAME)):
case 'mysql':
$this->connections[$name] = new Doctrine_Connection_Mysql($this, $adapter);
switch ($adapter->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'mysql':
$this->connections[$name] = new Doctrine_Connection_Mysql($this, $adapter);
break;
case 'sqlite':
$this->connections[$name] = new Doctrine_Connection_Sqlite($this, $adapter);
case 'sqlite':
$this->connections[$name] = new Doctrine_Connection_Sqlite($this, $adapter);
break;
case 'pgsql':
$this->connections[$name] = new Doctrine_Connection_Pgsql($this, $adapter);
case 'pgsql':
$this->connections[$name] = new Doctrine_Connection_Pgsql($this, $adapter);
break;
case 'oci':
case 'oracle':
$this->connections[$name] = new Doctrine_Connection_Oracle($this, $adapter);
case 'oci':
case 'oracle':
$this->connections[$name] = new Doctrine_Connection_Oracle($this, $adapter);
break;
case 'mssql':
$this->connections[$name] = new Doctrine_Connection_Mssql($this, $adapter);
case 'mssql':
$this->connections[$name] = new Doctrine_Connection_Mssql($this, $adapter);
break;
case 'firebird':
$this->connections[$name] = new Doctrine_Connection_Firebird($this, $adapter);
case 'firebird':
$this->connections[$name] = new Doctrine_Connection_Firebird($this, $adapter);
break;
case 'informix':
$this->connections[$name] = new Doctrine_Connection_Informix($this, $adapter);
case 'informix':
$this->connections[$name] = new Doctrine_Connection_Informix($this, $adapter);
break;
case 'mock':
$this->connections[$name] = new Doctrine_Connection_Mock($this, $adapter);
break;
default:
throw new Doctrine_Manager_Exception('Unknown connection driver '. $adapter->getAttribute(PDO::ATTR_DRIVER_NAME));
endswitch;
case 'mock':
$this->connections[$name] = new Doctrine_Connection_Mock($this, $adapter);
break;
default:
throw new Doctrine_Manager_Exception('Unknown connection driver '. $adapter->getAttribute(PDO::ATTR_DRIVER_NAME));
};
$this->currIndex = $name;
return $this->connections[$name];
@ -226,9 +226,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* @throws Doctrine_Manager_Exception if trying to get a non-existent connection
*/
public function getConnection($name) {
if( ! isset($this->connections[$name]))
if ( ! isset($this->connections[$name])) {
throw new Doctrine_Manager_Exception('Unknown connection: ' . $name);
}
$this->currIndex = $name;
return $this->connections[$name];
}
@ -252,9 +252,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* @return Doctrine_Connection
*/
public function getConnectionForComponent($componentName = null) {
if(isset($this->bound[$componentName]))
if (isset($this->bound[$componentName])) {
return $this->getConnection($this->bound[$componentName]);
}
return $this->getCurrentConnection();
}
/**
@ -298,9 +298,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*/
public function setCurrentConnection($key) {
$key = (string) $key;
if( ! isset($this->connections[$key]))
if ( ! isset($this->connections[$key])) {
throw new InvalidKeyException();
}
$this->currIndex = $key;
}
/**
@ -330,9 +330,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*/
public function getCurrentConnection() {
$i = $this->currIndex;
if( ! isset($this->connections[$i]))
if ( ! isset($this->connections[$i])) {
throw new Doctrine_Connection_Exception();
}
return $this->connections[$i];
}
/**
@ -349,4 +349,3 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
return implode("\n",$r);
}
}

View File

@ -15,9 +15,9 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part {
$parts = Doctrine_Query::bracketExplode($str, array(' \&\& ', ' AND '), '(', ')');
if(count($parts) > 1) {
if (count($parts) > 1) {
$ret = array();
foreach($parts as $part) {
foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parse($part);
}
@ -25,22 +25,22 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part {
} else {
$parts = Doctrine_Query::bracketExplode($str, array(' \|\| ', ' OR '), '(', ')');
if(count($parts) > 1) {
if (count($parts) > 1) {
$ret = array();
foreach($parts as $part) {
foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parse($part);
}
$r = implode(' OR ',$ret);
} else {
if(substr($parts[0],0,1) == '(' && substr($parts[0],-1) == ')')
if (substr($parts[0],0,1) == '(' && substr($parts[0],-1) == ')') {
return $this->parse(substr($parts[0],1,-1));
else
} else {
return $this->load($parts[0]);
}
}
}
return '(' . $r . ')';
}
}

View File

@ -2,4 +2,3 @@
require_once(Doctrine::getPath().DIRECTORY_SEPARATOR."Doctrine".DIRECTORY_SEPARATOR."Exception.php");
class Doctrine_Query_Exception extends Doctrine_Exception { }

View File

@ -45,34 +45,34 @@ class Doctrine_Query_From extends Doctrine_Query_Part {
$operator = false;
switch(trim($parts[0])) {
case 'INNER':
$operator = ':';
case 'LEFT':
array_shift($parts);
switch (trim($parts[0])) {
case 'INNER':
$operator = ':';
case 'LEFT':
array_shift($parts);
}
$last = '';
foreach($parts as $k => $part) {
foreach ($parts as $k => $part) {
$part = trim($part);
if(empty($part)) {
if (empty($part)) {
continue;
}
$e = explode(' ', $part);
if(end($e) == 'INNER' || end($e) == 'LEFT')
if (end($e) == 'INNER' || end($e) == 'LEFT') {
$last = array_pop($e);
}
$part = implode(' ', $e);
foreach(Doctrine_Query::bracketExplode($part, ',') as $reference) {
foreach (Doctrine_Query::bracketExplode($part, ',') as $reference) {
$reference = trim($reference);
$e = explode('.', $reference);
if($operator) {
if ($operator) {
$reference = array_shift($e) . $operator . implode('.', $e);
}
$table = $this->query->load($reference);
@ -86,4 +86,3 @@ class Doctrine_Query_From extends Doctrine_Query_Part {
return ( ! empty($this->parts))?implode(", ", $this->parts):'';
}
}

View File

@ -11,7 +11,7 @@ class Doctrine_Query_Groupby extends Doctrine_Query_Part {
*/
final public function parse($str) {
$r = array();
foreach(explode(",", $str) as $reference) {
foreach (explode(",", $str) as $reference) {
$reference = trim($reference);
$e = explode(".",$reference);
$field = array_pop($e);
@ -27,4 +27,3 @@ class Doctrine_Query_Groupby extends Doctrine_Query_Part {
return ( ! empty($this->parts))?implode(", ", $this->parts):'';
}
}

View File

@ -11,15 +11,14 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition {
private function parseAggregateFunction($func) {
$pos = strpos($func,"(");
if($pos !== false) {
if ($pos !== false) {
$funcs = array();
$name = substr($func, 0, $pos);
$func = substr($func, ($pos + 1), -1);
$params = Doctrine_Query::bracketExplode($func, ",", "(", ")");
foreach($params as $k => $param) {
foreach ($params as $k => $param) {
$params[$k] = $this->parseAggregateFunction($param);
}
@ -28,7 +27,7 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition {
return $funcs;
} else {
if( ! is_numeric($func)) {
if ( ! is_numeric($func)) {
$a = explode(".",$func);
$field = array_pop($a);
$reference = implode(".",$a);
@ -71,4 +70,3 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition {
return ( ! empty($this->parts))?implode(' AND ', $this->parts):'';
}
}

View File

@ -41,27 +41,26 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part {
public function parse($str) {
$ret = array();
foreach(explode(',', trim($str)) as $r) {
foreach (explode(',', trim($str)) as $r) {
$r = trim($r);
$e = explode(' ', $r);
$a = explode('.', $e[0]);
if(count($a) > 1) {
if (count($a) > 1) {
$field = array_pop($a);
$reference = implode('.', $a);
$name = end($a);
$this->query->load($reference, false);
$alias = $this->query->getTableAlias($reference);
$tname = $this->query->getTable($alias)->getTableName();
$r = $alias . '.' . $field;
if(isset($e[1]))
if (isset($e[1])) {
$r .= ' '.$e[1];
}
}
$ret[] = $r;
}
@ -72,4 +71,3 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part {
return ( ! empty($this->parts))?implode(', ', $this->parts):'';
}
}

View File

@ -75,6 +75,3 @@ abstract class Doctrine_Query_Part extends Doctrine_Access {
public function get($name) { }
public function set($name, $value) { }
}

View File

@ -34,7 +34,7 @@ class Doctrine_Query_Set extends Doctrine_Query_Part {
$parts = Doctrine_Query::sqlExplode($dql, ',');
$result = array();
foreach($parts as $part) {
foreach ($parts as $part) {
$set = Doctrine_Query::sqlExplode($part, '=');
$e = explode('.', trim($set[0]));
@ -50,4 +50,4 @@ class Doctrine_Query_Set extends Doctrine_Query_Part {
return implode(', ', $result);
}
}
?>

View File

@ -14,23 +14,24 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$e = Doctrine_Query::sqlExplode($where);
if(count($e) > 1) {
if (count($e) > 1) {
$tmp = $e[0].' '.$e[1];
if(substr($tmp, 0, 6) == 'EXISTS')
if (substr($tmp, 0, 6) == 'EXISTS') {
return $this->parseExists($where, true);
elseif(substr($where, 0, 10) == 'NOT EXISTS')
} elseif (substr($where, 0, 10) == 'NOT EXISTS') {
return $this->parseExists($where, false);
}
}
if(count($e) < 3) {
if (count($e) < 3) {
$e = Doctrine_Query::sqlExplode($where, array('=', '<', '>', '!='));
}
$r = array_shift($e);
$a = explode('.', $r);
if(count($a) > 1) {
if (count($a) > 1) {
$field = array_pop($a);
$count = count($e);
$slice = array_slice($e, -1, 1);
@ -40,11 +41,9 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$reference = implode('.', $a);
$count = count($a);
$pos = strpos($field, '(');
if($pos !== false) {
if ($pos !== false) {
$func = substr($field, 0, $pos);
$value = trim(substr($field, ($pos + 1), -1));
@ -62,25 +61,25 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$stack = $this->query->getTableStack();
switch($func) {
case 'contains':
case 'regexp':
case 'like':
$operator = $this->getOperator($func);
switch ($func) {
case 'contains':
case 'regexp':
case 'like':
$operator = $this->getOperator($func);
if(empty($relation))
throw new Doctrine_Query_Exception('DQL functions contains/regexp/like can only be used for fields of related components');
$where = array();
foreach($values as $value) {
$where[] = $alias.'.'.$relation->getLocal().
' IN (SELECT '.$relation->getForeign().
' FROM '.$relation->getTable()->getTableName().' WHERE '.$field.$operator.$value.')';
}
$where = implode(' AND ', $where);
if (empty($relation)) {
throw new Doctrine_Query_Exception('DQL functions contains/regexp/like can only be used for fields of related components');
}
$where = array();
foreach ($values as $value) {
$where[] = $alias.'.'.$relation->getLocal().
' IN (SELECT '.$relation->getForeign().
' FROM '.$relation->getTable()->getTableName().' WHERE '.$field.$operator.$value.')';
}
$where = implode(' AND ', $where);
break;
default:
throw new Doctrine_Query_Exception('Unknown DQL function: '.$func);
default:
throw new Doctrine_Query_Exception('Unknown DQL function: '.$func);
}
} else {
$table = $this->query->load($reference, false);
@ -89,47 +88,49 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
// check if value is enumerated value
$enumIndex = $table->enumIndex($field, trim($value, "'"));
if(substr($value, 0, 1) == '(') {
if (substr($value, 0, 1) == '(') {
// trim brackets
$trimmed = Doctrine_Query::bracketTrim($value);
if(substr($trimmed, 0, 4) == 'FROM' || substr($trimmed, 0, 6) == 'SELECT') {
if (substr($trimmed, 0, 4) == 'FROM' || substr($trimmed, 0, 6) == 'SELECT') {
// subquery found
$q = new Doctrine_Query();
$value = '(' . $q->parseQuery($trimmed)->getQuery() . ')';
} elseif(substr($trimmed, 0, 4) == 'SQL:') {
} elseif (substr($trimmed, 0, 4) == 'SQL:') {
$value = '(' . substr($trimmed, 4) . ')';
} else {
// simple in expression found
$e = Doctrine_Query::sqlExplode($trimmed, ',');
$value = array();
foreach($e as $part) {
foreach ($e as $part) {
$index = $table->enumIndex($field, trim($part, "'"));
if($index !== false)
if ($index !== false) {
$value[] = $index;
else
} else {
$value[] = $this->parseLiteralValue($part);
}
}
$value = '(' . implode(', ', $value) . ')';
}
} else {
if($enumIndex !== false)
if ($enumIndex !== false) {
$value = $enumIndex;
else
} else {
$value = $this->parseLiteralValue($value);
}
}
switch($operator) {
case '<':
case '>':
case '=':
case '!=':
if($enumIndex !== false)
$value = $enumIndex;
default:
$where = $alias.'.'.$field.' '.$operator.' '.$value;
switch ($operator) {
case '<':
case '>':
case '=':
case '!=':
if ($enumIndex !== false) {
$value = $enumIndex;
}
default:
$where = $alias.'.'.$field.' '.$operator.' '.$value;
}
}
}
@ -146,20 +147,19 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
*/
public function parseLiteralValue($value) {
// check that value isn't a string
if(strpos($value, '\'') === false) {
if (strpos($value, '\'') === false) {
// parse booleans
if($value == 'true')
if ($value == 'true')
$value = 1;
elseif($value == 'false')
elseif ($value == 'false')
$value = 0;
$a = explode('.', $value);
if(count($a) > 1) {
if (count($a) > 1) {
// either a float or a component..
if( ! is_numeric($a[0])) {
if ( ! is_numeric($a[0])) {
// a component found
$value = $this->query->getTableAlias($a[0]). '.' . $a[1];
}
@ -182,7 +182,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$pos = strpos($where, '(');
if($pos == false)
if ($pos == false)
throw new Doctrine_Query_Exception("Unknown expression, expected '('");
$sub = Doctrine_Query::bracketTrim(substr($where, $pos));
@ -196,15 +196,15 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
* @return string
*/
public function getOperator($func) {
switch($func) {
case 'contains':
$operator = ' = ';
switch ($func) {
case 'contains':
$operator = ' = ';
break;
case 'regexp':
$operator = $this->query->getConnection()->getRegexpOperator();
case 'regexp':
$operator = $this->query->getConnection()->getRegexpOperator();
break;
case 'like':
$operator = ' LIKE ';
case 'like':
$operator = ' LIKE ';
break;
}
return $operator;
@ -219,4 +219,3 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
return ( ! empty($this->parts))?implode(' AND ', $this->parts):'';
}
}

View File

@ -44,26 +44,26 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
* @return Doctrine_RawSql
*/
public function __call($name, $args) {
if( ! isset($this->parts[$name]))
if ( ! isset($this->parts[$name])) {
throw new Doctrine_RawSql_Exception("Unknown overload method $name. Availible overload methods are ".implode(" ",array_keys($this->parts)));
if($name == 'select') {
}
if ($name == 'select') {
preg_match_all('/{([^}{]*)}/U', $args[0], $m);
$this->fields = $m[1];
$this->parts["select"] = array();
} else
} else {
$this->parts[$name][] = $args[0];
}
return $this;
}
/**
* get
*/
public function get($name) {
if( ! isset($this->parts[$name]))
if ( ! isset($this->parts[$name])) {
throw new Doctrine_RawSql_Exception('Unknown query part '.$name);
}
return $this->parts[$name];
}
/**
@ -80,40 +80,42 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
$e = Doctrine_Query::sqlExplode($query,' ');
foreach($e as $k => $part):
foreach ($e as $k => $part) {
$low = strtolower($part);
switch(strtolower($part)):
case "select":
case "from":
case "where":
case "limit":
case "offset":
case "having":
switch (strtolower($part)) {
case "select":
case "from":
case "where":
case "limit":
case "offset":
case "having":
$p = $low;
if ( ! isset($parts[$low])) {
$parts[$low] = array();
}
break;
case "order":
case "group":
$i = ($k + 1);
if (isset($e[$i]) && strtolower($e[$i]) === "by") {
$p = $low;
if( ! isset($parts[$low]))
$parts[$low] = array();
$p .= "by";
$parts[$low."by"] = array();
} else {
$parts[$p][] = $part;
}
break;
case "order":
case "group":
$i = ($k + 1);
if(isset($e[$i]) && strtolower($e[$i]) === "by") {
$p = $low;
$p .= "by";
$parts[$low."by"] = array();
} else
$parts[$p][] = $part;
break;
case "by":
continue;
default:
if( ! isset($parts[$p][0]))
$parts[$p][0] = $part;
else
$parts[$p][0] .= ' '.$part;
endswitch;
endforeach;
case "by":
continue;
default:
if ( ! isset($parts[$p][0])) {
$parts[$p][0] = $part;
} else {
$parts[$p][0] .= ' '.$part;
}
};
};
$this->parts = $parts;
$this->parts["select"] = array();
@ -127,12 +129,12 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
* @return string
*/
public function getQuery() {
foreach($this->fields as $field) {
foreach ($this->fields as $field) {
$e = explode(".", $field);
if( ! isset($e[1]))
if ( ! isset($e[1])) {
throw new Doctrine_RawSql_Exception("All selected fields in Sql query must be in format tableAlias.fieldName");
if( ! isset($this->tables[$e[0]])) {
}
if ( ! isset($this->tables[$e[0]])) {
try {
$this->addComponent($e[0], ucwords($e[0]));
} catch(Doctrine_Exception $exception) {
@ -140,8 +142,8 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
}
}
if($e[1] == '*') {
foreach($this->tables[$e[0]]->getColumnNames() as $name) {
if ($e[1] == '*') {
foreach ($this->tables[$e[0]]->getColumnNames() as $name) {
$field = $e[0].".".$name;
$this->parts["select"][$field] = $field." AS ".$e[0]."__".$name;
}
@ -153,20 +155,21 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
// force-add all primary key fields
foreach($this->tableAliases as $alias) {
foreach($this->tables[$alias]->getPrimaryKeys() as $key) {
foreach ($this->tableAliases as $alias) {
foreach ($this->tables[$alias]->getPrimaryKeys() as $key) {
$field = $alias . '.' . $key;
if( ! isset($this->parts["select"][$field]))
if ( ! isset($this->parts["select"][$field])) {
$this->parts["select"][$field] = $field." AS ".$alias."__".$key;
}
}
}
$q = 'SELECT '.implode(', ', $this->parts['select']);
$string = $this->applyInheritance();
if( ! empty($string))
if ( ! empty($string)) {
$this->parts['where'][] = $string;
}
$copy = $this->parts;
unset($copy['select']);
@ -178,9 +181,9 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
$q .= ( ! empty($this->parts['limit']))? ' LIMIT ' . implode(' ', $this->parts['limit']) : '';
$q .= ( ! empty($this->parts['offset']))? ' OFFSET ' . implode(' ', $this->parts['offset']) : '';
if( ! empty($string))
if ( ! empty($string)) {
array_pop($this->parts['where']);
}
return $q;
}
/**
@ -204,21 +207,20 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
$currPath = '';
$table = null;
foreach($e as $k => $component) {
foreach ($e as $k => $component) {
$currPath .= '.' . $component;
if($k == 0)
if ($k == 0)
$currPath = substr($currPath,1);
if(isset($this->tableAliases[$currPath]))
if (isset($this->tableAliases[$currPath])) {
$alias = $this->tableAliases[$currPath];
else
} else {
$alias = $tableAlias;
}
if($table) {
if ($table) {
$tableName = $table->getAliasName($component);
$table = $this->conn->getTable($tableName);
} else {
$table = $this->conn->getTable($component);
@ -227,9 +229,9 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
$this->fetchModes[$alias] = Doctrine::FETCH_IMMEDIATE;
$this->tableAliases[$currPath] = $alias;
if($k !== 0)
if ($k !== 0) {
$this->joins[$alias] = $prevAlias;
}
$prevAlias = $alias;
$prevPath = $currPath;
}
@ -238,4 +240,3 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
}
}

View File

@ -136,7 +136,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @throws Doctrine_Record_Exception if the cleanData operation fails somehow
*/
public function __construct($table = null, $isNewEntry = false) {
if(isset($table) && $table instanceof Doctrine_Table) {
if (isset($table) && $table instanceof Doctrine_Table) {
$this->_table = $table;
$exists = ( ! $isNewEntry);
} else {
@ -150,15 +150,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
// If not this record is only used for creating table definition and setting up
// relations.
if($this->_table->getConnection()->hasTable($this->_table->getComponentName())) {
if ($this->_table->getConnection()->hasTable($this->_table->getComponentName())) {
$this->oid = self::$index;
self::$index++;
$keys = $this->_table->getPrimaryKeys();
if( ! $exists) {
if ( ! $exists) {
// listen the onPreCreate event
$this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onPreCreate($this);
} else {
@ -169,7 +168,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
// get the data array
$this->_data = $this->_table->getData();
// get the column count
$count = count($this->_data);
@ -178,12 +176,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->prepareIdentifiers($exists);
if( ! $exists) {
if($count > 0)
if ( ! $exists) {
if ($count > 0) {
$this->_state = Doctrine_Record::STATE_TDIRTY;
else
} else {
$this->_state = Doctrine_Record::STATE_TCLEAN;
}
// set the default values for this record
$this->setDefaultValues();
@ -194,7 +192,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
} else {
$this->_state = Doctrine_Record::STATE_CLEAN;
if($count < $this->_table->getColumnCount()) {
if ($count < $this->_table->getColumnCount()) {
$this->_state = Doctrine_Record::STATE_PROXY;
}
@ -255,9 +253,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return boolean whether or not this record passes all column validations
*/
public function isValid() {
if( ! $this->_table->getAttribute(Doctrine::ATTR_VLD))
if ( ! $this->_table->getAttribute(Doctrine::ATTR_VLD)) {
return true;
}
// Clear the stack from any previous errors.
$this->_errorStack->clear();
@ -307,16 +305,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return boolean
*/
public function setDefaultValues($overwrite = false) {
if( ! $this->_table->hasDefaultValues())
if ( ! $this->_table->hasDefaultValues()) {
return false;
foreach($this->_data as $column => $value) {
}
foreach ($this->_data as $column => $value) {
$default = $this->_table->getDefaultValueOf($column);
if($default === null)
if ($default === null)
$default = self::$null;
if($value === self::$null || $overwrite) {
if ($value === self::$null || $overwrite) {
$this->_data[$column] = $default;
$this->_modified[] = $column;
$this->_state = Doctrine_Record::STATE_TDIRTY;
@ -354,51 +352,49 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$count = 0;
foreach($this->_table->getColumnNames() as $name) {
foreach ($this->_table->getColumnNames() as $name) {
$type = $this->_table->getTypeOf($name);
if( ! isset($tmp[$name])) {
if ( ! isset($tmp[$name])) {
$this->_data[$name] = self::$null;
} else {
switch($type):
case "array":
case "object":
switch ($type) {
case "array":
case "object":
if($tmp[$name] !== self::$null) {
if(is_string($tmp[$name])) {
$value = unserialize($tmp[$name]);
if ($tmp[$name] !== self::$null) {
if (is_string($tmp[$name])) {
$value = unserialize($tmp[$name]);
if($value === false)
throw new Doctrine_Record_Exception("Unserialization of $name failed.");
} else
$value = $tmp[$name];
$this->_data[$name] = $value;
if ($value === false)
throw new Doctrine_Record_Exception("Unserialization of $name failed.");
} else {
$value = $tmp[$name];
}
$this->_data[$name] = $value;
}
break;
case "gzip":
case "gzip":
if($tmp[$name] !== self::$null) {
$value = gzuncompress($tmp[$name]);
if ($tmp[$name] !== self::$null) {
$value = gzuncompress($tmp[$name]);
if ($value === false)
throw new Doctrine_Record_Exception("Uncompressing of $name failed.");
if($value === false)
throw new Doctrine_Record_Exception("Uncompressing of $name failed.");
$this->_data[$name] = $value;
}
$this->_data[$name] = $value;
}
break;
case "enum":
$this->_data[$name] = $this->_table->enumValue($name, $tmp[$name]);
case "enum":
$this->_data[$name] = $this->_table->enumValue($name, $tmp[$name]);
break;
default:
$this->_data[$name] = $tmp[$name];
endswitch;
default:
$this->_data[$name] = $tmp[$name];
};
$count++;
}
}
return $count;
}
/**
@ -409,38 +405,40 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
private function prepareIdentifiers($exists = true) {
switch($this->_table->getIdentifierType()):
case Doctrine_Identifier::AUTO_INCREMENT:
case Doctrine_Identifier::SEQUENCE:
$name = $this->_table->getIdentifier();
switch ($this->_table->getIdentifierType()) {
case Doctrine_Identifier::AUTO_INCREMENT:
case Doctrine_Identifier::SEQUENCE:
$name = $this->_table->getIdentifier();
if($exists) {
if(isset($this->_data[$name]) && $this->_data[$name] !== self::$null)
$this->_id[$name] = $this->_data[$name];
}
unset($this->_data[$name]);
break;
case Doctrine_Identifier::NORMAL:
$this->_id = array();
$name = $this->_table->getIdentifier();
if(isset($this->_data[$name]) && $this->_data[$name] !== self::$null)
if ($exists) {
if (isset($this->_data[$name]) && $this->_data[$name] !== self::$null) {
$this->_id[$name] = $this->_data[$name];
break;
case Doctrine_Identifier::COMPOSITE:
$names = $this->_table->getIdentifier();
foreach($names as $name) {
if($this->_data[$name] === self::$null)
$this->_id[$name] = null;
else
$this->_id[$name] = $this->_data[$name];
}
}
unset($this->_data[$name]);
break;
endswitch;
case Doctrine_Identifier::NORMAL:
$this->_id = array();
$name = $this->_table->getIdentifier();
if (isset($this->_data[$name]) && $this->_data[$name] !== self::$null) {
$this->_id[$name] = $this->_data[$name];
}
break;
case Doctrine_Identifier::COMPOSITE:
$names = $this->_table->getIdentifier();
foreach ($names as $name) {
if ($this->_data[$name] === self::$null) {
$this->_id[$name] = null;
} else {
$this->_id[$name] = $this->_data[$name];
}
}
break;
};
}
/**
* serialize
@ -460,18 +458,18 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$name = $this->_table->getIdentifier();
$this->_data = array_merge($this->_data, $this->_id);
foreach($this->_data as $k => $v) {
if($v instanceof Doctrine_Record)
foreach ($this->_data as $k => $v) {
if ($v instanceof Doctrine_Record)
unset($vars['_data'][$k]);
elseif($v === self::$null) {
elseif ($v === self::$null) {
unset($vars['_data'][$k]);
} else {
switch($this->_table->getTypeOf($k)):
case "array":
case "object":
$vars['_data'][$k] = serialize($vars['_data'][$k]);
switch ($this->_table->getTypeOf($k)) {
case "array":
case "object":
$vars['_data'][$k] = serialize($vars['_data'][$k]);
break;
endswitch;
};
}
}
@ -494,10 +492,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->_table = $connection->getTable(get_class($this));
$array = unserialize($serialized);
foreach($array as $name => $values) {
foreach ($array as $name => $values) {
$this->$name = $values;
}
@ -530,34 +527,34 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return null|integer
*/
public function state($state = null) {
if($state == null) {
if ($state == null) {
return $this->_state;
}
$err = false;
if(is_integer($state)) {
if (is_integer($state)) {
if($state >= 1 && $state <= 6)
if ($state >= 1 && $state <= 6) {
$this->_state = $state;
else
} else {
$err = true;
} elseif(is_string($state)) {
}
} elseif (is_string($state)) {
$upper = strtoupper($state);
switch($upper) {
case 'DIRTY':
case 'CLEAN':
case 'TDIRTY':
case 'TCLEAN':
case 'PROXY':
case 'DELETED':
$this->_state = constant('Doctrine_Record::STATE_' . $upper);
switch ($upper) {
case 'DIRTY':
case 'CLEAN':
case 'TDIRTY':
case 'TCLEAN':
case 'PROXY':
case 'DELETED':
$this->_state = constant('Doctrine_Record::STATE_' . $upper);
break;
default:
$err = true;
default:
$err = true;
}
}
if($err)
if ($err)
throw new Doctrine_Record_State_Exception('Unknown record state ' . $state);
}
/**
@ -570,12 +567,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/
final public function refresh() {
$id = $this->obtainIdentifier();
if( ! is_array($id))
if ( ! is_array($id)) {
$id = array($id);
if(empty($id))
}
if (empty($id)) {
return false;
}
$id = array_values($id);
$query = $this->_table->getQuery()." WHERE ".implode(" = ? AND ",$this->_table->getPrimaryKeys())." = ?";
@ -583,8 +580,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->_data = $stmt->fetch(PDO::FETCH_ASSOC);
if( ! $this->_data)
if ( ! $this->_data)
throw new Doctrine_Record_Exception('Failed to refresh. Record does not exist anymore');
$this->_data = array_change_key_case($this->_data, CASE_LOWER);
@ -615,7 +611,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->prepareIdentifiers();
if($this->_id != $old)
if ($this->_id != $old)
throw new Doctrine_Record_Exception("The refreshed primary key doesn't match the one in the record memory.", Doctrine::ERR_REFRESH);
$this->_state = Doctrine_Record::STATE_CLEAN;
@ -652,10 +648,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/
public function rawGet($name) {
if( ! isset($this->_data[$name]))
if ( ! isset($this->_data[$name])) {
throw new Doctrine_Record_Exception('Unknown property '. $name);
if($this->_data[$name] === self::$null)
}
if ($this->_data[$name] === self::$null)
return null;
return $this->_data[$name];
@ -669,7 +665,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/
public function load() {
// only load the data from database if the Doctrine_Record is in proxy state
if($this->_state == Doctrine_Record::STATE_PROXY) {
if ($this->_state == Doctrine_Record::STATE_PROXY) {
$this->refresh();
$this->_state = Doctrine_Record::STATE_CLEAN;
@ -693,48 +689,46 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$value = self::$null;
$lower = strtolower($name);
if(isset($this->_data[$lower])) {
if (isset($this->_data[$lower])) {
// check if the property is null (= it is the Doctrine_Null object located in self::$null)
if($this->_data[$lower] === self::$null)
if ($this->_data[$lower] === self::$null) {
$this->load();
}
if($this->_data[$lower] === self::$null)
if ($this->_data[$lower] === self::$null) {
$value = null;
else
} else {
$value = $this->_data[$lower];
}
}
if($value !== self::$null) {
if ($value !== self::$null) {
$value = $this->_table->invokeGet($this, $name, $value);
if($invoke && $name !== $this->_table->getIdentifier())
if ($invoke && $name !== $this->_table->getIdentifier()) {
return $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onGetProperty($this, $name, $value);
else
} else {
return $value;
}
return $value;
}
if(isset($this->_id[$lower]))
if (isset($this->_id[$lower])) {
return $this->_id[$lower];
if($name === $this->_table->getIdentifier())
}
if ($name === $this->_table->getIdentifier()) {
return null;
if(isset($this->_values[$lower]))
}
if (isset($this->_values[$lower])) {
return $this->_values[$lower];
}
$rel = $this->_table->getRelation($name);
try {
if( ! isset($this->references[$name]))
if ( ! isset($this->references[$name])) {
$this->loadReference($name);
}
} catch(Doctrine_Table_Exception $e) {
throw new Doctrine_Record_Exception("Unknown property / related component '$name'.");
}
@ -772,39 +766,38 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function set($name, $value, $load = true) {
$lower = strtolower($name);
if(isset($this->_data[$lower])) {
if($value instanceof Doctrine_Record) {
if (isset($this->_data[$lower])) {
if ($value instanceof Doctrine_Record) {
$id = $value->getIncremented();
if($id !== null)
if ($id !== null)
$value = $id;
}
if($load)
if ($load) {
$old = $this->get($lower, false);
else
} else {
$old = $this->_data[$lower];
}
if($old !== $value) {
if ($old !== $value) {
$value = $this->_table->invokeSet($this, $name, $value);
$value = $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onSetProperty($this, $name, $value);
if($value === null)
if ($value === null)
$value = self::$null;
$this->_data[$lower] = $value;
$this->_modified[] = $lower;
switch($this->_state):
case Doctrine_Record::STATE_CLEAN:
$this->_state = Doctrine_Record::STATE_DIRTY;
switch ($this->_state) {
case Doctrine_Record::STATE_CLEAN:
$this->_state = Doctrine_Record::STATE_DIRTY;
break;
case Doctrine_Record::STATE_TCLEAN:
$this->_state = Doctrine_Record::STATE_TDIRTY;
case Doctrine_Record::STATE_TCLEAN:
$this->_state = Doctrine_Record::STATE_TDIRTY;
break;
endswitch;
};
}
} else {
try {
@ -819,31 +812,31 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$rel = $this->_table->getRelation($name);
// one-to-many or one-to-one relation
if($rel instanceof Doctrine_Relation_ForeignKey ||
if ($rel instanceof Doctrine_Relation_ForeignKey ||
$rel instanceof Doctrine_Relation_LocalKey) {
if( ! $rel->isOneToOne()) {
if ( ! $rel->isOneToOne()) {
// one-to-many relation found
if( ! ($value instanceof Doctrine_Collection))
if ( ! ($value instanceof Doctrine_Collection)) {
throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references.");
}
$value->setReference($this,$rel);
} else {
// one-to-one relation found
if( ! ($value instanceof Doctrine_Record))
if ( ! ($value instanceof Doctrine_Record)) {
throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Record when setting one-to-one references.");
if($rel instanceof Doctrine_Relation_LocalKey) {
}
if ($rel instanceof Doctrine_Relation_LocalKey) {
$this->set($rel->getLocal(), $value, false);
} else {
$value->set($rel->getForeign(), $this, false);
}
}
} elseif($rel instanceof Doctrine_Relation_Association) {
} elseif ($rel instanceof Doctrine_Relation_Association) {
// join table relation found
if( ! ($value instanceof Doctrine_Collection))
if ( ! ($value instanceof Doctrine_Collection)) {
throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Collection when setting many-to-many references.");
}
}
$this->references[$name] = $value;
@ -857,15 +850,15 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function contains($name) {
$lower = strtolower($name);
if(isset($this->_data[$lower]))
if (isset($this->_data[$lower])) {
return true;
if(isset($this->_id[$lower]))
}
if (isset($this->_id[$lower])) {
return true;
if(isset($this->references[$name]))
}
if (isset($this->references[$name])) {
return true;
}
return false;
}
/**
@ -873,9 +866,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
public function __unset($name) {
if(isset($this->_data[$name]))
if (isset($this->_data[$name])) {
$this->_data[$name] = array();
}
// todo: what to do with references ?
}
/**
@ -894,7 +887,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
$conn->beginTransaction();
$saveLater = $conn->unitOfWork->saveRelated($this);
if ($this->isValid()) {
@ -903,11 +895,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$conn->transaction->addInvalid($this);
}
foreach($saveLater as $fk) {
foreach ($saveLater as $fk) {
$table = $fk->getTable();
$alias = $this->_table->getAlias($table->getComponentName());
if(isset($this->references[$alias])) {
if (isset($this->references[$alias])) {
$obj = $this->references[$alias];
$obj->save();
}
@ -952,7 +944,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function getModified() {
$a = array();
foreach($this->_modified as $k => $v) {
foreach ($this->_modified as $k => $v) {
$a[$v] = $this->_data[$v];
}
return $a;
@ -969,43 +961,43 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function getPrepared(array $array = array()) {
$a = array();
if(empty($array))
if (empty($array)) {
$array = $this->_modified;
foreach($array as $k => $v) {
}
foreach ($array as $k => $v) {
$type = $this->_table->getTypeOf($v);
if($this->_data[$v] === self::$null) {
if ($this->_data[$v] === self::$null) {
$a[$v] = null;
continue;
}
switch($type) {
case 'array':
case 'object':
$a[$v] = serialize($this->_data[$v]);
switch ($type) {
case 'array':
case 'object':
$a[$v] = serialize($this->_data[$v]);
break;
case 'gzip':
$a[$v] = gzcompress($this->_data[$v],5);
case 'gzip':
$a[$v] = gzcompress($this->_data[$v],5);
break;
case 'boolean':
$a[$v] = (int) $this->_data[$v];
case 'boolean':
$a[$v] = (int) $this->_data[$v];
break;
case 'enum':
$a[$v] = $this->_table->enumIndex($v,$this->_data[$v]);
break;
case 'enum':
$a[$v] = $this->_table->enumIndex($v,$this->_data[$v]);
break;
default:
if($this->_data[$v] instanceof Doctrine_Record)
$this->_data[$v] = $this->_data[$v]->getIncremented();
default:
if ($this->_data[$v] instanceof Doctrine_Record)
$this->_data[$v] = $this->_data[$v]->getIncremented();
$a[$v] = $this->_data[$v];
$a[$v] = $this->_data[$v];
}
}
foreach($this->_table->getInheritanceMap() as $k => $v) {
foreach ($this->_table->getInheritanceMap() as $k => $v) {
$old = $this->get($k, false);
if((string) $old !== (string) $v || $old === null) {
if ((string) $old !== (string) $v || $old === null) {
$a[$k] = $v;
$this->_data[$k] = $v;
}
@ -1039,10 +1031,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function toArray() {
$a = array();
foreach($this as $column => $value) {
foreach ($this as $column => $value) {
$a[$column] = $value;
}
if($this->_table->getIdentifierType() == Doctrine_Identifier::AUTO_INCREMENT) {
if ($this->_table->getIdentifierType() == Doctrine_Identifier::AUTO_INCREMENT) {
$i = $this->_table->getIdentifier();
$a[$i] = $this->getIncremented();
}
@ -1064,8 +1056,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return boolean
*/
public function hasRelation($name) {
if(isset($this->_data[$name]) || isset($this->_id[$name]))
if (isset($this->_data[$name]) || isset($this->_id[$name])) {
return true;
}
return $this->_table->hasRelation($name);
}
/**
@ -1082,9 +1075,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return Doctrine_Collection|false
*/
public function obtainOriginals($name) {
if(isset($this->originals[$name]))
if (isset($this->originals[$name])) {
return $this->originals[$name];
}
return false;
}
/**
@ -1110,9 +1103,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function copy() {
$ret = $this->_table->create($this->_data);
$modified = array();
foreach($this->_data as $key => $val)
if (!($val instanceof Doctrine_Null))
foreach ($this->_data as $key => $val) {
if (!($val instanceof Doctrine_Null)) {
$ret->_modified[] = $key;
}
}
return $ret;
}
/**
@ -1122,12 +1117,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
final public function assignIdentifier($id = false) {
if($id === false) {
if ($id === false) {
$this->_id = array();
$this->cleanData();
$this->_state = Doctrine_Record::STATE_TCLEAN;
$this->_modified = array();
} elseif($id === true) {
} elseif ($id === true) {
$this->prepareIdentifiers(false);
$this->_state = Doctrine_Record::STATE_CLEAN;
$this->_modified = array();
@ -1164,7 +1159,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/
final public function getIncremented() {
$id = current($this->_id);
if($id === false)
if ($id === false)
return null;
return $id;
@ -1195,9 +1190,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @throws Doctrine_Record_Exception if trying to get an unknown related component
*/
public function obtainReference($name) {
if(isset($this->references[$name]))
if (isset($this->references[$name])) {
return $this->references[$name];
}
throw new Doctrine_Record_Exception("Unknown reference $name");
}
/**
@ -1210,13 +1205,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function initReference(Doctrine_Collection $coll, Doctrine_Relation $connector) {
$alias = $connector->getAlias();
if(isset($this->references[$alias]))
if (isset($this->references[$alias])) {
return false;
if( ! $connector->isOneToOne()) {
if( ! ($connector instanceof Doctrine_Relation_Association))
}
if ( ! $connector->isOneToOne()) {
if ( ! ($connector instanceof Doctrine_Relation_Association)) {
$coll->setReference($this, $connector);
}
$this->references[$alias] = $coll;
$this->originals[$alias] = clone $coll;
@ -1268,7 +1263,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
final public function loadReference($name) {
$fk = $this->_table->getRelation($name);
if($fk->isOneToOne()) {
if ($fk->isOneToOne()) {
$this->references[$name] = $fk->fetchRelatedFor($this);
} else {
$coll = $fk->fetchRelatedFor($this);
@ -1360,10 +1355,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
public function merge(array $values) {
foreach($this->_table->getColumnNames() as $value) {
foreach ($this->_table->getColumnNames() as $value) {
try {
if(isset($values[$value]))
if (isset($values[$value])) {
$this->set($value, $values[$value]);
}
} catch(Exception $e) {
// silence all exceptions
}
@ -1382,10 +1378,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->_table->setEnumValues($column, $values);
}
public function option($name, $value = null) {
if($value == null)
if ($value == null) {
$this->_table->getOption($name);
else
} else {
$this->_table->setOption($name, $value);
}
}
public function hasIndex($name ) {
@ -1433,7 +1430,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$args = func_get_args();
array_shift($args);
if(isset($args[0])) {
if (isset($args[0])) {
$column = $args[0];
$args[0] = $this->get($column);
@ -1450,4 +1447,3 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
return Doctrine_Lib::getRecordAsString($this);
}
}

View File

@ -33,10 +33,10 @@ class Doctrine_Record_Iterator extends ArrayIterator {
public function current() {
$value = parent::current();
if($value === self::$null)
if ($value === self::$null) {
return null;
else
} else {
return $value;
}
}
}

View File

@ -52,7 +52,6 @@ abstract class Doctrine_Relation {
*/
const MANY_COMPOSITE = 3;
/**
* @var Doctrine_Table $table foreign factory
*/
@ -188,21 +187,21 @@ abstract class Doctrine_Relation {
public static function getDeleteOperations(Doctrine_Collection $old, Doctrine_Collection $new) {
$r = array();
foreach($old as $k => $record) {
foreach ($old as $k => $record) {
$id = $record->getIncremented();
if(empty($id))
if (empty($id)) {
continue;
}
$found = false;
foreach($new as $k2 => $record2) {
if($record2->getIncremented() === $record->getIncremented()) {
foreach ($new as $k2 => $record2) {
if ($record2->getIncremented() === $record->getIncremented()) {
$found = true;
break;
}
}
if( ! $found) {
if ( ! $found) {
$r[] = $record;
unset($old[$k]);
}
@ -230,19 +229,19 @@ abstract class Doctrine_Relation {
public static function getInsertOperations(Doctrine_Collection $old, Doctrine_Collection $new) {
$r = array();
foreach($new as $k => $record) {
foreach ($new as $k => $record) {
$found = false;
$id = $record->getIncremented();
if( ! empty($id)) {
foreach($old as $k2 => $record2) {
if($record2->getIncremented() === $record->getIncremented()) {
if ( ! empty($id)) {
foreach ($old as $k2 => $record2) {
if ($record2->getIncremented() === $record->getIncremented()) {
$found = true;
break;
}
}
}
if( ! $found) {
if ( ! $found) {
$old[] = $record;
$r[] = $record;
}
@ -276,5 +275,3 @@ abstract class Doctrine_Relation {
return implode("\n", $r);
}
}

View File

@ -66,17 +66,15 @@ class Doctrine_Relation_Association extends Doctrine_Relation {
$asf = $this->getAssociationFactory();
$alias = $this->getAlias();
if($record->hasReference($alias)) {
if ($record->hasReference($alias)) {
$new = $record->obtainReference($alias);
if( ! $record->obtainOriginals($alias))
if ( ! $record->obtainOriginals($alias)) {
$record->loadReference($alias);
}
$operations = Doctrine_Relation::getDeleteOperations($record->obtainOriginals($alias), $new);
foreach($operations as $r) {
foreach ($operations as $r) {
$query = 'DELETE FROM ' . $asf->getTableName()
. ' WHERE ' . $this->getForeign() . ' = ?'
. ' AND ' . $this->getLocal() . ' = ?';
@ -86,7 +84,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation {
$operations = Doctrine_Relation::getInsertOperations($record->obtainOriginals($alias),$new);
foreach($operations as $r) {
foreach ($operations as $r) {
$reldao = $asf->create();
$reldao->set($this->getForeign(), $r);
$reldao->set($this->getLocal(), $record);
@ -103,23 +101,23 @@ class Doctrine_Relation_Association extends Doctrine_Relation {
* @return string
*/
public function getRelationDql($count, $context = 'record') {
switch($context):
case "record":
$sub = 'SQL:SELECT ' . $this->foreign.
' FROM ' . $this->associationTable->getTableName().
' WHERE ' . $this->local.
' IN (' . substr(str_repeat("?, ", $count),0,-2) .
')';
switch ($context) {
case "record":
$sub = 'SQL:SELECT ' . $this->foreign.
' FROM ' . $this->associationTable->getTableName().
' WHERE ' . $this->local.
' IN (' . substr(str_repeat("?, ", $count),0,-2) .
')';
$dql = "FROM ".$this->table->getComponentName();
$dql .= ".".$this->associationTable->getComponentName();
$dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier()." IN ($sub)";
$dql = "FROM ".$this->table->getComponentName();
$dql .= ".".$this->associationTable->getComponentName();
$dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier()." IN ($sub)";
break;
case "collection":
$sub = substr(str_repeat("?, ", $count),0,-2);
$dql = "FROM ".$this->associationTable->getComponentName().".".$this->table->getComponentName();
$dql .= " WHERE ".$this->associationTable->getComponentName().".".$this->local." IN ($sub)";
endswitch;
case "collection":
$sub = substr(str_repeat("?, ", $count),0,-2);
$dql = "FROM ".$this->associationTable->getComponentName().".".$this->table->getComponentName();
$dql .= " WHERE ".$this->associationTable->getComponentName().".".$this->local." IN ($sub)";
};
return $dql;
}
@ -133,12 +131,11 @@ class Doctrine_Relation_Association extends Doctrine_Relation {
*/
public function fetchRelatedFor(Doctrine_Record $record) {
$id = $record->getIncremented();
if(empty($id))
if (empty($id)) {
$coll = new Doctrine_Collection($this->table);
else
} else {
$coll = Doctrine_Query::create()->parseQuery($this->getRelationDql(1))->execute(array($id));
}
return $coll;
}
}

View File

@ -38,33 +38,31 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association {
* @return string
*/
public function getRelationDql($count, $context = 'record') {
switch($context):
case 'record':
$sub = 'SELECT '.$this->foreign.
' FROM '.$this->associationTable->getTableName().
' WHERE '.$this->local.
' = ?';
$sub2 = 'SELECT '.$this->local.
' FROM '.$this->associationTable->getTableName().
' WHERE '.$this->foreign.
' = ?';
switch ($context) {
case 'record':
$sub = 'SELECT '.$this->foreign.
' FROM '.$this->associationTable->getTableName().
' WHERE '.$this->local.
' = ?';
$sub2 = 'SELECT '.$this->local.
' FROM '.$this->associationTable->getTableName().
' WHERE '.$this->foreign.
' = ?';
$dql = 'FROM '.$this->table->getComponentName();
$dql .= '.'.$this->associationTable->getComponentName();
$dql .= ' WHERE '.$this->table->getComponentName().'.'.$this->table->getIdentifier().' IN ('.$sub.')';
$dql .= ' || '.$this->table->getComponentName().'.'.$this->table->getIdentifier().' IN ('.$sub2.')';
$dql = 'FROM '.$this->table->getComponentName();
$dql .= '.'.$this->associationTable->getComponentName();
$dql .= ' WHERE '.$this->table->getComponentName().'.'.$this->table->getIdentifier().' IN ('.$sub.')';
$dql .= ' || '.$this->table->getComponentName().'.'.$this->table->getIdentifier().' IN ('.$sub2.')';
break;
case 'collection':
$sub = substr(str_repeat('?, ', $count),0,-2);
$dql = 'FROM '.$this->associationTable->getComponentName().'.'.$this->table->getComponentName();
$dql .= ' WHERE '.$this->associationTable->getComponentName().'.'.$this->local.' IN ('.$sub.')';
endswitch;
case 'collection':
$sub = substr(str_repeat('?, ', $count),0,-2);
$dql = 'FROM '.$this->associationTable->getComponentName().'.'.$this->table->getComponentName();
$dql .= ' WHERE '.$this->associationTable->getComponentName().'.'.$this->local.' IN ('.$sub.')';
};
return $dql;
}
public function fetchRelatedFor(Doctrine_Record $record) {
$id = $record->getIncremented();
@ -98,4 +96,4 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association {
return $q->execute(array($id, $id));
}
}
?>

View File

@ -40,20 +40,22 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation {
public function processDiff(Doctrine_Record $record) {
$alias = $this->getAlias();
if($this->isOneToOne()) {
if($record->obtainOriginals($alias) &&
$record->obtainOriginals($alias)->obtainIdentifier() != $this->obtainReference($alias)->obtainIdentifier())
if ($this->isOneToOne()) {
if ($record->obtainOriginals($alias)
&& $record->obtainOriginals($alias)->obtainIdentifier() != $this->obtainReference($alias)->obtainIdentifier()
) {
$record->obtainOriginals($alias)->delete();
}
} else {
if($record->hasReference($alias)) {
if ($record->hasReference($alias)) {
$new = $record->obtainReference($alias);
if( ! $record->obtainOriginals($alias))
if ( ! $record->obtainOriginals($alias)) {
$record->loadReference($alias);
}
$operations = Doctrine_Relation::getDeleteOperations($record->obtainOriginals($alias), $new);
foreach($operations as $r) {
foreach ($operations as $r) {
$r->delete();
}
@ -72,8 +74,8 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation {
public function fetchRelatedFor(Doctrine_Record $record) {
$id = $record->get($this->local);
if($this->isOneToOne()) {
if(empty($id)) {
if ($this->isOneToOne()) {
if (empty($id)) {
$related = $this->table->create();
} else {
$dql = "FROM ".$this->table->getComponentName()." WHERE ".$this->table->getComponentName().".".$this->foreign." = ?";
@ -84,7 +86,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation {
$related->set($this->foreign, $record, false);
} else {
if(empty($id)) {
if (empty($id)) {
$related = new Doctrine_Collection($this->table);
} else {
$query = $this->getRelationDql(1);

View File

@ -40,9 +40,11 @@ class Doctrine_Relation_LocalKey extends Doctrine_Relation {
public function processDiff(Doctrine_Record $record) {
$alias = $this->getAlias();
if($record->obtainOriginals($alias) &&
$record->obtainOriginals($alias)->obtainIdentifier() != $this->references[$alias]->obtainIdentifier())
if ($record->obtainOriginals($alias)
&& $record->obtainOriginals($alias)->obtainIdentifier() != $this->references[$alias]->obtainIdentifier()
) {
$record->obtainOriginals($alias)->delete();
}
}
/**
* fetchRelatedFor
@ -55,11 +57,12 @@ class Doctrine_Relation_LocalKey extends Doctrine_Relation {
public function fetchRelatedFor(Doctrine_Record $record) {
$id = $record->get($this->local);
if(empty($id))
if (empty($id)) {
$related = $this->table->create();
else {
if( ! ($related = $this->table->find($id)))
} else {
if ( ! ($related = $this->table->find($id))) {
$related = $this->table->create();
}
}
$record->set($this->local, $related, false);

View File

@ -43,7 +43,6 @@ class Doctrine_Schema extends Doctrine_Schema_Object implements Countable, Itera
*/
private $childs;
/**
*
* @param Doctrine_Schema_Database database * @return

View File

@ -52,7 +52,6 @@ class Doctrine_Schema_Column extends Doctrine_Schema_Object implements IteratorA
'autoinc' => false
);
public function getName() {
return $this->definition['name'];
}

View File

@ -39,24 +39,25 @@ abstract class Doctrine_Schema_Object extends Doctrine_Access implements Iterato
protected $definition = array('name' => '');
public function __construct(array $definition = array()) {
foreach($this->definition as $key => $val) {
if(isset($definition[$key]))
foreach ($this->definition as $key => $val) {
if (isset($definition[$key])) {
$this->definition[$key] = $definition[$key];
}
}
}
public function get($name) {
if( ! array_key_exists($name, $this->definition))
if ( ! array_key_exists($name, $this->definition)) {
throw new Doctrine_Schema_Exception('Unknown definition '. $name);
}
return $this->definition[$name];
}
public function set($name, $value) {
if( ! array_key_exists($name, $this->definition))
if ( ! array_key_exists($name, $this->definition)) {
throw new Doctrine_Schema_Exception('Unknown definition '. $name);
}
$this->definition[$name] = $value;
}
@ -73,9 +74,9 @@ abstract class Doctrine_Schema_Object extends Doctrine_Access implements Iterato
* @access public
*/
public function count() {
if( ! empty($this->children))
if ( ! empty($this->children)) {
return count($this->children);
}
return count($this->definition);
}
@ -86,10 +87,9 @@ abstract class Doctrine_Schema_Object extends Doctrine_Access implements Iterato
* @access public
*/
public function getIterator() {
if( ! empty($this->children))
if ( ! empty($this->children)) {
return new ArrayIterator($this->children);
}
return new ArrayIterator($this->definition);
}
}

Some files were not shown because too many files have changed in this diff Show More