[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/propel-generator/classes/propel/engine/builder/om/php5/ -> PHP5MapBuilderBuilder.php (source)

   1  <?php
   2  
   3  /*
   4   *  $Id: PHP5BasicObjectBuilder.php 120 2005-06-17 02:18:41Z hans $
   5   *
   6   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   7   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   8   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   9   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17   *
  18   * This software consists of voluntary contributions made by many individuals
  19   * and is licensed under the LGPL. For more information please see
  20   * <http://propel.phpdb.org>.
  21   */
  22  
  23  require_once 'propel/engine/builder/om/OMBuilder.php';
  24  
  25  /**
  26   * Generates the PHP5 map builder class for user object model (OM).
  27   * 
  28   * This class replaces the MapBuilder.tpl, with the intent of being easier for users
  29   * to customize (through extending & overriding).
  30   * 
  31   * @author Hans Lellelid <hans@xmpl.org>
  32   * @package propel.engine.builder.om.php5
  33   */
  34  class PHP5MapBuilderBuilder extends OMBuilder {
  35  
  36      /**
  37       * Gets the package for the map builder classes.
  38       * @return string
  39       */
  40  	public function getPackage()
  41      {
  42          return parent::getPackage() . '.map';
  43      }
  44      
  45      /**
  46       * Returns the name of the current class being built.
  47       * @return string
  48       */
  49  	public function getClassname()
  50      {
  51          return $this->getTable()->getPhpName() . 'MapBuilder';
  52      }
  53  
  54      /**
  55       * Adds the include() statements for files that this class depends on or utilizes.
  56       * @param string &$script The script will be modified in this method.
  57       */
  58  	protected function addIncludes(&$script)
  59      {        
  60          $script .= "        
  61  require_once 'propel/map/MapBuilder.php';
  62  include_once 'creole/CreoleTypes.php';
  63  ";
  64          
  65          
  66      } // addIncludes()
  67      
  68      /**
  69       * Adds class phpdoc comment and openning of class.
  70       * @param string &$script The script will be modified in this method.
  71       */
  72  	protected function addClassOpen(&$script)
  73      {
  74          $table = $this->getTable();        
  75          $script .= "
  76  
  77  /**
  78   * This class adds structure of '".$table->getName()."' table to '".$table->getDatabase()->getName()."' DatabaseMap object.
  79   *
  80   *";
  81          if ($this->getBuildProperty('addTimeStamp')) {
  82              $now = strftime('%c');
  83              $script .= "
  84   * This class was autogenerated by Propel on:
  85   *
  86   * $now
  87   *";
  88          }
  89          $script .= "
  90   *
  91   * These statically-built map classes are used by Propel to do runtime db structure discovery.
  92   * For example, the createSelectSql() method checks the type of a given column used in an 
  93   * ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive 
  94   * (i.e. if it's a text column type).
  95   *
  96   * @package ".$this->getPackage()."
  97   */    
  98  class ".$this->getClassname()." {
  99  ";
 100      }
 101      
 102      /**
 103       * Specifies the methods that are added as part of the map builder class.
 104       * This can be overridden by subclasses that wish to add more methods.
 105       * @see ObjectBuilder::addClassBody()
 106       */
 107  	protected function addClassBody(&$script)
 108      {
 109          $this->addConstants($script);
 110          $this->addAttributes($script);
 111          
 112          $this->addIsBuilt($script);
 113          $this->addGetDatabaseMap($script);
 114          $this->addDoBuild($script);
 115      }
 116      
 117      /**
 118       * Adds any constants needed for this MapBuilder class.
 119       * @param string &$script The script will be modified in this method.
 120       */
 121  	protected function addConstants(&$script)
 122      {
 123          $script .= "
 124      /**
 125       * The (dot-path) name of this class
 126       */
 127      const CLASS_NAME = '".$this->getClasspath()."';    
 128  ";
 129      }
 130      
 131      /**
 132       * Adds any attributes needed for this MapBuilder class.
 133       * @param string &$script The script will be modified in this method.
 134       */
 135  	protected function addAttributes(&$script)
 136      {
 137          $script .= "
 138      /**
 139       * The database map.
 140       */
 141      private \$dbMap;
 142  ";
 143      }
 144      
 145      /**
 146       * Closes class.
 147       * @param string &$script The script will be modified in this method.
 148       */    
 149  	protected function addClassClose(&$script)
 150      {
 151          $script .= "
 152  } // " . $this->getClassname() . "
 153  ";
 154      }
 155      
 156      /**
 157       * Adds the method that indicates whether this map has already been built.
 158       * @param string &$script The script will be modified in this method.
 159       */    
 160  	protected function addIsBuilt(&$script)
 161      {
 162          $script .= "
 163      /**
 164       * Tells us if this DatabaseMapBuilder is built so that we
 165       * don't have to re-build it every time.
 166       *
 167       * @return boolean true if this DatabaseMapBuilder is built, false otherwise.
 168       */
 169      public function isBuilt()
 170      {
 171          return (\$this->dbMap !== null);
 172      }
 173  ";
 174      }
 175      
 176      /**
 177       * Adds the DatabaseMap accessor method.
 178       * @param string &$script The script will be modified in this method.
 179       */    
 180  	protected function addGetDatabaseMap(&$script)
 181      {
 182          $script .= "
 183      /**
 184       * Gets the databasemap this map builder built.
 185       *
 186       * @return the databasemap
 187       */
 188      public function getDatabaseMap()
 189      {
 190          return \$this->dbMap;
 191      }
 192  ";
 193      }
 194      
 195      /**
 196       * Adds the main doBuild() method to the map builder class.
 197       * @param string &$script The script will be modified in this method.
 198       */    
 199  	protected function addDoBuild(&$script)
 200      {
 201      
 202          $table = $this->getTable();
 203          $platform = $this->getPlatform();
 204          
 205          $script .= "
 206      /**
 207       * The doBuild() method builds the DatabaseMap
 208       *
 209       * @return void
 210       * @throws PropelException
 211       */
 212      public function doBuild()
 213      {
 214          \$this->dbMap = Propel::getDatabaseMap('".$table->getDatabase()->getName()."');
 215          
 216          \$tMap = \$this->dbMap->addTable('".$table->getName()."');
 217          \$tMap->setPhpName('".$table->getPhpName()."');
 218  ";
 219          if ($table->getIdMethod() == "native") { 
 220              $script .= "
 221          \$tMap->setUseIdGenerator(true);
 222  ";
 223          } else { 
 224              $script .= "
 225          \$tMap->setUseIdGenerator(false);
 226  ";
 227          }
 228  
 229          if ($table->getIdMethodParameters()) {
 230              $params = $table->getIdMethodParameters();
 231              $imp = $params[0];
 232              $script .= "
 233          \$tMap->setPrimaryKeyMethodInfo('".$imp->getValue()."');
 234  ";
 235          } elseif ($table->getIdMethod() == "native" && ($platform->getNativeIdMethod() == Platform::SEQUENCE)) {
 236              $script .= " 
 237          \$tMap->setPrimaryKeyMethodInfo('".$table->getSequenceName()."');
 238  ";
 239          } elseif ($table->getIdMethod() == "native" && ($platform->getNativeIdMethod() == Platform::SEQUENCE)) {
 240              $script .= " 
 241          \$tMap->setPrimaryKeyMethodInfo('".$table->getName()."');
 242  ";
 243          }
 244          
 245          // Add columns to map
 246          foreach ($table->getColumns() as $col) {
 247              $tfc=$table->getPhpName();
 248              $cfc=$col->getPhpName();
 249              $cup=strtoupper($col->getName());
 250              if (!$col->getSize()) {
 251                  $size = "null";
 252              } else {
 253                  $size = $col->getSize();
 254              }
 255              if($col->isPrimaryKey()) {
 256                  if($col->isForeignKey()) {
 257                      $script .= "
 258          \$tMap->addForeignPrimaryKey('$cup', '$cfc', '".$col->getPhpType()."' , CreoleTypes::".$col->getType().", '".$col->getRelatedTableName()."', '".strtoupper($col->getRelatedColumnName())."', ".($col->isNotNull() ? 'true' : 'false').", ".$size.");
 259  ";
 260                  } else {
 261                      $script .= "
 262          \$tMap->addPrimaryKey('$cup', '$cfc', '".$col->getPhpType()."', CreoleTypes::".$col->getType().", ".var_export($col->isNotNull(), true).", ".$size.");
 263  ";
 264                  } 
 265              } else {
 266                  if($col->isForeignKey()) {
 267                      $script .= "
 268          \$tMap->addForeignKey('$cup', '$cfc', '".$col->getPhpType()."', CreoleTypes::".$col->getType().", '".$col->getRelatedTableName()."', '".strtoupper($col->getRelatedColumnName())."', ".($col->isNotNull() ? 'true' : 'false').", ".$size.");
 269  ";
 270              } else { 
 271                      $script .= "
 272          \$tMap->addColumn('$cup', '$cfc', '".$col->getPhpType()."', CreoleTypes::".$col->getType().", ".var_export($col->isNotNull(), true).");
 273  ";
 274                  } 
 275              } // if col-is prim key
 276          } // foreach
 277          
 278          foreach($table->getValidators() as $val) {
 279              $col = $val->getColumn();
 280              $cup = strtoupper($col->getName());
 281              foreach($val->getRules() as $rule) {
 282                  if ($val->getTranslate() !== Validator::TRANSLATE_NONE) {
 283                      $script .= "
 284          \$tMap->addValidator('$cup', '".$rule->getName()."', '".$rule->getClass()."', '".$rule->getValue()."', ".$val->getTranslate()."('".str_replace("'", "\'", $rule->getMessage())."'));
 285  ";
 286                  } else {
 287                      $script .= "
 288          \$tMap->addValidator('$cup', '".$rule->getName()."', '".$rule->getClass()."', '".$rule->getValue()."', '".str_replace("'", "\'", $rule->getMessage())."');
 289  ";
 290                  } // if ($rule->getTranslation() ...
 291                } // foreach rule
 292          }  // foreach validator
 293          
 294          $script .= "                
 295      } // doBuild()
 296  ";
 297  
 298      }
 299      
 300  } // PHP5ExtensionPeerBuilder


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7