[ 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/phing/ -> PropelOMTask.php (source)

   1  <?php
   2  
   3  /*

   4   *  $Id: PropelOMTask.php 258 2005-11-07 16:12:09Z 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/phing/AbstractPropelDataModelTask.php';
  24  include_once 'propel/engine/builder/om/ClassTools.php';
  25  require_once 'propel/engine/builder/om/OMBuilder.php';
  26  
  27  /**

  28   * This Task creates the OM classes based on the XML schema file.

  29   * 

  30   * @author Hans Lellelid <hans@xmpl.org>

  31   * @package propel.phing

  32   */
  33  class PropelOMTask extends AbstractPropelDataModelTask {
  34  
  35      /**

  36       * The platform (php4, php5, etc.) for which the om is being built.

  37       * @var string

  38       */
  39      private $targetPlatform;
  40      
  41      /**

  42       * Sets the platform (php4, php5, etc.) for which the om is being built.

  43       * @param string $v

  44       */
  45  	public function setTargetPlatform($v) {
  46          $this->targetPlatform = $v;
  47      }
  48      
  49      /**

  50       * Gets the platform (php4, php5, etc.) for which the om is being built.

  51       * @return string

  52       */
  53  	public function getTargetPlatform() {
  54          return $this->targetPlatform;
  55      }
  56      
  57      /**

  58       * Utility method to create directory for package if it doesn't already exist.

  59       * @param string $path The [relative] package path.

  60       * @throws BuildException - if there is an error creating directories

  61       */
  62  	protected function ensureDirExists($path)
  63      {
  64          $f = new PhingFile($this->getOutputDirectory(), $path);
  65          if (!$f->exists()) {
  66              if (!$f->mkdirs()) {
  67                  throw new BuildException("Error creating directories: ". $f->getPath());
  68              }
  69          }
  70      }
  71      
  72      /**

  73       * Uses a builder class to create the output class.

  74       * This method assumes that the DataModelBuilder class has been initialized with the build properties.

  75       * @param OMBuilder $builder

  76       * @param boolean $overwrite Whether to overwrite existing files with te new ones (default is YES).

  77       * @todo -cPropelOMTask Consider refactoring build() method into AbstractPropelDataModelTask (would need to be more generic).

  78       */
  79  	protected function build(OMBuilder $builder, $overwrite = true)
  80      {
  81          
  82          $path = $builder->getClassFilePath();
  83          $this->ensureDirExists(dirname($path));
  84          
  85          $_f = new PhingFile($this->getOutputDirectory(), $path);
  86          if ($overwrite || !$_f->exists()) {
  87              $this->log("\t\t-> " . $builder->getClassname() . " [builder: " . get_class($builder) . "]");
  88              $script = $builder->build();
  89              file_put_contents($_f->getAbsolutePath(), $script);
  90              foreach($builder->getWarnings() as $warning) {
  91                  $this->log($warning, PROJECT_MSG_WARN);
  92              }
  93          } else {
  94              $this->log("\t\t-> (exists) " . $builder->getClassname());
  95          }
  96          
  97      }
  98      
  99      /**

 100       * Main method builds all the targets for a typical propel project.

 101       */
 102  	public function main()
 103      {        
 104          // check to make sure task received all correct params

 105          $this->validate();        
 106          
 107          $basepath = $this->getOutputDirectory();        
 108          
 109          // Get new Capsule context

 110          $generator = $this->createContext();
 111          $generator->put("basepath", $basepath); // make available to other templates

 112          
 113          $targetPlatform = $this->getTargetPlatform(); // convenience for embedding in strings below

 114                  
 115          // we need some values that were loaded into the template context

 116          $basePrefix = $generator->get('basePrefix');
 117          $project = $generator->get('project');
 118          
 119          DataModelBuilder::setBuildProperties($this->getPropelProperties());
 120          
 121          foreach ($this->getDataModels() as $dataModel) {
 122              $this->log("Processing Datamodel : " . $dataModel->getName());
 123              
 124              foreach ($dataModel->getDatabases() as $database) {
 125                  
 126                  $this->log("  - processing database : " . $database->getName());
 127                  $generator->put("platform", $database->getPlatform());
 128                  
 129                              
 130                  foreach ($database->getTables() as $table) {                    
 131                  
 132                      if (!$table->isForReferenceOnly()) {
 133                          
 134                          $this->log("\t+ " . $table->getName());
 135                          
 136                          // -----------------------------------------------------------------------------------------

 137                          // Create Peer, Object, and MapBuilder classes

 138                          // -----------------------------------------------------------------------------------------

 139                          
 140                          // these files are always created / overwrite any existing files

 141                          foreach(array('peer', 'object', 'mapbuilder') as $target) {
 142                              $builder = DataModelBuilder::builderFactory($table, $target);
 143                              $this->build($builder);
 144                          }
 145                          
 146                          // -----------------------------------------------------------------------------------------

 147                          // Create [empty] stub Peer and Object classes if they don't exist

 148                          // -----------------------------------------------------------------------------------------

 149                          
 150                          // these classes are only generated if they don't already exist

 151                          foreach(array('peerstub', 'objectstub') as $target) {
 152                              $builder = DataModelBuilder::builderFactory($table, $target);
 153                              $this->build($builder, $overwrite=false);
 154                          }
 155                          
 156                          // -----------------------------------------------------------------------------------------

 157                          // Create [empty] stub child Object classes if they don't exist

 158                          // -----------------------------------------------------------------------------------------

 159                          
 160                          // If table has enumerated children (uses inheritance) then create the empty child stub classes if they don't already exist.

 161                          if ($table->getChildrenColumn()) {
 162                              $col = $table->getChildrenColumn();
 163                              if ($col->isEnumeratedClasses()) {
 164                                  foreach ($col->getChildren() as $child) {
 165                                      $builder = DataModelBuilder::builderFactory($table, 'objectmultiextend');
 166                                      $builder->setChild($child);
 167                                      $this->build($builder, $overwrite=false);
 168                                  } // foreach

 169                              } // if col->is enumerated

 170                          } // if tbl->getChildrenCol

 171                          
 172                          
 173                          // -----------------------------------------------------------------------------------------

 174                          // Create [empty] Interface if it doesn't exist

 175                          // -----------------------------------------------------------------------------------------

 176                          
 177                          // Create [empty] interface if it does not already exist

 178                          if ($table->getInterface()) {
 179                              $builder = DataModelBuilder::builderFactory($table, 'interface');
 180                              $this->build($builder, $overwrite=false);
 181                          }
 182                          
 183                          // -----------------------------------------------------------------------------------------

 184                          // Create tree Node classes

 185                          // -----------------------------------------------------------------------------------------

 186                          
 187                          if ($table->isTree()) {
 188                              
 189                              foreach(array('nodepeer', 'node') as $target) {                            
 190                                  $builder = DataModelBuilder::builderFactory($table, $target);
 191                                  $this->build($builder);                            
 192                              }
 193                              
 194                              foreach(array('nodepeerstub', 'nodestub') as $target) {
 195                                  $builder = DataModelBuilder::builderFactory($table, $target);
 196                                  $this->build($builder, $overwrite=false);                            
 197                              }
 198                              
 199                          } // if Table->isTree()

 200                          
 201                          
 202                      } // if !$table->isForReferenceOnly()                                        

 203                      
 204                  } // foreach table    

 205          
 206              } // foreach database

 207          
 208          } // foreach dataModel

 209  
 210      
 211      } // main()

 212  }


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