From: Andrey Kutejko Date: Sat, 27 Jul 2013 19:42:57 +0000 (+0300) Subject: simplify orm templates X-Git-Tag: 0.6~52 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=cb1f518c7b27d076b29807d911abb058ee0cfcd2;p=ipf-legacy-orm.git simplify orm templates --- diff --git a/ipf/orm/table.php b/ipf/orm/table.php index 5a5f193..e91896a 100644 --- a/ipf/orm/table.php +++ b/ipf/orm/table.php @@ -985,9 +985,7 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable $className = get_class($tpl); $this->_templates[$className] = $tpl; - $tpl->setTable($this); - $tpl->setUp(); - $tpl->setTableDefinition(); + $tpl->setTableDefinition($this); } public function getGenerators() diff --git a/ipf/orm/template.php b/ipf/orm/template.php index d963da1..9339498 100644 --- a/ipf/orm/template.php +++ b/ipf/orm/template.php @@ -1,19 +1,9 @@ _table = $table; - } - - public function getTable() - { - return $this->_table; - } - public function setInvoker(IPF_ORM_Record $invoker) { $this->_invoker = $invoker; @@ -24,22 +14,6 @@ abstract class IPF_ORM_Template extends IPF_ORM_Record_Abstract return $this->_invoker; } - public function get($name) - { - throw new IPF_ORM_Exception("Templates doesn't support accessors."); - } - - public function set($name, $value) - { - throw new IPF_ORM_Exception("Templates doesn't support accessors."); - } - - public function setUp() - { - } - - public function setTableDefinition() - { - } + abstract public function setTableDefinition(IPF_ORM_Table $table) } diff --git a/ipf/orm/template/orderable.php b/ipf/orm/template/orderable.php index 9e7ea2c..4ed0a33 100644 --- a/ipf/orm/template/orderable.php +++ b/ipf/orm/template/orderable.php @@ -23,9 +23,8 @@ class IPF_ORM_Template_Orderable extends IPF_ORM_Template return $this->columnName; } - public function setTableDefinition() + public function setTableDefinition(IPF_ORM_Table $table) { - $table = $this->getTable(); $table->setColumn($this->columnName, 'integer', null, array('exclude' => $this->exclude)); $table->addIndex($table->getOption('tableName') . '_orderable_' . $this->columnName, array('fields' => array($this->columnName))); $table->listeners['Orderable_'.$this->columnName] = new IPF_ORM_Template_Listener_Orderable($this->columnName, $this->prepend); diff --git a/ipf/orm/template/owned.php b/ipf/orm/template/owned.php index db204c0..7b7e69d 100644 --- a/ipf/orm/template/owned.php +++ b/ipf/orm/template/owned.php @@ -26,9 +26,9 @@ class IPF_ORM_Template_Owned extends IPF_ORM_Template return $this->columnName; } - public function setTableDefinition() + public function setTableDefinition(IPF_ORM_Table $table) { - $this->getTable()->setColumn($this->columnName, 'integer', null, array( + $table->setColumn($this->columnName, 'integer', null, array( 'exclude' => $this->exclude, 'verbose' => $this->verbose, )); @@ -38,7 +38,7 @@ class IPF_ORM_Template_Owned extends IPF_ORM_Template 'foreign' => 'id', 'onDelete' => 'CASCADE', )); - $this->getTable()->listeners['Owned_'.$this->columnName] = new IPF_ORM_Template_Listener_Owned($this->columnName); + $table->listeners['Owned_'.$this->columnName] = new IPF_ORM_Template_Listener_Owned($this->columnName); } } diff --git a/ipf/orm/template/sluggable.php b/ipf/orm/template/sluggable.php index c9e0003..30d14ed 100644 --- a/ipf/orm/template/sluggable.php +++ b/ipf/orm/template/sluggable.php @@ -20,10 +20,8 @@ class IPF_ORM_Template_Sluggable extends IPF_ORM_Template $this->_options = IPF_ORM_Utils::arrayDeepMerge($this->_options, $options); } - public function setTableDefinition() + public function setTableDefinition(IPF_ORM_Table $table) { - $table = $this->getTable(); - $table->setColumn($this->_options['name'], $this->_options['type'], $this->_options['length'], $this->_options['options']); if ($this->_options['unique'] == true && $this->_options['uniqueIndex'] == true && !empty($this->_options['fields'])) { diff --git a/ipf/orm/template/timestampable.php b/ipf/orm/template/timestampable.php index 5c7c813..117b025 100644 --- a/ipf/orm/template/timestampable.php +++ b/ipf/orm/template/timestampable.php @@ -28,15 +28,15 @@ class IPF_ORM_Template_Timestampable extends IPF_ORM_Template $this->_options = IPF_ORM_Utils::arrayDeepMerge($this->_options, $options); } - public function setTableDefinition() + public function setTableDefinition(IPF_ORM_Table $table) { if (!$this->_options['created']['disabled']) { - $this->getTable()->setColumn($this->_options['created']['name'], $this->_options['created']['type'], null, $this->_options['created']['options']); + $table->setColumn($this->_options['created']['name'], $this->_options['created']['type'], null, $this->_options['created']['options']); } if (!$this->_options['updated']['disabled']) { - $this->getTable()->setColumn($this->_options['updated']['name'], $this->_options['updated']['type'], null, $this->_options['updated']['options']); + $table->setColumn($this->_options['updated']['name'], $this->_options['updated']['type'], null, $this->_options['updated']['options']); } - $this->getTable()->listeners['Timestampable_'.print_r($this->_options, true)] = new IPF_ORM_Template_Listener_Timestampable($this->_options); + $table->listeners['Timestampable_'.print_r($this->_options, true)] = new IPF_ORM_Template_Listener_Timestampable($this->_options); } }