[ 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/ -> PHP5MultiExtendObjectBuilder.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/ObjectBuilder.php';
  24  
  25  /**
  26   * Generates the empty PHP5 stub object class for use with inheritance in the user object model (OM).
  27   * 
  28   * This class produces the empty stub class that can be customized with application
  29   * business logic, custom behavior, etc.
  30   * 
  31   * This class replaces the MultiExtendObject.tpl, with the intent of being easier for users
  32   * to customize (through extending & overriding).
  33   * 
  34   * @author Hans Lellelid <hans@xmpl.org>
  35   * @package propel.engine.builder.om.php5
  36   */
  37  class PHP5MultiExtendObjectBuilder extends ObjectBuilder {
  38      
  39      /**
  40       * The current child "object" we are operating on.
  41       */
  42      private $child;
  43      
  44      /**
  45       * Returns the name of the current class being built.
  46       * @return string
  47       */
  48  	public function getClassname()
  49      {
  50          return $this->getChild()->getClassName();
  51      }
  52      
  53      /**
  54       * Override method to return child package, if specified.
  55       * @return string
  56       */
  57  	public function getPackage()
  58      {
  59          return ($this->child->getPackage() ? $this->child->getPackage() : parent::getPackage());
  60      }
  61      
  62      /**
  63       * Set the child object that we're operating on currrently.
  64       * @param $child Inheritance
  65       */
  66  	public function setChild(Inheritance $child)
  67      {
  68          $this->child = $child;
  69      }
  70      
  71      /**
  72       * Returns the child object we're operating on currently.
  73       * @return Inheritance
  74       * @throws BuildException - if child was not set.
  75       */
  76  	public function getChild()
  77      {
  78          if (!$this->child) {
  79              throw new BuildException("The PHP5MultiExtendObjectBuilder needs to be told which child class to build (via setChild() method) before it can build the stub class.");
  80          }
  81          return $this->child;
  82      }
  83      
  84      /**
  85       * Returns classpath to parent class.
  86       * @return string
  87       */
  88  	protected function getParentClasspath()
  89      {
  90          if ($this->getChild()->getAncestor()) {
  91              return $this->getChild()->getAncestor();
  92          } else {
  93              return $this->getObjectBuilder()->getClasspath();
  94          }
  95      }
  96      
  97      /**
  98       * Returns classname of parent class.
  99       * @return string
 100       */
 101  	protected function getParentClassname()
 102      {
 103          return ClassTools::classname($this->getParentClasspath());
 104      }
 105      
 106      /**
 107       * Gets the file path to the parent class.
 108       * @return string
 109       */
 110  	protected function getParentClassFilePath()
 111      {
 112          return $this->getFilePath($this->getParentClasspath());
 113      }
 114      
 115      /**
 116       * Adds the include() statements for files that this class depends on or utilizes.
 117       * @param string &$script The script will be modified in this method.
 118       */
 119  	protected function addIncludes(&$script)
 120      {
 121          $script .= "
 122  require_once '".$this->getParentClassFilePath()."';
 123  ";
 124          $script .= "
 125  require_once '".$this->getObjectBuilder()->getClassFilePath()."';
 126  ";
 127      } // addIncludes()
 128      
 129      /**
 130       * Adds class phpdoc comment and openning of class.
 131       * @param string &$script The script will be modified in this method.
 132       */
 133  	protected function addClassOpen(&$script)
 134      {
 135          
 136          $table = $this->getTable();
 137          $tableName = $table->getName();
 138          $tableDesc = $table->getDescription();
 139          
 140          $baseClassname = $this->getObjectBuilder()->getClassname();
 141          
 142          $script .= "
 143  
 144  /**
 145   * Skeleton subclass for representing a row from one of the subclasses of the '$tableName' table.
 146   *
 147   * $tableDesc
 148   *";
 149          if ($this->getBuildProperty('addTimeStamp')) {
 150              $now = strftime('%c');
 151              $script .= "
 152   * This class was autogenerated by Propel on:
 153   *
 154   * $now
 155   *";
 156          }
 157          $script .= "
 158   * You should add additional methods to this class to meet the
 159   * application requirements.  This class will only be generated as
 160   * long as it does not already exist in the output directory.
 161   *
 162   * @package ".$this->getPackage()."
 163   */    
 164  class ".$this->getClassname()." extends ".$this->getParentClassname()." {
 165  ";
 166      }
 167      
 168      /**
 169       * Specifies the methods that are added as part of the stub object class.
 170       * 
 171       * By default there are no methods for the empty stub classes; override this method
 172       * if you want to change that behavior.
 173       * 
 174       * @see ObjectBuilder::addClassBody()
 175       */
 176  	protected function addClassBody(&$script)
 177      {
 178          $child = $this->getChild();
 179          $col = $child->getColumn();
 180          $cfc = $col->getPhpName();
 181          
 182          $const = "CLASSKEY_".strtoupper($child->getKey());
 183          
 184          $script .= "
 185      /**
 186       * Constructs a new ".$this->getChild()->getClassName()." class, setting the ".$col->getName()." column to ".$this->getPeerClassname()."::$const.
 187       */
 188  	public function __construct()
 189      {
 190  ";
 191          
 192          $script .= "
 193          \$this->set$cfc(".$this->getPeerClassname()."::CLASSKEY_".strtoupper($child->getKey()).");
 194      }
 195  ";
 196      }
 197      
 198      /**
 199       * Closes class.
 200       * @param string &$script The script will be modified in this method.
 201       */    
 202  	protected function addClassClose(&$script)
 203      {
 204          $script .= "
 205  } // " . $this->getClassname() . "
 206  ";
 207      }
 208      
 209  } // PHP5ExtensionObjectBuilder


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