1
0
mirror of synced 2025-01-19 06:51:40 +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;
}
/**
@ -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);

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;
}
@ -116,9 +116,10 @@ abstract class Doctrine_Access implements ArrayAccess {
public function offsetSet($offset, $value) {
if ( ! isset($offset)) {
$this->add($value);
} else
} else {
$this->set($offset,$value);
}
}
/**
* unset a given offset
* @see set, offsetSet, __set
@ -128,4 +129,3 @@ abstract class Doctrine_Access implements ArrayAccess {
return $this->remove($offset);
}
}

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,11 +77,11 @@ 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);
@ -250,8 +249,9 @@ 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();
@ -288,38 +288,39 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$limit = null;
$offset = null;
switch(get_class($this)):
switch (get_class($this)) {
case "Doctrine_Collection_Offset":
$limit = $this->getLimit();
$offset = (floor($key / $limit) * $limit);
if( ! $this->expandable && isset($this->expanded[$offset]))
if ( ! $this->expandable && isset($this->expanded[$offset])) {
return false;
}
$fields = implode(", ",$this->table->getColumnNames());
break;
default:
if( ! $this->expandable)
if ( ! $this->expandable) {
return false;
}
if( ! isset($this->reference))
if ( ! isset($this->reference)) {
return false;
}
$id = $this->reference->obtainIdentifier();
if(empty($id))
if (empty($id)) {
return false;
}
switch(get_class($this)):
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) {
@ -337,7 +338,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->expandable = false;
}
} elseif ($this->relation instanceof Doctrine_Relation_Association) {
$asf = $this->relation->getAssociationFactory();
@ -366,9 +366,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if ( ! isset($offset)) {
foreach ($coll as $record) {
if(isset($this->reference_field))
if (isset($this->reference_field)) {
$record->set($this->reference_field,$this->reference, false);
}
$this->reference->addReference($record, $this->relation);
}
} else {
@ -377,9 +377,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
foreach ($coll as $record) {
if (isset($this->reference)) {
$this->reference->addReference($record, $this->relation, $i);
} else
} else {
$this->data[$i] = $record;
}
$i++;
}
@ -431,9 +431,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
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)) {
$value = $this->reference->get($this->relation->getLocal());
@ -456,13 +456,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$list = array();
$name = $this->table->getIdentifier();
foreach($this->data as $record):
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)
if ($val === $record) {
return false;
}
}
if (isset($key)) {
if(isset($this->data[$key]))
if (isset($this->data[$key])) {
return false;
}
$this->data[$key] = $record;
return true;
}
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;
}
/**
@ -543,11 +544,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$query = new Doctrine_Query($this->table->getConnection());
if ( ! isset($name)) {
foreach($this->data as $record):
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).")");
@ -561,15 +563,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$list = array();
if ($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) {
foreach($this->data as $record):
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');
@ -601,10 +604,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
} 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)
if ($record->getState() == Doctrine_Record::STATE_TCLEAN
|| $record->getState() == Doctrine_Record::STATE_TDIRTY
) {
continue;
}
$sub = new Doctrine_Collection($table);
foreach ($coll as $k => $related) {
@ -622,14 +626,14 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$name = $table->getComponentName();
foreach ($this->data as $key => $record) {
if($record->getState() == Doctrine_Record::STATE_TCLEAN ||
$record->getState() == Doctrine_Record::STATE_TDIRTY)
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]) {
$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();
}
@ -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)
if ($v->obtainIdentifier() == $id) {
break;
}
} elseif (is_array($v[$identifier])) {
if($v[$identifier] == $id)
if ($v[$identifier] == $id) {
break;
}
}
}
$x = floor($key / $this->batchSize);
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);
@ -123,9 +122,9 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
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])) {
$this->data[$k]->factoryRefresh($this->table);
@ -149,7 +148,7 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
*/
public function get($key) {
if (isset($this->data[$key])) {
switch(gettype($this->data[$key])):
switch (gettype($this->data[$key])) {
case "array":
// Doctrine_Record didn't exist in cache
$this->table->setData($this->data[$key]);
@ -157,21 +156,18 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
$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,9 +69,10 @@ 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];
}
}
/**
* returns the current key
@ -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,10 +32,9 @@ 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) {
@ -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

@ -135,9 +135,9 @@ class Doctrine_Compiler {
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,29 +61,32 @@ abstract class Doctrine_Configurable {
* @return void
*/
public function setAttribute($attribute,$value) {
switch($attribute):
switch ($attribute) {
case Doctrine::ATTR_BATCH_SIZE:
if($value < 0)
if ($value < 0) {
throw new Doctrine_Exception("Batch size should be greater than or equal to zero");
}
break;
case Doctrine::ATTR_FETCHMODE:
if($value < 0)
if ($value < 0) {
throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants.");
}
break;
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)
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)
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.");
}
@ -94,8 +97,9 @@ abstract class Doctrine_Configurable {
case Doctrine::ATTR_ACCESSORS:
$accessors = array('none','get','set','both');
// if( ! in_array($value,$accessors))
// if ( ! in_array($value,$accessors)) {
// throw new Doctrine_Exception();
// }
break;
case Doctrine::ATTR_COLL_LIMIT:
@ -104,13 +108,12 @@ abstract class Doctrine_Configurable {
}
break;
case Doctrine::ATTR_COLL_KEY:
if( ! ($this instanceof Doctrine_Table))
if ( ! ($this instanceof Doctrine_Table)) {
throw new Doctrine_Exception("This attribute can only be set at table level.");
if( ! $this->hasColumn($value))
}
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:
@ -124,9 +127,9 @@ abstract class Doctrine_Configurable {
break;
case Doctrine::ATTR_SEQCOL_NAME:
if( ! is_string($value))
if ( ! is_string($value)) {
throw new Doctrine_Exception('Sequence column name attribute only accepts string values');
}
break;
case Doctrine::ATTR_FIELD_CASE:
if ($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER)
@ -141,7 +144,7 @@ abstract class Doctrine_Configurable {
break;
default:
throw new Doctrine_Exception("Unknown attribute.");
endswitch;
};
$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;
@ -174,9 +177,9 @@ abstract class Doctrine_Configurable {
*/
public function getListener() {
if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
if(isset($this->parent))
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;
@ -209,9 +213,9 @@ abstract class Doctrine_Configurable {
throw new Doctrine_Exception('Unknown attribute.');
if ( ! isset($this->attributes[$attribute])) {
if(isset($this->parent))
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);
@ -151,9 +151,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
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':
@ -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
@ -383,10 +385,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
//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) {
@ -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);
}
/**
@ -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))) {
return new $class($name, $this);
} else {
return new Doctrine_Table($name, $this);
}
}
@ -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;
}
@ -839,8 +837,7 @@ 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()):
switch ($record->getState()) {
case Doctrine_Record::STATE_TDIRTY:
$this->unitOfWork->insert($record);
break;
@ -852,7 +849,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
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

@ -30,4 +30,3 @@ class Doctrine_Connection_Common extends Doctrine_Connection {
return $query;
}
}

View File

@ -46,7 +46,6 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection {
if ($offset == 0) {
return $sql . ' FETCH FIRST '. $count .' ROWS ONLY';
} else {
$sqlPieces = explode('from', $sql);
$select = $sqlPieces[0];
$table = $sqlPieces[1];

View File

@ -112,4 +112,3 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
return $data[0];
}
}

View File

@ -124,9 +124,9 @@ class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Excepti
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

@ -105,12 +105,11 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
*/
public function modifyLimitQuery($query, $limit, $offset, $isManip = false) {
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

@ -85,7 +85,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$this->properties['varchar_max_length'] = 255;
parent::__construct($manager, $adapter);
}
/**
@ -225,17 +224,16 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$values .= $value;
if (isset($fields[$name]['key']) && $fields[$name]['key']) {
if($value === 'NULL')
if ($value === 'NULL') {
throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL');
}
$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

@ -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

@ -157,8 +157,8 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
$tmp = explode('.', $server_info, 3);
if (empty($tmp[2]) && isset($tmp[1])
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)) {
&& 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

@ -46,9 +46,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$tree = array();
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);
@ -146,17 +146,18 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$foreign = $fk->getForeign();
if ($record->getTable()->hasPrimaryKey($fk->getLocal())) {
if( ! $record->exists())
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) {
@ -197,13 +198,13 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
*/
public function deleteComposites(Doctrine_Record $record) {
foreach ($record->getTable()->getRelations() as $fk) {
switch($fk->getType()):
switch ($fk->getType()) {
case Doctrine_Relation::ONE_COMPOSITE:
case Doctrine_Relation::MANY_COMPOSITE:
$obj = $record->get($fk->getAlias());
$obj->delete();
break;
endswitch;
};
}
}
/**
@ -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()):
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;
};
}
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,13 +301,12 @@ 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)) {
@ -326,8 +324,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$id = $table->getMaxIdentifier();
$record->assignIdentifier($id);
} else
} else {
$record->assignIdentifier(true);
}
// listen the onInsert event
$table->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record);

View File

@ -102,5 +102,4 @@ class Doctrine_DataDict_Informix extends Doctrine_DataDict {
}
return '';
}
}

View File

@ -84,7 +84,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
'sqlite2' => 'sqlite',
'sqlite3' => 'sqlite');
/**
* constructor
*
@ -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;
@ -201,9 +200,9 @@ 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;
}
/**
@ -219,20 +218,21 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$names = array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment');
foreach ($names as $name) {
if( ! isset($parts[$name]))
if ( ! isset($parts[$name])) {
$parts[$name] = null;
}
}
if(count($parts) == 0 || ! isset($parts['scheme']))
if (count($parts) == 0 || ! isset($parts['scheme'])) {
throw new Doctrine_Db_Exception('Empty data source name');
}
$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') {
@ -248,15 +248,15 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
case 'firebird':
case 'pgsql':
case 'odbc':
if( ! isset($parts['path']) || $parts['path'] == '/')
if ( ! isset($parts['path']) || $parts['path'] == '/') {
throw new Doctrine_Db_Exception('No database availible in data source name');
if(isset($parts['path']))
}
if (isset($parts['path'])) {
$parts['database'] = substr($parts['path'], 1);
if( ! isset($parts['host']))
}
if ( ! isset($parts['host'])) {
throw new Doctrine_Db_Exception('No hostname set in data source name');
}
$parts['dsn'] = $parts["scheme"].":host=".$parts["host"].";dbname=".$parts["database"];
break;
default:
@ -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++;

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,28 +35,31 @@ 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;
}

View File

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

View File

@ -58,13 +58,14 @@ 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)) {
// pre-event listener found
$a[0]->start();
@ -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).
@ -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

@ -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];
}
/**
@ -427,4 +427,3 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
}
}
}

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'])) {
@ -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;
}
/**
@ -597,9 +597,10 @@ class Doctrine_Export extends Doctrine_Connection_Module {
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) {
@ -621,12 +622,12 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$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

@ -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

@ -93,23 +93,22 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
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'])) {
$optionsSting['charset'] = 'DEFAULT CHARACTER SET '.$options['charset'];
if (isset($options['collate'])) {
@ -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');

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

@ -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

@ -52,11 +52,12 @@ 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)';
}
}
/**
* Returns part of a string.
@ -74,9 +75,10 @@ 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 . ')';
}
}
/**
* Returns a series of strings concatinated

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

@ -95,9 +95,9 @@ 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) {
$e = explode('.', $name);
@ -108,7 +108,6 @@ class Doctrine_Hook {
$table = $this->query->getTable($tableAlias);
if ($def = $table->getDefinitionOf($column)) {
if (isset($this->typeParsers[$def[0]])) {
$name = $this->typeParsers[$def[0]];
$parser = new $name;
@ -134,9 +133,9 @@ 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) {
$e = explode(' ', $name);

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();
}
@ -205,11 +205,12 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
*/
public function remove($name) {
if (isset($this->parts[$name])) {
if($name == "limit" || $name == "offset")
if ($name == "limit" || $name == "offset") {
$this->parts[$name] = false;
else
} else {
$this->parts[$name] = array();
}
}
return $this;
}
/**
@ -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,10 +301,10 @@ 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]):
}
switch ($this->fetchModes[$name]) {
case Doctrine::FETCH_BATCH:
$coll = new Doctrine_Collection_Batch($table);
break;
@ -321,7 +322,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
break;
default:
throw new Doctrine_Exception("Unknown fetchmode");
endswitch;
};
return $coll;
}
@ -333,9 +334,10 @@ 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)
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,35 +387,33 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$coll = $this->getCollection($root);
$prev[$root] = $coll;
if ($this->aggregate)
$return = Doctrine::FETCH_ARRAY;
$array = $this->parseData($stmt);
if ($return == Doctrine::FETCH_ARRAY)
return $array;
foreach ($array as $data) {
/**
* remove duplicated data rows and map data into objects
*/
foreach ($data as $key => $row) {
if(empty($row))
if (empty($row)) {
continue;
}
//$key = array_search($key, $this->shortAliases);
foreach ($this->tables as $k => $t) {
if ( ! strcasecmp($key, $k))
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;
@ -452,10 +454,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
}
if( ! isset($previd[$name]))
if ( ! isset($previd[$name])) {
$previd[$name] = array();
}
if ($previd[$name] !== $row) {
// set internal data
@ -473,15 +474,14 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
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) {
// add record into root collection
$coll->add($record);
unset($previd);
@ -518,9 +518,9 @@ 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()) {
@ -528,10 +528,11 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
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);
}
}
}
return $prev;
}
@ -587,9 +588,10 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
return true;
}
} else {
if( ! isset($row[$ids]))
if ( ! isset($row[$ids])) {
return true;
}
}
return false;
}
/**
@ -602,9 +604,9 @@ 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 = "";
@ -612,24 +614,25 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$index = 0;
foreach ($array as $tableAlias => $maps) {
$a = array();
foreach ($maps as $map) {
$b = array();
foreach ($map as $field => $value) {
if($index > 0)
if ($index > 0) {
$b[] = '(' . $tableAlias . '.' . $field . ' = ' . $value . ' OR ' . $tableAlias . '.' . $field . ' IS NULL)';
else
} else {
$b[] = $tableAlias . '.' . $field . ' = ' . $value;
}
if( ! empty($b))
$a[] = implode(' AND ', $b);
}
if( ! empty($a))
$c[] = implode(' AND ', $a);
if ( ! empty($b)) {
$a[] = implode(' AND ', $b);
}
}
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

@ -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,9 +72,9 @@ 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])) {
$alias = $char . ++$this->shortAliasIndexes[$alias];
}
@ -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

@ -42,13 +42,14 @@ 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');
}
}
/**
*
@ -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;
@ -95,12 +95,12 @@ class Doctrine_Import_Builder {
$i = 0;
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();
@ -120,15 +120,16 @@ class Doctrine_Import_Builder {
$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,7 +137,6 @@ class Doctrine_Import_Builder {
$bytes = file_put_contents($fileName, $content);
if ($bytes === false)
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName);
}

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
@ -100,7 +98,4 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
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

@ -36,7 +36,7 @@ class Doctrine_Lib {
* @return string string representation of given state
*/
public static function getRecordStateAsString($state) {
switch($state):
switch ($state) {
case Doctrine_Record::STATE_PROXY:
return "proxy";
break;
@ -52,7 +52,7 @@ class Doctrine_Lib {
case Doctrine_Record::STATE_TCLEAN:
return "transient clean";
break;
endswitch;
};
}
/**
* returns a string representation of Doctrine_Record object
@ -75,7 +75,7 @@ class Doctrine_Lib {
* @param integer $state connection state
*/
public static function getConnectionStateAsString($state) {
switch($state):
switch ($state) {
case Doctrine_Transaction::STATE_SLEEP:
return "open";
break;
@ -85,7 +85,7 @@ class Doctrine_Lib {
case Doctrine_Transaction::STATE_ACTIVE:
return "active";
break;
endswitch;
};
}
/**
* returns a string representation of Doctrine_Connection object
@ -106,8 +106,9 @@ class Doctrine_Lib {
$sum = array_sum($connection->getDBH()->getExecTimes());
} elseif ($connection->getDBH() instanceof PDO) {
$handler = "PHP Native PDO Driver";
} else
} else {
$handler = "Unknown Database Handler";
}
$r[] = "DB Handler : ".$handler;
if ($queries) {
@ -169,4 +170,3 @@ class Doctrine_Lib {
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

@ -106,9 +106,10 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
);
foreach ($attributes as $attribute => $value) {
$old = $this->getAttribute($attribute);
if($old === null)
if ($old === null) {
$this->setAttribute($attribute,$value);
}
}
return true;
}
return false;
@ -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;
}
/**
@ -166,23 +167,23 @@ 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) {
$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)):
switch ($adapter->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'mysql':
$this->connections[$name] = new Doctrine_Connection_Mysql($this, $adapter);
break;
@ -210,8 +211,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
break;
default:
throw new Doctrine_Manager_Exception('Unknown connection driver '. $adapter->getAttribute(PDO::ATTR_DRIVER_NAME));
endswitch;
};
$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

@ -33,14 +33,14 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_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

@ -63,9 +63,9 @@ class Doctrine_Query_From extends Doctrine_Query_Part {
$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) {
@ -86,4 +86,3 @@ class Doctrine_Query_From extends Doctrine_Query_Part {
return ( ! empty($this->parts))?implode(", ", $this->parts):'';
}
}

View File

@ -27,4 +27,3 @@ class Doctrine_Query_Groupby extends Doctrine_Query_Part {
return ( ! empty($this->parts))?implode(", ", $this->parts):'';
}
}

View File

@ -12,7 +12,6 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition {
$pos = strpos($func,"(");
if ($pos !== false) {
$funcs = array();
$name = substr($func, 0, $pos);
@ -71,4 +70,3 @@ class Doctrine_Query_Having extends Doctrine_Query_Condition {
return ( ! empty($this->parts))?implode(' AND ', $this->parts):'';
}
}

View File

@ -51,18 +51,17 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part {
$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

@ -50,4 +50,4 @@ class Doctrine_Query_Set extends Doctrine_Query_Part {
return implode(', ', $result);
}
}
?>

View File

@ -17,11 +17,12 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
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) {
$e = Doctrine_Query::sqlExplode($where, array('=', '<', '>', '!='));
@ -40,8 +41,6 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$reference = implode('.', $a);
$count = count($a);
$pos = strpos($field, '(');
if ($pos !== false) {
@ -68,9 +67,9 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
case 'like':
$operator = $this->getOperator($func);
if(empty($relation))
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().
@ -106,28 +105,30 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$value = array();
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)
if ($enumIndex !== false) {
$value = $enumIndex;
}
default:
$where = $alias.'.'.$field.' '.$operator.' '.$value;
}
@ -147,7 +148,6 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
public function parseLiteralValue($value) {
// check that value isn't a string
if (strpos($value, '\'') === false) {
// parse booleans
if ($value == 'true')
$value = 1;
@ -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') {
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,9 +80,9 @@ 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)):
switch (strtolower($part)) {
case "select":
case "from":
case "where":
@ -90,9 +90,9 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
case "offset":
case "having":
$p = $low;
if( ! isset($parts[$low]))
if ( ! isset($parts[$low])) {
$parts[$low] = array();
}
break;
case "order":
case "group":
@ -102,18 +102,20 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
$p .= "by";
$parts[$low."by"] = array();
} else
} else {
$parts[$p][] = $part;
}
break;
case "by":
continue;
default:
if( ! isset($parts[$p][0]))
if ( ! isset($parts[$p][0])) {
$parts[$p][0] = $part;
else
} else {
$parts[$p][0] .= ' '.$part;
endswitch;
endforeach;
}
};
};
$this->parts = $parts;
$this->parts["select"] = array();
@ -129,9 +131,9 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
public function getQuery() {
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]])) {
try {
$this->addComponent($e[0], ucwords($e[0]));
@ -156,17 +158,18 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
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;
}
/**
@ -209,16 +212,15 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
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) {
$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

@ -151,7 +151,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
// relations.
if ($this->_table->getConnection()->hasTable($this->_table->getComponentName())) {
$this->oid = self::$index;
self::$index++;
@ -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);
@ -179,11 +177,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->prepareIdentifiers($exists);
if ( ! $exists) {
if($count > 0)
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();
@ -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,9 +305,9 @@ 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) {
$default = $this->_table->getDefaultValueOf($column);
@ -360,7 +358,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if ( ! isset($tmp[$name])) {
$this->_data[$name] = self::$null;
} else {
switch($type):
switch ($type) {
case "array":
case "object":
@ -370,9 +368,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if ($value === false)
throw new Doctrine_Record_Exception("Unserialization of $name failed.");
} else
} else {
$value = $tmp[$name];
}
$this->_data[$name] = $value;
}
break;
@ -381,7 +379,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if ($tmp[$name] !== self::$null) {
$value = gzuncompress($tmp[$name]);
if ($value === false)
throw new Doctrine_Record_Exception("Uncompressing of $name failed.");
@ -393,12 +390,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
break;
default:
$this->_data[$name] = $tmp[$name];
endswitch;
};
$count++;
}
}
return $count;
}
/**
@ -409,15 +405,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
private function prepareIdentifiers($exists = true) {
switch($this->_table->getIdentifierType()):
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)
if (isset($this->_data[$name]) && $this->_data[$name] !== self::$null) {
$this->_id[$name] = $this->_data[$name];
}
}
unset($this->_data[$name]);
@ -426,21 +423,22 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->_id = array();
$name = $this->_table->getIdentifier();
if(isset($this->_data[$name]) && $this->_data[$name] !== self::$null)
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)
if ($this->_data[$name] === self::$null) {
$this->_id[$name] = null;
else
} else {
$this->_id[$name] = $this->_data[$name];
}
}
break;
endswitch;
};
}
/**
* serialize
@ -466,12 +464,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
elseif ($v === self::$null) {
unset($vars['_data'][$k]);
} else {
switch($this->_table->getTypeOf($k)):
switch ($this->_table->getTypeOf($k)) {
case "array":
case "object":
$vars['_data'][$k] = serialize($vars['_data'][$k]);
break;
endswitch;
};
}
}
@ -494,7 +492,6 @@ 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) {
@ -536,11 +533,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$err = false;
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)) {
$upper = strtoupper($state);
switch ($upper) {
@ -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,7 +580,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->_data = $stmt->fetch(PDO::FETCH_ASSOC);
if ( ! $this->_data)
throw new Doctrine_Record_Exception('Failed to refresh. Record does not exist anymore');
@ -652,9 +648,9 @@ 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)
return null;
@ -694,47 +690,45 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$lower = strtolower($name);
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)
$value = null;
else
$value = $this->_data[$lower];
}
if ($this->_data[$lower] === self::$null) {
$value = null;
} else {
$value = $this->_data[$lower];
}
}
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'.");
}
@ -773,7 +767,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$lower = strtolower($name);
if (isset($this->_data[$lower])) {
if ($value instanceof Doctrine_Record) {
$id = $value->getIncremented();
@ -781,13 +774,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$value = $id;
}
if($load)
if ($load) {
$old = $this->get($lower, false);
else
} else {
$old = $this->_data[$lower];
}
if ($old !== $value) {
$value = $this->_table->invokeSet($this, $name, $value);
$value = $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onSetProperty($this, $name, $value);
@ -797,14 +790,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->_data[$lower] = $value;
$this->_modified[] = $lower;
switch($this->_state):
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;
break;
endswitch;
};
}
} else {
try {
@ -823,15 +816,15 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$rel instanceof Doctrine_Relation_LocalKey) {
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) {
$this->set($rel->getLocal(), $value, false);
} else {
@ -841,9 +834,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
} 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()) {
@ -969,9 +961,9 @@ 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) {
$type = $this->_table->getTypeOf($v);
@ -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;
}
/**
@ -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 instanceof Doctrine_Relation_Association)) {
$coll->setReference($this, $connector);
}
$this->references[$alias] = $coll;
$this->originals[$alias] = clone $coll;
@ -1362,8 +1357,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function merge(array $values) {
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,11 +1378,12 @@ 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 ) {
}
@ -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
*/
@ -191,9 +190,9 @@ abstract class Doctrine_Relation {
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()) {
@ -276,5 +275,3 @@ abstract class Doctrine_Relation {
return implode("\n", $r);
}
}

View File

@ -67,13 +67,11 @@ class Doctrine_Relation_Association extends Doctrine_Relation {
$alias = $this->getAlias();
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) {
@ -103,7 +101,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation {
* @return string
*/
public function getRelationDql($count, $context = 'record') {
switch($context):
switch ($context) {
case "record":
$sub = 'SQL:SELECT ' . $this->foreign.
' FROM ' . $this->associationTable->getTableName().
@ -119,7 +117,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation {
$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;
};
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,7 +38,7 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association {
* @return string
*/
public function getRelationDql($count, $context = 'record') {
switch($context):
switch ($context) {
case 'record':
$sub = 'SELECT '.$this->foreign.
' FROM '.$this->associationTable->getTableName().
@ -49,7 +49,6 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association {
' WHERE '.$this->foreign.
' = ?';
$dql = 'FROM '.$this->table->getComponentName();
$dql .= '.'.$this->associationTable->getComponentName();
$dql .= ' WHERE '.$this->table->getComponentName().'.'.$this->table->getIdentifier().' IN ('.$sub.')';
@ -59,12 +58,11 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association {
$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;
};
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

@ -41,16 +41,18 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation {
$alias = $this->getAlias();
if ($this->isOneToOne()) {
if($record->obtainOriginals($alias) &&
$record->obtainOriginals($alias)->obtainIdentifier() != $this->obtainReference($alias)->obtainIdentifier())
if ($record->obtainOriginals($alias)
&& $record->obtainOriginals($alias)->obtainIdentifier() != $this->obtainReference($alias)->obtainIdentifier()
) {
$record->obtainOriginals($alias)->delete();
}
} else {
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) {

View File

@ -40,10 +40,12 @@ 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,12 +57,13 @@ 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

@ -40,23 +40,24 @@ abstract class Doctrine_Schema_Object extends Doctrine_Access implements Iterato
public function __construct(array $definition = array()) {
foreach ($this->definition as $key => $val) {
if(isset($definition[$key]))
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);
}
}

View File

@ -93,7 +93,6 @@ class Doctrine_Schema_Relation extends Doctrine_Schema_Object {
*/
public static $ACTION_SET_DEFAULT = 5;
/**
*
* @param Doctrine_Schema_Column referencing

View File

@ -67,9 +67,9 @@ class Doctrine_Schema_Table extends Doctrine_Schema_Object implements Countable,
* @return Doctrine_Schema_Column|false
*/
public function getColumn($name) {
if( ! isset($this->children[$name]))
if ( ! isset($this->children[$name])) {
return false;
}
return $this->children[$name];
}
/**

View File

@ -135,9 +135,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
'enumMap' => array(),
);
/**
* the constructor
* @throws Doctrine_Connection_Exception if there are no opened connections
@ -151,9 +148,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$this->options['name'] = $name;
if( ! class_exists($name) || empty($name))
if ( ! class_exists($name) || empty($name)) {
throw new Doctrine_Exception("Couldn't find class $name");
}
$record = new $name($this);
$names = array();
@ -180,15 +177,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$this->columnCount = count($this->columns);
if (isset($this->columns)) {
// get the declaring class of setTableDefinition method
$method = new ReflectionMethod($this->options['name'], 'setTableDefinition');
$class = $method->getDeclaringClass();
if( ! isset($this->options['tableName']))
if ( ! isset($this->options['tableName'])) {
$this->options['tableName'] = Doctrine::tableize($class->getName());
switch(count($this->primaryKeys)):
}
switch (count($this->primaryKeys)) {
case 0:
$this->columns = array_merge(array('id' =>
array('integer',
@ -221,7 +217,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$e2 = explode(":",$option);
switch(strtolower($e2[0])):
switch (strtolower($e2[0])) {
case "autoincrement":
$this->identifierType = Doctrine_Identifier::AUTO_INCREMENT;
$found = true;
@ -230,15 +226,15 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$this->identifierType = Doctrine_Identifier::SEQUENCE;
$found = true;
break;
endswitch;
};
}
if( ! isset($this->identifierType))
if ( ! isset($this->identifierType)) {
$this->identifierType = Doctrine_Identifier::NORMAL;
}
$this->identifier = $pk;
}
}
endswitch;
};
if ($this->getAttribute(Doctrine::ATTR_CREATE_TABLES)) {
if (Doctrine::isValidClassname($class->getName())) {
@ -249,12 +245,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$definition['type'] = $column[0];
$definition['length'] = $column[1];
if($definition['type'] == 'enum' && isset($definition['default']))
if ($definition['type'] == 'enum' && isset($definition['default'])) {
$definition['default'] = $this->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;
}
@ -265,13 +261,11 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
}
}
}
} else {
throw new Doctrine_Table_Exception("Class '$name' has no table definition.");
}
$record->setUp();
// save parents
@ -281,9 +275,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$this->query = "SELECT ".implode(", ",array_keys($this->columns))." FROM ".$this->getTableName();
// check if an instance of this table is already initialized
if( ! $this->conn->addTable($this))
if ( ! $this->conn->addTable($this)) {
throw new Doctrine_Table_Exception();
}
$this->repository = new Doctrine_Table_Repository($this);
}
/**
@ -312,8 +306,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
break;
case 'enumMap':
case 'inheritanceMap':
if( ! is_array($value))
if ( ! is_array($value)) {
throw new Doctrine_Table_Exception($name.' should be an array.');
}
break;
}
$this->options[$name] = $value;
@ -323,9 +318,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
return ( ! empty($this->options['inheritanceMap']));
}
public function getOption($name) {
if(isset($this->options[$name]))
if (isset($this->options[$name])) {
return $this->options[$name];
}
return null;
}
/**
@ -337,14 +332,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return void
*/
final public function setColumn($name, $type, $length = null, $options = array()) {
if(is_string($options))
if (is_string($options)) {
$options = explode('|', $options);
}
foreach ($options as $k => $option) {
if (is_numeric($k)) {
if( ! empty($option))
if ( ! empty($option)) {
$options[$option] = true;
}
unset($options[$k]);
}
}
@ -380,15 +375,15 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
*/
public function getDefaultValueOf($column) {
$column = strtolower($column);
if( ! isset($this->columns[$column]))
if ( ! isset($this->columns[$column])) {
throw new Doctrine_Table_Exception("Couldn't get default value. Column ".$column." doesn't exist.");
}
if (isset($this->columns[$column][2]['default'])) {
return $this->columns[$column][2]['default'];
} else
} else {
return null;
}
}
/**
* @return mixed
*/
@ -413,14 +408,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return void
*/
final public function setPrimaryKey($key) {
switch(gettype($key)):
switch (gettype($key)) {
case "array":
$this->primaryKeys = array_values($key);
break;
case "string":
$this->primaryKeys[] = $key;
break;
endswitch;
};
}
/**
* returns all primary keys
@ -476,7 +471,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
foreach ($this->bound as $k=>$a) {
try {
$fk = $this->getRelation($k);
switch($fk->getType()):
switch ($fk->getType()) {
case Doctrine_Relation::ONE_COMPOSITE:
case Doctrine_Relation::MANY_COMPOSITE:
$n = $fk->getTable()->getComponentName();
@ -488,7 +483,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
}
}
break;
endswitch;
};
} catch(Doctrine_Table_Exception $e) {
}
@ -510,9 +505,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return array
*/
public function getBound($name) {
if( ! isset($this->bound[$name]))
if ( ! isset($this->bound[$name])) {
throw new Doctrine_Table_Exception('Unknown bound '.$name);
}
return $this->bound[$name];
}
/**
@ -539,9 +534,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return string
*/
public function getAlias($name) {
if(isset($this->boundAliases[$name]))
if (isset($this->boundAliases[$name])) {
return $this->boundAliases[$name];
}
return $name;
}
/**
@ -551,9 +546,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return string
*/
public function getAliasName($alias) {
if($name = array_search($alias, $this->boundAliases))
if ($name = array_search($alias, $this->boundAliases)) {
return $name;
}
return $alias;
}
/**
@ -574,17 +569,17 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return boolean
*/
public function unbind($name) {
if( ! isset($this->bound[$name]))
if ( ! isset($this->bound[$name])) {
return false;
}
unset($this->bound[$name]);
if(isset($this->relations[$name]))
if (isset($this->relations[$name])) {
unset($this->relations[$name]);
if(isset($this->boundAliases[$name]))
}
if (isset($this->boundAliases[$name])) {
unset($this->boundAliases[$name]);
}
return true;
}
/**
@ -595,18 +590,18 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return void
*/
public function bind($name, $field, $type, $localKey) {
if(isset($this->relations[$name]))
if (isset($this->relations[$name])) {
unset($this->relations[$name]);
}
$e = explode(" as ",$name);
$name = $e[0];
if (isset($e[1])) {
$alias = $e[1];
$this->boundAliases[$name] = $alias;
} else
} else {
$alias = $name;
}
$this->bound[$alias] = array($field, $type, $localKey, $name);
}
@ -635,14 +630,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return boolean
*/
final public function hasRelation($name) {
if(isset($this->bound[$name]))
if (isset($this->bound[$name])) {
return true;
foreach($this->bound as $k=>$v)
{
if($this->hasRelatedComponent($k, $name))
}
foreach ($this->bound as $k=>$v) {
if ($this->hasRelatedComponent($k, $name)) {
return true;
}
}
return false;
}
/**
@ -654,9 +649,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
final public function getRelation($name, $recursive = true) {
$original = $name;
if(isset($this->relations[$name]))
if (isset($this->relations[$name])) {
return $this->relations[$name];
}
if (isset($this->bound[$name])) {
$type = $this->bound[$name][1];
$local = $this->bound[$name][2];
@ -667,24 +662,23 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$table = $this->conn->getTable($name);
if ($component == $this->options['name'] || in_array($component, $this->parents)) {
// ONE-TO-ONE
if ($type == Doctrine_Relation::ONE_COMPOSITE ||
$type == Doctrine_Relation::ONE_AGGREGATE) {
if( ! isset($local))
if ( ! isset($local)) {
$local = $table->getIdentifier();
}
$relation = new Doctrine_Relation_LocalKey($table, $foreign, $local, $type, $alias);
} else
} else {
$relation = new Doctrine_Relation_ForeignKey($table, $foreign, $local, $type, $alias);
}
} elseif ($component == $name ||
($component == $alias)) { // && ($name == $this->options['name'] || in_array($name,$this->parents))
if( ! isset($local))
if ( ! isset($local)) {
$local = $this->identifier;
}
// ONE-TO-MANY or ONE-TO-ONE
$relation = new Doctrine_Relation_ForeignKey($table, $local, $foreign, $type, $alias);
@ -703,14 +697,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
break;
} catch(Doctrine_Table_Exception $exc) { }
}
if( ! isset($bound))
if ( ! isset($bound)) {
throw new Doctrine_Table_Exception("Couldn't map many-to-many relation for "
. $this->options['name'] . " and $name. Components use different join tables.");
if( ! isset($local))
}
if ( ! isset($local)) {
$local = $this->identifier;
}
$e2 = explode('.', $bound[0]);
$fields = explode('-', $e2[1]);
@ -803,15 +796,15 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
*/
public function find($id) {
if ($id !== null) {
if( ! is_array($id))
if ( ! is_array($id)) {
$id = array($id);
else
} else {
$id = array_values($id);
}
$query = $this->query." WHERE ".implode(" = ? AND ",$this->primaryKeys)." = ?";
$query = $this->applyInheritance($query);
$params = array_merge($id, array_values($this->options['inheritanceMap']));
$stmt = $this->conn->execute($query,$params);
@ -891,21 +884,21 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$key = $this->getIdentifier();
if( ! is_array($key))
if ( ! is_array($key)) {
$key = array($key);
}
foreach ($key as $k) {
if( ! isset($this->data[$k]))
if ( ! isset($this->data[$k])) {
throw new Doctrine_Exception("Primary key value for $k wasn't found");
}
$id[] = $this->data[$k];
}
$id = implode(' ', $id);
if(isset($this->identityMap[$id]))
if (isset($this->identityMap[$id])) {
$record = $this->identityMap[$id];
else {
} else {
$record = new $this->options['name']($this);
$this->identityMap[$id] = $record;
}
@ -989,11 +982,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return array
*/
final public function getEnumValues($field) {
if(isset($this->options['enumMap'][$field]))
if (isset($this->options['enumMap'][$field])) {
return $this->options['enumMap'][$field];
else
} else {
return array();
}
}
/**
* enumValue
*
@ -1013,9 +1007,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @param mixed $value
*/
public function invokeSet(Doctrine_Record $record, $name, $value) {
if( ! ($this->getAttribute(Doctrine::ATTR_ACCESSORS) & Doctrine::ACCESSOR_SET))
if ( ! ($this->getAttribute(Doctrine::ATTR_ACCESSORS) & Doctrine::ACCESSOR_SET)) {
return $value;
}
$prefix = $this->getAttribute(Doctrine::ATTR_ACCESSOR_PREFIX_SET);
if (!$prefix)
$prefix = 'set';
@ -1034,9 +1028,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @param mixed $value
*/
public function invokeGet(Doctrine_Record $record, $name, $value) {
if( ! ($this->getAttribute(Doctrine::ATTR_ACCESSORS) & Doctrine::ACCESSOR_GET))
if ( ! ($this->getAttribute(Doctrine::ATTR_ACCESSORS) & Doctrine::ACCESSOR_GET)) {
return $value;
}
$prefix = $this->getAttribute(Doctrine::ATTR_ACCESSOR_PREFIX_GET);
if (!$prefix)
$prefix = 'get';
@ -1057,10 +1051,11 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return mixed
*/
final public function enumIndex($field, $value) {
if( ! isset($this->options['enumMap'][$field]))
if ( ! isset($this->options['enumMap'][$field])) {
$values = array();
else
} else {
$values = $this->options['enumMap'][$field];
}
return array_search($value, $values);
}
@ -1070,9 +1065,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return string ValueWrapper class name on success, false on failure
*/
public function getValueWrapperOf($column) {
if(isset($this->columns[$column][2]['wrapper']))
if (isset($this->columns[$column][2]['wrapper'])) {
return $this->columns[$column][2]['wrapper'];
}
return false;
}
/**
@ -1107,9 +1102,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return mixed array on success, false on failure
*/
public function getDefinitionOf($column) {
if(isset($this->columns[$column]))
if (isset($this->columns[$column])) {
return $this->columns[$column];
}
return false;
}
/**
@ -1118,9 +1113,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return mixed string on success, false on failure
*/
public function getTypeOf($column) {
if(isset($this->columns[$column]))
if (isset($this->columns[$column])) {
return $this->columns[$column][0];
}
return false;
}
/**
@ -1171,4 +1166,3 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
return Doctrine_Lib::getTableAsString($this);
}
}

View File

@ -38,4 +38,3 @@ class Doctrine_Table_Exception extends Doctrine_Exception {
parent::__construct($message);
}
}

View File

@ -67,9 +67,9 @@ class Doctrine_Table_Repository implements Countable, IteratorAggregate {
public function add(Doctrine_Record $record) {
$oid = $record->getOID();
if(isset($this->registry[$oid]))
if (isset($this->registry[$oid])) {
return false;
}
$this->registry[$oid] = $record;
return true;
@ -80,9 +80,9 @@ class Doctrine_Table_Repository implements Countable, IteratorAggregate {
* @throws Doctrine_Table_Repository_Exception
*/
public function get($oid) {
if( ! isset($this->registry[$oid]))
if ( ! isset($this->registry[$oid])) {
throw new Doctrine_Table_Repository_Exception("Unknown object identifier");
}
return $this->registry[$oid];
}
/**
@ -98,9 +98,9 @@ class Doctrine_Table_Repository implements Countable, IteratorAggregate {
* @return boolean whether ot not the operation was successful
*/
public function evict($oid) {
if( ! isset($this->registry[$oid]))
if ( ! isset($this->registry[$oid])) {
return false;
}
unset($this->registry[$oid]);
return true;
}
@ -110,9 +110,10 @@ class Doctrine_Table_Repository implements Countable, IteratorAggregate {
public function evictAll() {
$evicted = 0;
foreach ($this->registry as $oid=>$record) {
if($this->evict($oid))
if ($this->evict($oid)) {
$evicted++;
}
}
return $evicted;
}
/**
@ -137,4 +138,3 @@ class Doctrine_Table_Repository implements Countable, IteratorAggregate {
$this->table->findAll();
}
}

View File

@ -96,9 +96,9 @@ class Doctrine_Transaction extends Doctrine_Connection_Module {
* otherwise true
*/
public function addInvalid(Doctrine_Record $record) {
if(in_array($record, $this->invalid))
if (in_array($record, $this->invalid)) {
return false;
}
$this->invalid[] = $record;
return true;
}
@ -167,7 +167,6 @@ class Doctrine_Transaction extends Doctrine_Connection_Module {
$this->savePoints[] = $savepoint;
$this->createSavePoint($savepoint);
} else {
if ($this->transactionLevel == 0) {
@ -181,7 +180,6 @@ class Doctrine_Transaction extends Doctrine_Connection_Module {
$level = ++$this->transactionLevel;
return $level;
}
/**
@ -209,7 +207,6 @@ class Doctrine_Transaction extends Doctrine_Connection_Module {
if ($this->transactionLevel == 1) {
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionCommit($this->conn);
try {
$this->bulkDelete();
@ -259,7 +256,6 @@ class Doctrine_Transaction extends Doctrine_Connection_Module {
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionRollback($this->conn);
if ( ! is_null($savepoint)) {
$this->transactionLevel = $this->removeSavePoints($savepoint);
$this->rollbackSavePoint($savepoint);

View File

@ -80,7 +80,6 @@ class Doctrine_Validator {
$errorStack = $record->getErrorStack();
// if record is transient all fields will be validated
// if record is persistent only the modified fields will be validated
$data = ($record->exists()) ? $record->getModified() : $record->getData();
@ -110,11 +109,11 @@ class Doctrine_Validator {
}
}
if( ! is_array($column[2]))
if ( ! is_array($column[2])) {
$e = explode("|",$column[2]);
else
} else {
$e = $column[2];
}
foreach ($e as $k => $arg) {
if (is_string($k)) {
@ -123,16 +122,19 @@ class Doctrine_Validator {
} else {
$args = explode(":",$arg);
$name = array_shift($args);
if( ! isset($args[0]))
if ( ! isset($args[0])) {
$args[0] = '';
}
}
if(empty($name) || $name == 'primary' ||
$name == 'protected' ||
$name == 'autoincrement' ||
$name == 'default')
if (empty($name)
|| $name == 'primary'
|| $name == 'protected'
|| $name == 'autoincrement'
|| $name == 'default'
) {
continue;
}
if (strtolower($name) == 'length') {
if (!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD)) {
if (!$this->validateLength($column, $key, $value)) {
@ -153,8 +155,6 @@ class Doctrine_Validator {
$validator = self::getValidator($name);
if ( ! $validator->validate($record, $key, $value, $args)) {
$errorStack->add($key, $name);
//$err[$key] = 'not valid';
@ -177,10 +177,11 @@ class Doctrine_Validator {
*
*/
private function validateLength($column, $key, $value) {
if($column[0] == "array" || $column[0] == "object")
if ($column[0] == "array" || $column[0] == "object") {
$length = strlen(serialize($value));
else
} else {
$length = strlen($value);
}
if ($length > $column[1]) {
return false;
@ -232,7 +233,7 @@ class Doctrine_Validator {
$looseType = self::gettype($var);
$type = self::phpType($type);
switch($looseType):
switch ($looseType) {
case 'float':
case 'double':
case 'integer':
@ -246,7 +247,7 @@ class Doctrine_Validator {
case 'NULL':
return true;
break;
endswitch;
};
}
/**
* returns the type of loosely typed variable
@ -256,18 +257,18 @@ class Doctrine_Validator {
*/
public static function gettype($var) {
$type = gettype($var);
switch($type):
switch ($type) {
case 'string':
if(preg_match("/^[0-9]+$/",$var))
if (preg_match("/^[0-9]+$/",$var)) {
return 'integer';
elseif(is_numeric($var))
} elseif (is_numeric($var)) {
return 'float';
else
} else {
return $type;
}
break;
default:
return $type;
endswitch;
};
}
}

View File

@ -294,4 +294,3 @@ class Doctrine_Validator_Country {
}
}

View File

@ -45,4 +45,3 @@ class Doctrine_Validator_Creditcard {
}
}

View File

@ -39,14 +39,13 @@ class Doctrine_Validator_Date {
* @return boolean
*/
public function validate(Doctrine_Record $record, $key, $value, $args) {
if(empty($value))
if (empty($value)) {
return true;
}
$e = explode("-", $value);
if(count($e) !== 3)
if (count($e) !== 3) {
return false;
}
return checkdate($e[1], $e[0], $e[2]);
}
}

View File

@ -41,16 +41,17 @@ class Doctrine_Validator_Email {
* @return boolean
*/
public function validate(Doctrine_Record $record, $key, $value, $args) {
if(empty($value))
if (empty($value)) {
return true;
}
if (isset($args[0])) {
$parts = explode("@", $value);
if (isset($parts[1]) && function_exists("checkdnsrr")) {
if( ! checkdnsrr($parts[1], "MX"))
if ( ! checkdnsrr($parts[1], "MX")) {
return false;
}
}
}
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
@ -65,8 +66,9 @@ class Doctrine_Validator_Email {
/*
following psudocode to allow strict checking - ask pookey about this if you're puzzled
if ($this->getValidationOption('strict_checking') == true)
if ($this->getValidationOption('strict_checking') == true) {
$domain = "$sub_domain(\\x2e$sub_domain)*";
}
*/
$local_part = "$word(\\x2e$word)*";
$addr_spec = "$local_part\\x40$domain";
@ -75,4 +77,3 @@ class Doctrine_Validator_Email {
}
}

View File

@ -42,13 +42,12 @@ class Doctrine_Validator_Enum {
$max = substr_count($args, '-');
$int = (int) $value;
if($int != $value)
if ($int != $value) {
return false;
if($int < 0 || $int > $max)
}
if ($int < 0 || $int > $max) {
return false;
}
return true;
}
}

View File

@ -102,7 +102,6 @@ class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable
$this->errors = array();
}
/** IteratorAggregate implementation */
/**
@ -114,7 +113,6 @@ class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable
return new ArrayIterator($this->errors);
}
/** Countable implementation */
/**

View File

@ -63,4 +63,3 @@ class Doctrine_Validator_Exception extends Doctrine_Exception implements Countab
return parent::__toString();
}
}

View File

@ -45,4 +45,3 @@ class Doctrine_Validator_HtmlColor {
return true;
}
}

View File

@ -2,4 +2,3 @@
interface Doctrine_Validator_Interface {
public function validate();
}

View File

@ -42,4 +42,3 @@ class Doctrine_Validator_Ip {
return (bool) ip2long(str_replace("\0", '', $value));
}
}

View File

@ -42,4 +42,3 @@ class Doctrine_Validator_Nospace {
return ($value === null || ! preg_match('/\s\t\r\n/',$value));
}
}

View File

@ -42,4 +42,3 @@ class Doctrine_Validator_Notblank {
return (trim($value) != "");
}
}

View File

@ -38,10 +38,9 @@ class Doctrine_Validator_Notnull {
* @return boolean
*/
public function validate(Doctrine_Record $record, $key, $value) {
if ($value === null || $value === '')
if ($value === null || $value === '') {
return false;
}
return true;
}
}

View File

@ -1,2 +1 @@
<?php

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