Commit af657cbe authored by romanb's avatar romanb

Introduced a new attribute ATTR_AUTOLOAD_TABLE_CLASSES that can be used to...

Introduced a new attribute ATTR_AUTOLOAD_TABLE_CLASSES that can be used to control whether Doctrine should try to autoload custom table class files when looking for them.
parent 2bcd41e2
...@@ -191,6 +191,7 @@ final class Doctrine ...@@ -191,6 +191,7 @@ final class Doctrine
const ATTR_DEFAULT_PARAM_NAMESPACE = 156; const ATTR_DEFAULT_PARAM_NAMESPACE = 156;
const ATTR_QUERY_CACHE = 157; const ATTR_QUERY_CACHE = 157;
const ATTR_QUERY_CACHE_LIFESPAN = 158; const ATTR_QUERY_CACHE_LIFESPAN = 158;
const ATTR_AUTOLOAD_TABLE_CLASSES = 160;
/** /**
* LIMIT CONSTANTS * LIMIT CONSTANTS
......
...@@ -124,6 +124,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable ...@@ -124,6 +124,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
case Doctrine::ATTR_RECORD_LISTENER: case Doctrine::ATTR_RECORD_LISTENER:
case Doctrine::ATTR_THROW_EXCEPTIONS: case Doctrine::ATTR_THROW_EXCEPTIONS:
case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE: case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE:
case Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES:
break; break;
case Doctrine::ATTR_SEQCOL_NAME: case Doctrine::ATTR_SEQCOL_NAME:
......
...@@ -237,7 +237,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -237,7 +237,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if ($this->isConnected) { if ($this->isConnected) {
try { try {
return $this->dbh->getAttribute($attribute); return $this->dbh->getAttribute($attribute);
} catch(Exception $e) { } catch (Exception $e) {
throw new Doctrine_Connection_Exception('Attribute ' . $attribute . ' not found.'); throw new Doctrine_Connection_Exception('Attribute ' . $attribute . ' not found.');
} }
} else { } else {
...@@ -1014,7 +1014,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1014,7 +1014,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} }
$class = $name . 'Table'; $class = $name . 'Table';
if (class_exists($class) && in_array('Doctrine_Table', class_parents($class))) { if (class_exists($class, $this->getAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES)) &&
in_array('Doctrine_Table', class_parents($class))) {
$table = new $class($name, $this, true); $table = new $class($name, $this, true);
} else { } else {
$table = new Doctrine_Table($name, $this, true); $table = new Doctrine_Table($name, $this, true);
......
...@@ -240,6 +240,6 @@ class Doctrine_Formatter extends Doctrine_Connection_Module ...@@ -240,6 +240,6 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
public function getTableName($table) public function getTableName($table)
{ {
return sprintf($this->conn->getAttribute(Doctrine::ATTR_TBLNAME_FORMAT), return sprintf($this->conn->getAttribute(Doctrine::ATTR_TBLNAME_FORMAT),
preg_replace('/[^a-z0-9_\$]/i', '_', $table)); $table);
} }
} }
...@@ -109,6 +109,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -109,6 +109,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
Doctrine::ATTR_EXPORT => Doctrine::EXPORT_ALL, Doctrine::ATTR_EXPORT => Doctrine::EXPORT_ALL,
Doctrine::ATTR_DECIMAL_PLACES => 2, Doctrine::ATTR_DECIMAL_PLACES => 2,
Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE => 'doctrine', Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE => 'doctrine',
Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES => true,
); );
foreach ($attributes as $attribute => $value) { foreach ($attributes as $attribute => $value) {
$old = $this->getAttribute($attribute); $old = $this->getAttribute($attribute);
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_Hydrate');
/** /**
* Doctrine_Query_Abstract * Doctrine_Query_Abstract
* *
......
<?php
/**
* Doctrine_Ticket_626_TestCase
*
* @package Doctrine
* @author Tamcy <7am.online@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Ticket_626C_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{ }
public function prepareTables()
{
$this->tables = array('T626C_Student1', 'T626C_Student2');
parent::prepareTables();
}
protected function newStudent($cls, $id, $name)
{
$u = new $cls;
$u->id = $id;
$u->name = $name;
$u->save();
return $u;
}
public function testFieldNames()
{
$student1 = $this->newStudent('T626C_Student1', '07090002', 'First Student');
try {
$students = Doctrine_Query::create()
->from('T626C_Student1 s INDEXBY s.id')
->execute(array(), Doctrine::FETCH_ARRAY);
$this->pass();
} catch (Exception $e) {
$this->fail($e->__toString());
}
}
public function testColNames()
{
$student1 = $this->newStudent('T626C_Student2', '07090002', 'First Student');
try {
$students = Doctrine_Query::create()
->from('T626C_Student2 s INDEXBY s.id')
->execute(array(), Doctrine::FETCH_ARRAY);
$this->pass();
} catch (Exception $e) {
$this->fail($e->__toString());
}
}
}
class T626C_Student1 extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('T626C_Student_record_1');
$this->hasColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,));
$this->hasColumn('s_name as name', 'varchar', 50, array ());
}
}
class T626C_Student2 extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('T626C_Student_record_2');
$this->hasColumn('id', 'varchar', 30, array ( 'primary' => true,));
$this->hasColumn('name', 'varchar', 50, array ());
}
}
\ No newline at end of file
...@@ -18,6 +18,7 @@ $tickets->addTestCase(new Doctrine_Ticket_587_TestCase()); ...@@ -18,6 +18,7 @@ $tickets->addTestCase(new Doctrine_Ticket_587_TestCase());
$tickets->addTestCase(new Doctrine_Ticket_576_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_576_TestCase());
$tickets->addTestCase(new Doctrine_Ticket_583_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_583_TestCase());
$tickets->addTestCase(new Doctrine_Ticket_626B_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_626B_TestCase());
$tickets->addTestCase(new Doctrine_Ticket_626C_TestCase());
$tickets->addTestCase(new Doctrine_Ticket_642_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_642_TestCase());
//If you write a ticket testcase add it here like shown above! //If you write a ticket testcase add it here like shown above!
$test->addTestCase($tickets); $test->addTestCase($tickets);
......
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