[Solar-svn] Revision 3022

pmjones at solarphp.com pmjones at solarphp.com
Thu Mar 20 07:43:24 CDT 2008


Solar_Cli_MakeModel

* [FIX] Now honors the "extends" option.

* [FIX] Now correctly descends from Solar_Cli_Base.  Thanks, Nate Abele.


Modified: trunk/Solar/Cli/MakeModel.php
===================================================================
--- trunk/Solar/Cli/MakeModel.php	2008-03-20 12:41:43 UTC (rev 3021)
+++ trunk/Solar/Cli/MakeModel.php	2008-03-20 12:43:24 UTC (rev 3022)
@@ -14,7 +14,7 @@
  * @version $Id$
  * 
  */
-class Solar_Cli_MakeModel extends Solar_Controller_Command {
+class Solar_Cli_MakeModel extends Solar_Cli_Base {
     
     /**
      * 
@@ -37,6 +37,15 @@
     
     /**
      * 
+     * The class name this model extends from.
+     * 
+     * @var string
+     * 
+     */
+    protected $_extends = 'Solar_Sql_Model';
+    
+    /**
+     * 
      * Array of model-class templates (skeletons).
      * 
      * @var array
@@ -68,6 +77,9 @@
         // we need a target directory
         $this->_setTarget();
         
+        // extend this class
+        $this->_setExtends();
+        
         // emit feedback
         $this->_outln("Using table '{$this->_table}'.");
         $this->_outln("Writing '$class' to '{$this->_target}'.");
@@ -84,13 +96,10 @@
             ));
         }
         
-        // what class the model extends from
-        $extends = 'Solar_Sql_Model';
-        
         // get the class model template
         $text = str_replace(
             array(':class', ':extends'),
-            array($class, $extends),
+            array($class, $this->_extends),
             $this->_tpl['model']
         );
         
@@ -138,7 +147,7 @@
         $record_target = substr($target, 0, -4) . DIRECTORY_SEPARATOR . 'Record.php';
         $text = str_replace(
             array(':class', ':extends'),
-            array($class, $extends),
+            array($class, $this->_extends),
             $this->_tpl['record']
         );
         
@@ -153,7 +162,7 @@
         $collection_target = substr($target, 0, -4) . DIRECTORY_SEPARATOR . 'Collection.php';
         $text = str_replace(
             array(':class', ':extends'),
-            array($class, $extends),
+            array($class, $this->_extends),
             $this->_tpl['collection']
         );
         
@@ -241,6 +250,23 @@
     
     /**
      * 
+     * Sets the class this model will extend from.
+     * 
+     * @return void
+     * 
+     */
+    protected function _setExtends()
+    {
+        $extends = $this->_options['extends'];
+        if ($extends) {
+            $this->_extends = $extends;
+        } else {
+            $this->_extends = 'Solar_Sql_Model';
+        }
+    }
+    
+    /**
+     * 
      * Gets the SQL connection parameters from the command line options.
      * 
      * @return array An array of SQL connection parameters suitable for 




More information about the Solar-svn mailing list