public function getTable($name)
{
- if (isset($this->tables[$name])) {
- return $this->tables[$name];
- }
- $class = $name . 'Table';
-
- if (class_exists($class, $this->getAttribute(IPF_ORM::ATTR_AUTOLOAD_TABLE_CLASSES)) &&
- in_array('IPF_ORM_Table', class_parents($class))) {
- $table = new $class($name, $this, true);
- } else {
- $table = new IPF_ORM_Table($name, $this, true);
- }
-
- $this->tables[$name] = $table;
-
- return $table;
+ if (!isset($this->tables[$name]))
+ $this->tables[$name] = new IPF_ORM_Table($name, $this);
+ return $this->tables[$name];
}
public function getTables()
protected $_filters = array();
protected $_generators = array();
protected $_invokedMethods = array();
- protected $record;
public $listeners = array();
- public function __construct($name, IPF_ORM_Connection $conn, $initDefinition = false)
+ public function __construct($name, IPF_ORM_Connection $conn)
{
if (empty($name) || !class_exists($name))
throw new IPF_ORM_Exception("Couldn't find class " . $name);
$this->_options['name'] = $name;
$this->_parser = new IPF_ORM_Relation_Parser($this);
- if ($initDefinition) {
- $this->record = $this->initDefinition();
+ $this->initParents($name);
- $this->initIdentifier();
+ // create database table
+ $record = new $name($this);
+ $record->setTableDefinition();
- $this->record->setUp();
- } else {
- if ( ! isset($this->_options['tableName'])) {
- $this->setTableName(IPF_ORM_Inflector::tableize($this->_options['name']));
- }
+ $this->columnCount = count($this->_columns);
+
+ if (!isset($this->_options['tableName'])) {
+ $this->setTableName(IPF_ORM_Inflector::tableize($class->getName()));
}
+
+ $this->initIdentifier();
+
+ $record->setUp();
+
$this->_filters[] = new IPF_ORM_Record_Filter_Standard();
$this->_repository = new IPF_ORM_Table_Repository($this);
}
- public function initDefinition()
+ private function initParents($name)
{
- $name = $this->_options['name'];
- $record = new $name($this);
-
$names = array();
$class = $name;
-
- // get parent classes
-
do {
if ($class === 'IPF_ORM_Record')
break;
// save parents
array_pop($names);
$this->_options['parents'] = $names;
-
- // create database table
- if (method_exists($record, 'setTableDefinition')) {
- $record->setTableDefinition();
- // get the declaring class of setTableDefinition method
- $method = new ReflectionMethod($this->_options['name'], 'setTableDefinition');
- $class = $method->getDeclaringClass();
-
- } else {
- $class = new ReflectionClass($class);
- }
-
- $this->_options['declaringClass'] = $class;
-
- $this->columnCount = count($this->_columns);
-
- if ( ! isset($this->_options['tableName'])) {
- $this->setTableName(IPF_ORM_Inflector::tableize($class->getName()));
- }
-
- return $record;
}
public function initIdentifier()