]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
unify adding templates to a record
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 14:19:27 +0000 (17:19 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 14:19:27 +0000 (17:19 +0300)
ipf/orm/import/builder.php
ipf/orm/record/abstract.php
ipf/orm/table.php

index 3b34351604020690d1d5f5d5c9e89a02942d77f0..2f6d6aefdc5b68d522a506f2251e243308299857 100644 (file)
@@ -228,12 +228,12 @@ class IPF_ORM_Import_Builder
             if (is_array($options) && !empty($options)) {
                 $optionsPhp = self::varExport($options);
 
-                $build .= "    \$this->loadTemplate('" . $name . "', " . $optionsPhp . ");" . PHP_EOL;
+                $build .= "    \$this->getTable()->addTemplate('" . $name . "', " . $optionsPhp . ");" . PHP_EOL;
             } else {
                 if (isset($templates[0])) {
-                    $build .= "    \$this->loadTemplate('" . $options . "');" . PHP_EOL;
+                    $build .= "    \$this->getTable()->addTemplate('" . $options . "');" . PHP_EOL;
                 } else {
-                    $build .= "    \$this->loadTemplate('" . $name . "');" . PHP_EOL;
+                    $build .= "    \$this->getTable()->addTemplate('" . $name . "');" . PHP_EOL;
                 }
             }
         }
@@ -258,7 +258,7 @@ class IPF_ORM_Import_Builder
 
     private function emitActAs($level, $name)
     {
-        return "    \$this->actAs(\$" . strtolower($name) . "$level);" . PHP_EOL;
+        return "    \$this->getTable()->addTemplate(\$" . strtolower($name) . "$level);" . PHP_EOL;
     }
 
     private function buildActAs($actAs)
index 2bef5075d63894f34875ad766b4b98b297cd7632..f34c98cd2b067b9db286f37632d1023a0c2d5335 100644 (file)
@@ -114,11 +114,6 @@ abstract class IPF_ORM_Record_Abstract extends IPF_ORM_Access
         }
     } 
 
-    public function loadTemplate($template, array $options = array())
-    {
-        $this->actAs($template, $options);
-    }
-
     public function bindQueryParts(array $queryParts)
     {
         $this->_table->bindQueryParts($queryParts);
@@ -131,35 +126,6 @@ abstract class IPF_ORM_Record_Abstract extends IPF_ORM_Access
         $this->_table->addGenerator($generator, get_class($generator));
     }
 
-    public function actAs($tpl, array $options = array())
-    {
-        if ( ! is_object($tpl)) {
-            $className = 'IPF_ORM_Template_' . $tpl;
-
-            if (class_exists($className, true)) {
-                $tpl = new $className($options);
-            } else if (class_exists($tpl, true)) {
-                $tpl = new $tpl($options);
-            } else {
-                throw new IPF_ORM_Record_Exception('Could not load behavior named: "' . $tpl . '"');
-            }
-        }
-
-        if ( ! ($tpl instanceof IPF_ORM_Template)) {
-            throw new IPF_ORM_Record_Exception('Loaded behavior class is not an istance of IPF_ORM_Template.');
-        }
-
-        $className = get_class($tpl);
-
-        $this->_table->addTemplate($className, $tpl);
-
-        $tpl->setTable($this->_table);
-        $tpl->setUp();
-        $tpl->setTableDefinition();
-
-        return $this;
-    }
-
     public function check($constraint, $name = null)
     {
         if (is_array($constraint)) {
index 73ce2a40a99598624028353323fdd4aa8202fc75..5328b9ff0c3c8a82348bd6b833a63672baed38b6 100644 (file)
@@ -997,11 +997,30 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable
         return isset($this->_templates[$template]);
     }
 
-    public function addTemplate($template, IPF_ORM_Template $impl)
+    public function addTemplate($tpl, array $options=array())
     {
-        $this->_templates[$template] = $impl;
+        if (!is_object($tpl)) {
+            $className = 'IPF_ORM_Template_' . $tpl;
 
-        return $this;
+            if (class_exists($className, true)) {
+                $tpl = new $className($options);
+            } else if (class_exists($tpl, true)) {
+                $tpl = new $tpl($options);
+            } else {
+                throw new IPF_ORM_Record_Exception('Could not load behavior named: "' . $tpl . '"');
+            }
+        }
+
+        if (!($tpl instanceof IPF_ORM_Template)) {
+            throw new IPF_ORM_Record_Exception('Loaded behavior class is not an istance of IPF_ORM_Template.');
+        }
+
+        $className = get_class($tpl);
+        $this->_templates[$className] = $tpl;
+
+        $tpl->setTable($this);
+        $tpl->setUp();
+        $tpl->setTableDefinition();
     }
 
     public function getGenerators()