Changeset 423

Show
Ignore:
Timestamp:
11.07.2006 21:00:11 (4 years ago)
Author:
hans
Message:

ticket:268 (wrapping up)

  • Reverted the change from changeset:372 that required that static code be put in the extension classes
  • Changed static attributes of the base peer class to not reference the peer subclass
  • Changed OMBuilder::getColumnConstant() method to take an optional classname parameter.
Location:
trunk/generator/classes/propel/engine/builder/om
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/generator/classes/propel/engine/builder/om/OMBuilder.php

    r186 r423  
    357357     *  
    358358     * @param Column $col The column we need a name for. 
    359      * @param string $phpName The PHP Name of the peer class. The 'Peer' is appended automatically. 
     359     * @param string $classname The Peer classname to use. 
    360360     *  
    361      * @return string If $phpName is provided, then will return {$phpName}Peer::COLUMN_NAME; if not, then uses current table COLUMN_NAME. 
     361     * @return string If $classname is provided, then will return $classname::COLUMN_NAME; if not, then the peername is looked up for current table to yield $currTablePeer::COLUMN_NAME. 
    362362     */ 
    363     public function getColumnConstant($col, $phpName = null) 
     363    public function getColumnConstant($col, $classname = null) 
    364364        {        
    365365                if ($col === null) { 
     
    368368                        throw $e; 
    369369                } 
    370                 $classname = $this->getPeerClassname($phpName); 
     370                 
     371                if ($classname === null) { 
     372                        $classname = $this->getPeerClassname(); 
     373                } 
    371374                 
    372375        // was it overridden in schema.xml ? 
  • trunk/generator/classes/propel/engine/builder/om/php5/PHP5BasicPeerBuilder.php

    r417 r423  
    118118} // " . $this->getClassname() . " 
    119119"; 
    120         } 
     120                $this->addStaticMapBuilderRegistration($script); 
     121        } 
     122 
     123        /** 
     124         * Adds the static map builder registration code. 
     125         * @param string &$script The script will be modified in this method. 
     126         */ 
     127        protected function addStaticMapBuilderRegistration(&$script) 
     128        { 
     129                $table = $this->getTable(); 
     130                $mapBuilderFile = $this->getMapBuilderBuilder()->getClassFilePath(); 
     131 
     132                $script .= " 
     133// This is the static code needed to register the MapBuilder for this table with the main Propel class. 
     134// 
     135// NOTE: This static code cannot call methods on the ".$this->getPeerClassname()." class, because it is not defined yet. 
     136// If you need to use overridden methods, you can add this code to the bottom of the ".$this->getPeerClassname()." class: 
     137//  
     138// Propel::getDatabaseMap(".$this->getPeerClassname()."::DATABASE_NAME)->addTableBuilder(".$this->getPeerClassname()."::TABLE_NAME, ".$this->getPeerClassname()."::getMapBuilder()); 
     139//  
     140// Doing so will effectively overwrite the registration below. 
     141 
     142Propel::getDatabaseMap(".$this->getClassname()."::DATABASE_NAME)->addTableBuilder(".$this->getClassname()."::TABLE_NAME, ".$this->getClassname()."::getMapBuilder()); 
     143 
     144"; 
     145        } 
     146 
    121147 
    122148        /** 
     
    208234                BasePeer::TYPE_COLNAME => array ("; 
    209235                foreach ($tableColumns as $col) { 
    210                         $script .= $this->getColumnConstant($col).", "; 
     236                        $script .= $this->getColumnConstant($col, 'self').", "; 
    211237                } 
    212238                $script .= "), 
     
    247273                BasePeer::TYPE_COLNAME => array ("; 
    248274                foreach ($tableColumns as $num => $col) { 
    249                         $script .= $this->getColumnConstant($col)." => $num, "; 
     275                        $script .= $this->getColumnConstant($col, 'self')." => $num, "; 
    250276                } 
    251277                $script .= "), 
  • trunk/generator/classes/propel/engine/builder/om/php5/PHP5ExtensionPeerBuilder.php

    r372 r423  
    123123} // " . $this->getClassname() . " 
    124124"; 
    125                 $this->addStaticMapBuilderRegistration($script); 
    126125        } 
    127126         
    128         /** 
    129          * Adds the static map builder registration code. 
    130          * @param string &$script The script will be modified in this method. 
    131          */ 
    132         protected function addStaticMapBuilderRegistration(&$script) 
    133         { 
    134                 $table = $this->getTable(); 
    135                 $mapBuilderFile = $this->getMapBuilderBuilder()->getClassFilePath(); 
    136  
    137                 $script .= " 
    138 // static code to register the map builder for this table with the main Propel class 
    139 try { 
    140         Propel::getDatabaseMap(".$this->getPeerClassname()."::DATABASE_NAME)->addTableBuilder(".$this->getPeerClassname()."::TABLE_NAME, ".$this->getPeerClassname()."::getMapBuilder()); 
    141 } catch (Exception \$e) { 
    142         Propel::log('Could not register MapBuilder  for ".$this->getPeerClassname()." with Propel: ' . \$e->getMessage(), Propel::LOG_ERR); 
    143 } 
    144 "; 
    145         } 
    146127         
    147128} // PHP5ExtensionPeerBuilder