Commit b4ad6038 authored by zYne's avatar zYne

--no commit message

--no commit message
parent ccc51c72
...@@ -78,7 +78,6 @@ class Doctrine_Import_Builder ...@@ -78,7 +78,6 @@ class Doctrine_Import_Builder
* This is a template that was previously in Builder/Record.tpl. Due to the fact * This is a template that was previously in Builder/Record.tpl. Due to the fact
* that it was not bundled when compiling, it had to be moved here. * that it was not bundled when compiling, it had to be moved here.
* *
* @access public
* @return void * @return void
*/ */
public function loadTemplate() public function loadTemplate()
...@@ -114,7 +113,6 @@ END; ...@@ -114,7 +113,6 @@ END;
* *
* @param string $table * @param string $table
* @param array $tableColumns * @param array $tableColumns
* @access public
*/ */
public function buildDefinition($table, $tableColumns) public function buildDefinition($table, $tableColumns)
{ {
...@@ -201,20 +199,4 @@ END; ...@@ -201,20 +199,4 @@ END;
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName); throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName);
} }
} }
/**
*
* @param Doctrine_Schema_Object $schema
* @throws Doctrine_Import_Exception
* @return void
*/
public function build(Doctrine_Schema_Object $schema)
{
foreach ($schema->getDatabases() as $database){
foreach ($database->getTables() as $table){
$this->buildRecord($table);
}
}
}
} }
...@@ -1385,7 +1385,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1385,7 +1385,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/ */
public function loadTemplate($template) public function loadTemplate($template)
{ {
$tpl = new $template($this->_table); $tpl = new $template();
$tpl->setTable($this->_table);
$tpl->setUp(); $tpl->setUp();
$tpl->setTableDefinition(); $tpl->setTableDefinition();
return $this; return $this;
......
...@@ -101,6 +101,20 @@ class Doctrine_Relation_Parser ...@@ -101,6 +101,20 @@ class Doctrine_Relation_Parser
throw new Doctrine_Relation_Exception('Relation type not set.'); throw new Doctrine_Relation_Exception('Relation type not set.');
} }
if (strpos($name, '[Component]') !== false) {
$name = str_replace('[Component]', $this->_table->getComponentName(), $name);
$templateName = substr($name, strlen($this->_table->getComponentName()));
if (substr($name, -8) === 'Template') {
$name = substr($name, 0, -8);
}
if ( ! class_exists($name)) {
$template = new $templateName();
print_r($template->getTable()->getColumns());
}
}
$this->_pending[$alias] = array_merge($options, array('class' => $name, 'alias' => $alias)); $this->_pending[$alias] = array_merge($options, array('class' => $name, 'alias' => $alias));
$m = Doctrine_Manager::getInstance(); $m = Doctrine_Manager::getInstance();
......
...@@ -231,13 +231,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -231,13 +231,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
switch (count($this->primaryKeys)) { switch (count($this->primaryKeys)) {
case 0: case 0:
$this->columns = array_merge(array('id' => $this->columns = array_merge(array('id' =>
array('integer', array('type' => 'integer',
20, 'length' => 20,
array('autoincrement' => true, 'autoincrement' => true,
'primary' => true, 'primary' => true)), $this->columns);
)
)
), $this->columns);
$this->primaryKeys[] = 'id'; $this->primaryKeys[] = 'id';
$this->identifier = 'id'; $this->identifier = 'id';
...@@ -251,7 +248,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -251,7 +248,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
} else { } else {
foreach ($this->primaryKeys as $pk) { foreach ($this->primaryKeys as $pk) {
$e = $this->columns[$pk][2]; $e = $this->columns[$pk];
$found = false; $found = false;
...@@ -329,9 +326,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -329,9 +326,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$primary = array(); $primary = array();
foreach ($this->getColumns() as $name => $column) { foreach ($this->getColumns() as $name => $column) {
$definition = $column[2]; $definition = $column;
$definition['type'] = $column[0];
$definition['length'] = $column[1];
switch ($definition['type']) { switch ($definition['type']) {
case 'enum': case 'enum':
...@@ -689,7 +684,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -689,7 +684,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
throw new Doctrine_Table_Exception('Invalid argument given for column length'); throw new Doctrine_Table_Exception('Invalid argument given for column length');
} }
$this->columns[$name] = array($type, $length, $options); $this->columns[$name] = $options;
$this->columns[$name]['type'] = $type;
$this->columns[$name]['length'] = $length;
if (isset($options['primary'])) { if (isset($options['primary'])) {
$this->primaryKeys[] = $name; $this->primaryKeys[] = $name;
...@@ -721,8 +718,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -721,8 +718,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
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."); throw new Doctrine_Table_Exception("Couldn't get default value. Column ".$column." doesn't exist.");
} }
if (isset($this->columns[$column][2]['default'])) { if (isset($this->columns[$column]['default'])) {
return $this->columns[$column][2]['default']; return $this->columns[$column]['default'];
} else { } else {
return null; return null;
} }
...@@ -871,7 +868,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -871,7 +868,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/ */
public function findBySql($dql, array $params = array()) { public function findBySql($dql, array $params = array()) {
$q = new Doctrine_Query($this->conn); $q = new Doctrine_Query($this->conn);
$users = $q->query("FROM ".$this->options['name']." WHERE ".$dql, $params); $users = $q->query('FROM ' . $this->options['name'] . ' WHERE ' . $dql, $params);
return $users; return $users;
} }
...@@ -1010,7 +1007,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -1010,7 +1007,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/ */
public function count() public function count()
{ {
$a = $this->conn->getDBH()->query("SELECT COUNT(1) FROM ".$this->options['tableName'])->fetch(PDO::FETCH_NUM); $a = $this->conn->execute('SELECT COUNT(1) FROM ' . $this->options['tableName'])->fetch(Doctrine::FETCH_NUM);
return current($a); return current($a);
} }
/** /**
...@@ -1022,40 +1019,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -1022,40 +1019,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$graph->load($this->getComponentName()); $graph->load($this->getComponentName());
return $graph; return $graph;
} }
/**
* execute
* @param string $query
* @param array $array
* @param integer $limit
* @param integer $offset
*/
public function execute($query, array $array = array(), $limit = null, $offset = null) {
$coll = new Doctrine_Collection($this);
$query = $this->conn->modifyLimitQuery($query,$limit,$offset);
if ( ! empty($array)) {
$stmt = $this->conn->getDBH()->prepare($query);
$stmt->execute($array);
} else {
$stmt = $this->conn->getDBH()->query($query);
}
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($data as $row) {
$this->data = $row;
$record = $this->getRecord();
$coll->add($record);
}
return $coll;
}
/** /**
* @param string $field * @param string $field
* @return array * @return array
*/ */
final public function getEnumValues($field) public function getEnumValues($field)
{ {
if (isset($this->columns[$field][2]['values'])) { if (isset($this->columns[$field]['values'])) {
return $this->columns[$field][2]['values']; return $this->columns[$field]['values'];
} else { } else {
return array(); return array();
} }
...@@ -1072,7 +1043,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -1072,7 +1043,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if ($index instanceof Doctrine_Null) if ($index instanceof Doctrine_Null)
return $index; return $index;
return isset($this->columns[$field][2]['values'][$index]) ? $this->columns[$field][2]['values'][$index] : $index; return isset($this->columns[$field]['values'][$index]) ? $this->columns[$field]['values'][$index] : $index;
} }
/** /**
* enumIndex * enumIndex
...@@ -1087,24 +1058,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -1087,24 +1058,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
return array_search($value, $values); return array_search($value, $values);
} }
/**
* getDefinitionOf
*
* @return string ValueWrapper class name on success, false on failure
*/
public function getValueWrapperOf($column)
{
if (isset($this->columns[$column][2]['wrapper'])) {
return $this->columns[$column][2]['wrapper'];
}
return false;
}
/** /**
* getColumnCount * getColumnCount
* *
* @return integer the number of columns in this table * @return integer the number of columns in this table
*/ */
final public function getColumnCount() public function getColumnCount()
{ {
return $this->columnCount; return $this->columnCount;
} }
...@@ -1114,7 +1073,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -1114,7 +1073,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* *
* @return array * @return array
*/ */
final public function getColumns() public function getColumns()
{ {
return $this->columns; return $this->columns;
} }
...@@ -1147,7 +1106,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -1147,7 +1106,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
public function getTypeOf($column) public function getTypeOf($column)
{ {
if (isset($this->columns[$column])) { if (isset($this->columns[$column])) {
return $this->columns[$column][0]; return $this->columns[$column]['type'];
} }
return false; return false;
} }
...@@ -1173,14 +1132,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -1173,14 +1132,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$sql = "SELECT MAX(".$this->getIdentifier().") FROM ".$this->getTableName(); $sql = "SELECT MAX(".$this->getIdentifier().") FROM ".$this->getTableName();
$stmt = $this->conn->getDBH()->query($sql); $stmt = $this->conn->getDBH()->query($sql);
$data = $stmt->fetch(PDO::FETCH_NUM); $data = $stmt->fetch(PDO::FETCH_NUM);
return isset($data[0])?$data[0]:1; return isset($data[0])? $data[0] : 1;
} }
/** /**
* returns simple cached query * returns simple cached query
* *
* @return string * @return string
*/ */
final public function getQuery() public function getQuery()
{ {
return $this->query; return $this->query;
} }
...@@ -1190,7 +1149,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -1190,7 +1149,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* *
* @return array * @return array
*/ */
final public function getData() public function getData()
{ {
return $this->data; return $this->data;
} }
......
...@@ -37,11 +37,11 @@ class Doctrine_Template extends Doctrine_Record_Abstract ...@@ -37,11 +37,11 @@ class Doctrine_Template extends Doctrine_Record_Abstract
*/ */
protected $_table; protected $_table;
/** /**
* constructor, creates tree with reference to table and any options * setTable
* *
* @param Doctrine_Table $_table the table object this Template belongs to * @param Doctrine_Table $_table the table object this Template belongs to
*/ */
public function __construct(Doctrine_Table $table) public function setTable(Doctrine_Table $table)
{ {
$this->_table = $table; $this->_table = $table;
} }
......
...@@ -30,27 +30,12 @@ ...@@ -30,27 +30,12 @@
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Validator class Doctrine_Validator extends Doctrine_Object
{ {
/** /**
* @var array $validators an array of validator objects * @var array $validators an array of validator objects
*/ */
private static $validators = array(); private static $validators = array();
/**
* @var Doctrine_Null $null a Doctrine_Null object used for extremely fast
* null value testing
*/
private static $null;
/**
* initNullObject
*
* @param Doctrine_Null $null
* @return void
*/
public static function initNullObject(Doctrine_Null $null)
{
self::$null = $null;
}
/** /**
* returns a validator object * returns a validator object
* *
...@@ -90,14 +75,15 @@ class Doctrine_Validator ...@@ -90,14 +75,15 @@ class Doctrine_Validator
$err = array(); $err = array();
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
if ($value === self::$null) if ($value === self::$_null) {
$value = null; $value = null;
elseif ($value instanceof Doctrine_Record) } elseif ($value instanceof Doctrine_Record) {
$value = $value->getIncremented(); $value = $value->getIncremented();
}
$column = $columns[$key]; $column = $columns[$key];
if ($column[0] == "enum") { if ($column['type'] == 'enum') {
$value = $record->getTable()->enumIndex($key, $value); $value = $record->getTable()->enumIndex($key, $value);
if ($value === false) { if ($value === false) {
...@@ -114,24 +100,7 @@ class Doctrine_Validator ...@@ -114,24 +100,7 @@ class Doctrine_Validator
} }
} }
if ( ! is_array($column[2])) { foreach ($column as $name => $args) {
$e = explode("|",$column[2]);
} else {
$e = $column[2];
}
foreach ($e as $k => $arg) {
if (is_string($k)) {
$name = $k;
$args = $arg;
} else {
$args = explode(":",$arg);
$name = array_shift($args);
if ( ! isset($args[0])) {
$args[0] = '';
}
}
if (empty($name) if (empty($name)
|| $name == 'primary' || $name == 'primary'
|| $name == 'protected' || $name == 'protected'
...@@ -139,8 +108,7 @@ class Doctrine_Validator ...@@ -139,8 +108,7 @@ class Doctrine_Validator
|| $name == 'default' || $name == 'default'
|| $name == 'values' || $name == 'values'
|| $name == 'sequence' || $name == 'sequence'
|| $name == 'zerofill' || $name == 'zerofill') {
) {
continue; continue;
} }
if (strtolower($name) == 'length') { if (strtolower($name) == 'length') {
...@@ -154,7 +122,7 @@ class Doctrine_Validator ...@@ -154,7 +122,7 @@ class Doctrine_Validator
if (strtolower($name) == 'type') { if (strtolower($name) == 'type') {
if (!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) { if (!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) {
if ( ! self::isValidType($value, $column[0])) { if ( ! self::isValidType($value, $column['type'])) {
$errorStack->add($key, 'type'); $errorStack->add($key, 'type');
} }
} }
...@@ -173,7 +141,7 @@ class Doctrine_Validator ...@@ -173,7 +141,7 @@ class Doctrine_Validator
} }
if ($record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) { if ($record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) {
if ( ! self::isValidType($value, $column[0])) { if ( ! self::isValidType($value, $column['type'])) {
$errorStack->add($key, 'type'); $errorStack->add($key, 'type');
continue; continue;
} }
...@@ -185,15 +153,15 @@ class Doctrine_Validator ...@@ -185,15 +153,15 @@ class Doctrine_Validator
*/ */
private function validateLength($column, $key, $value) private function validateLength($column, $key, $value)
{ {
if ($column[0] == "timestamp" || $column[0] == "integer") { if ($column['type'] == 'timestamp' || $column['type'] == 'integer') {
return true; return true;
} else if ($column[0] == "array" || $column[0] == "object") { } elseif ($column['type'] == 'array' || $column['type'] == 'object') {
$length = strlen(serialize($value)); $length = strlen(serialize($value));
} else { } else {
$length = strlen($value); $length = strlen($value);
} }
if ($length > $column[1]) { if ($length > $column['length']) {
return false; return false;
} }
return true; return true;
...@@ -240,8 +208,9 @@ class Doctrine_Validator ...@@ -240,8 +208,9 @@ class Doctrine_Validator
*/ */
public static function isValidType($var, $type) public static function isValidType($var, $type)
{ {
if ($type == 'boolean') if ($type == 'boolean') {
return true; return true;
}
$looseType = self::gettype($var); $looseType = self::gettype($var);
$type = self::phpType($type); $type = self::phpType($type);
...@@ -250,8 +219,9 @@ class Doctrine_Validator ...@@ -250,8 +219,9 @@ class Doctrine_Validator
case 'float': case 'float':
case 'double': case 'double':
case 'integer': case 'integer':
if ($type == 'string' || $type == 'float') if ($type == 'string' || $type == 'float') {
return true; return true;
}
case 'string': case 'string':
case 'array': case 'array':
case 'object': case 'object':
......
...@@ -32,8 +32,12 @@ ...@@ -32,8 +32,12 @@
*/ */
class Doctrine_Template_TestCase extends Doctrine_UnitTestCase class Doctrine_Template_TestCase extends Doctrine_UnitTestCase
{ {
public function testTemplateRelationsSupportConcreteInheritance() public function testTemplateRelationsSupportConcreteInheritance()
{ {
$blog = new Blog(); $blog = new Blog();
$this->conn->export->exportClassesSql(array('Blog'));
} }
} }
...@@ -70,7 +70,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests'); ...@@ -70,7 +70,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
$test->addTestCase(new Doctrine_Ticket330_TestCase()); $test->addTestCase(new Doctrine_Ticket330_TestCase());
*/ */
/** */ /** */
// Connection drivers (not yet fully tested) // Connection drivers (not yet fully tested)
$test->addTestCase(new Doctrine_Connection_Pgsql_TestCase()); $test->addTestCase(new Doctrine_Connection_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Connection_Oracle_TestCase()); $test->addTestCase(new Doctrine_Connection_Oracle_TestCase());
...@@ -302,14 +302,15 @@ $test->addTestCase(new Doctrine_Query_TestCase()); ...@@ -302,14 +302,15 @@ $test->addTestCase(new Doctrine_Query_TestCase());
$test->addTestCase(new Doctrine_Ticket364_TestCase()); $test->addTestCase(new Doctrine_Ticket364_TestCase());
$test->addTestCase(new Doctrine_Template_TestCase());
$test->addTestCase(new Doctrine_Query_MysqlSubquery_TestCase()); $test->addTestCase(new Doctrine_Query_MysqlSubquery_TestCase());
$test->addTestCase(new Doctrine_Query_PgsqlSubquery_TestCase()); $test->addTestCase(new Doctrine_Query_PgsqlSubquery_TestCase());
$test->addTestCase(new Doctrine_Query_MysqlSubqueryHaving_TestCase()); $test->addTestCase(new Doctrine_Query_MysqlSubqueryHaving_TestCase());
/***/
/**
$test->addTestCase(new Doctrine_Template_TestCase());
*/
//$test->addTestCase(new Doctrine_IntegrityAction_TestCase()); //$test->addTestCase(new Doctrine_IntegrityAction_TestCase());
//$test->addTestCase(new Doctrine_AuditLog_TestCase()); //$test->addTestCase(new Doctrine_AuditLog_TestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment