]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
simplify orm templates
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 19:42:57 +0000 (22:42 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 19:42:57 +0000 (22:42 +0300)
ipf/orm/table.php
ipf/orm/template.php
ipf/orm/template/orderable.php
ipf/orm/template/owned.php
ipf/orm/template/sluggable.php
ipf/orm/template/timestampable.php

index 5a5f1931544d36b11f51cf634db0cd5e03486d5a..e91896a5c168292f046e153d219e8b24e17865ab 100644 (file)
@@ -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()
index d963da11453a156b70352e53e74eff8f930cdf18..93394985c660af34eccb3a5a4bd806b6abc769d3 100644 (file)
@@ -1,19 +1,9 @@
 <?php
 
-abstract class IPF_ORM_Template extends IPF_ORM_Record_Abstract
+abstract class IPF_ORM_Template
 {
     protected $_invoker;
 
-    public function setTable(IPF_ORM_Table $table)
-    {
-        $this->_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)
 }
 
index 9e7ea2cf9e33cbd3889cefb6a9a35dc2a7235ace..4ed0a330b4398583e28a5a7cb032e8b308a7472a 100644 (file)
@@ -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);
index db204c0f63fd6b2bd4f6497e7a24d1db7d4dce70..7b7e69d757245ededd0f16194af682fb22fb78e6 100644 (file)
@@ -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);
     }
 }
 
index c9e0003bb51a41bf9dc7efbcc2d41b7e9dd961c0..30d14ed714ce1e750c33a22843f99489607adad5 100644 (file)
@@ -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'])) {
index 5c7c813c8d666e643a4ffb8c9c279d900a06ee35..117b02539a97469ff1277e0750357a5f90018b04 100644 (file)
@@ -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);
     }
 }