Commit b4ad6038 authored by zYne's avatar zYne

--no commit message

--no commit message
parent ccc51c72
......@@ -78,7 +78,6 @@ class Doctrine_Import_Builder
* 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.
*
* @access public
* @return void
*/
public function loadTemplate()
......@@ -114,7 +113,6 @@ END;
*
* @param string $table
* @param array $tableColumns
* @access public
*/
public function buildDefinition($table, $tableColumns)
{
......@@ -201,20 +199,4 @@ END;
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
*/
public function loadTemplate($template)
{
$tpl = new $template($this->_table);
$tpl = new $template();
$tpl->setTable($this->_table);
$tpl->setUp();
$tpl->setTableDefinition();
return $this;
......
......@@ -101,6 +101,20 @@ class Doctrine_Relation_Parser
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));
$m = Doctrine_Manager::getInstance();
......
......@@ -231,13 +231,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
switch (count($this->primaryKeys)) {
case 0:
$this->columns = array_merge(array('id' =>
array('integer',
20,
array('autoincrement' => true,
'primary' => true,
)
)
), $this->columns);
array('type' => 'integer',
'length' => 20,
'autoincrement' => true,
'primary' => true)), $this->columns);
$this->primaryKeys[] = 'id';
$this->identifier = 'id';
......@@ -251,7 +248,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
} else {
foreach ($this->primaryKeys as $pk) {
$e = $this->columns[$pk][2];
$e = $this->columns[$pk];
$found = false;
......@@ -329,9 +326,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$primary = array();
foreach ($this->getColumns() as $name => $column) {
$definition = $column[2];
$definition['type'] = $column[0];
$definition['length'] = $column[1];
$definition = $column;
switch ($definition['type']) {
case 'enum':
......@@ -689,7 +684,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
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'])) {
$this->primaryKeys[] = $name;
......@@ -721,8 +718,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
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'];
if (isset($this->columns[$column]['default'])) {
return $this->columns[$column]['default'];
} else {
return null;
}
......@@ -871,7 +868,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
public function findBySql($dql, array $params = array()) {
$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;
}
......@@ -1010,7 +1007,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
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);
}
/**
......@@ -1022,40 +1019,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$graph->load($this->getComponentName());
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
* @return array
*/
final public function getEnumValues($field)
public function getEnumValues($field)
{
if (isset($this->columns[$field][2]['values'])) {
return $this->columns[$field][2]['values'];
if (isset($this->columns[$field]['values'])) {
return $this->columns[$field]['values'];
} else {
return array();
}
......@@ -1072,7 +1043,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if ($index instanceof Doctrine_Null)
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
......@@ -1087,24 +1058,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
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
*
* @return integer the number of columns in this table
*/
final public function getColumnCount()
public function getColumnCount()
{
return $this->columnCount;
}
......@@ -1114,7 +1073,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*
* @return array
*/
final public function getColumns()
public function getColumns()
{
return $this->columns;
}
......@@ -1147,7 +1106,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
public function getTypeOf($column)
{
if (isset($this->columns[$column])) {
return $this->columns[$column][0];
return $this->columns[$column]['type'];
}
return false;
}
......@@ -1173,14 +1132,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$sql = "SELECT MAX(".$this->getIdentifier().") FROM ".$this->getTableName();
$stmt = $this->conn->getDBH()->query($sql);
$data = $stmt->fetch(PDO::FETCH_NUM);
return isset($data[0])?$data[0]:1;
return isset($data[0])? $data[0] : 1;
}
/**
* returns simple cached query
*
* @return string
*/
final public function getQuery()
public function getQuery()
{
return $this->query;
}
......@@ -1190,7 +1149,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*
* @return array
*/
final public function getData()
public function getData()
{
return $this->data;
}
......
......@@ -37,11 +37,11 @@ class Doctrine_Template extends Doctrine_Record_Abstract
*/
protected $_table;
/**
* constructor, creates tree with reference to table and any options
* setTable
*
* @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;
}
......
......@@ -30,27 +30,12 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Validator
class Doctrine_Validator extends Doctrine_Object
{
/**
* @var array $validators an array of validator objects
*/
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
*
......@@ -90,14 +75,15 @@ class Doctrine_Validator
$err = array();
foreach ($data as $key => $value) {
if ($value === self::$null)
if ($value === self::$_null) {
$value = null;
elseif ($value instanceof Doctrine_Record)
} elseif ($value instanceof Doctrine_Record) {
$value = $value->getIncremented();
}
$column = $columns[$key];
if ($column[0] == "enum") {
if ($column['type'] == 'enum') {
$value = $record->getTable()->enumIndex($key, $value);
if ($value === false) {
......@@ -114,24 +100,7 @@ class Doctrine_Validator
}
}
if ( ! is_array($column[2])) {
$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] = '';
}
}
foreach ($column as $name => $args) {
if (empty($name)
|| $name == 'primary'
|| $name == 'protected'
......@@ -139,8 +108,7 @@ class Doctrine_Validator
|| $name == 'default'
|| $name == 'values'
|| $name == 'sequence'
|| $name == 'zerofill'
) {
|| $name == 'zerofill') {
continue;
}
if (strtolower($name) == 'length') {
......@@ -154,7 +122,7 @@ class Doctrine_Validator
if (strtolower($name) == 'type') {
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');
}
}
......@@ -173,7 +141,7 @@ class Doctrine_Validator
}
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');
continue;
}
......@@ -185,15 +153,15 @@ class Doctrine_Validator
*/
private function validateLength($column, $key, $value)
{
if ($column[0] == "timestamp" || $column[0] == "integer") {
if ($column['type'] == 'timestamp' || $column['type'] == 'integer') {
return true;
} else if ($column[0] == "array" || $column[0] == "object") {
} elseif ($column['type'] == 'array' || $column['type'] == 'object') {
$length = strlen(serialize($value));
} else {
$length = strlen($value);
}
if ($length > $column[1]) {
if ($length > $column['length']) {
return false;
}
return true;
......@@ -240,8 +208,9 @@ class Doctrine_Validator
*/
public static function isValidType($var, $type)
{
if ($type == 'boolean')
if ($type == 'boolean') {
return true;
}
$looseType = self::gettype($var);
$type = self::phpType($type);
......@@ -250,8 +219,9 @@ class Doctrine_Validator
case 'float':
case 'double':
case 'integer':
if ($type == 'string' || $type == 'float')
if ($type == 'string' || $type == 'float') {
return true;
}
case 'string':
case 'array':
case 'object':
......
......@@ -32,8 +32,12 @@
*/
class Doctrine_Template_TestCase extends Doctrine_UnitTestCase
{
public function testTemplateRelationsSupportConcreteInheritance()
{
$blog = new Blog();
$this->conn->export->exportClassesSql(array('Blog'));
}
}
......@@ -70,7 +70,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
$test->addTestCase(new Doctrine_Ticket330_TestCase());
*/
/** */
/** */
// Connection drivers (not yet fully tested)
$test->addTestCase(new Doctrine_Connection_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Connection_Oracle_TestCase());
......@@ -302,14 +302,15 @@ $test->addTestCase(new Doctrine_Query_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_PgsqlSubquery_TestCase());
$test->addTestCase(new Doctrine_Query_MysqlSubqueryHaving_TestCase());
/***/
/**
$test->addTestCase(new Doctrine_Template_TestCase());
*/
//$test->addTestCase(new Doctrine_IntegrityAction_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