From: Andrey Kutejko Date: Tue, 23 Jul 2013 17:35:42 +0000 (+0300) Subject: cleanup X-Git-Tag: 0.5~153 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=1d6fdf78ccc9829fa70116ceb850e909471c0a81;p=ipf.git cleanup --- diff --git a/ipf/orm.php b/ipf/orm.php index 68ac5de..43bbc49 100644 --- a/ipf/orm.php +++ b/ipf/orm.php @@ -133,7 +133,6 @@ final class IPF_ORM const ATTR_DEFAULT_PARAM_NAMESPACE = 156; const ATTR_QUERY_CACHE = 157; const ATTR_QUERY_CACHE_LIFESPAN = 158; - const ATTR_AUTOLOAD_TABLE_CLASSES = 160; const ATTR_MODEL_LOADING = 161; const ATTR_RECURSIVE_MERGE_FIXTURES = 162; const ATTR_SINGULARIZE_IMPORT = 163; diff --git a/ipf/orm/configurable.php b/ipf/orm/configurable.php index e247be8..887b2b8 100644 --- a/ipf/orm/configurable.php +++ b/ipf/orm/configurable.php @@ -72,7 +72,6 @@ abstract class IPF_ORM_Configurable extends IPF_ORM_Locator_Injectable case IPF_ORM::ATTR_DECIMAL_PLACES: case IPF_ORM::ATTR_LOAD_REFERENCES: case IPF_ORM::ATTR_DEFAULT_PARAM_NAMESPACE: - case IPF_ORM::ATTR_AUTOLOAD_TABLE_CLASSES: case IPF_ORM::ATTR_MODEL_LOADING: case IPF_ORM::ATTR_RESULT_CACHE_LIFESPAN: case IPF_ORM::ATTR_QUERY_CACHE_LIFESPAN: diff --git a/ipf/orm/connection.php b/ipf/orm/connection.php index fa69f56..06c5306 100644 --- a/ipf/orm/connection.php +++ b/ipf/orm/connection.php @@ -562,21 +562,9 @@ abstract class IPF_ORM_Connection extends IPF_ORM_Configurable implements Counta 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() diff --git a/ipf/orm/manager.php b/ipf/orm/manager.php index 9390e99..ddeaaf7 100644 --- a/ipf/orm/manager.php +++ b/ipf/orm/manager.php @@ -24,7 +24,6 @@ class IPF_ORM_Manager extends IPF_ORM_Configurable implements Countable, Iterato IPF_ORM::ATTR_EXPORT => IPF_ORM::EXPORT_ALL, IPF_ORM::ATTR_DECIMAL_PLACES => 2, IPF_ORM::ATTR_DEFAULT_PARAM_NAMESPACE => 'ipf', - IPF_ORM::ATTR_AUTOLOAD_TABLE_CLASSES => false, ); } diff --git a/ipf/orm/table.php b/ipf/orm/table.php index 416102a..9cf7cd6 100644 --- a/ipf/orm/table.php +++ b/ipf/orm/table.php @@ -39,11 +39,10 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable 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); @@ -54,32 +53,31 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable $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; @@ -96,27 +94,6 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable // 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()