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

   1  <?php
   2  
   3  /*
   4   *  $Id: PropelOldOMTask.php 176 2005-08-24 15:44:58Z 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  
  26  /**
  27   * This Task creates the OM classes based on the XML schema file using the legacy templates.
  28   *
  29   * @author Hans Lellelid <hans@xmpl.org>
  30   * @package propel.phing
  31   * @deprecated
  32   */
  33  class PropelOldOMTask 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      public function main() {
  58  
  59          // check to make sure task received all correct params
  60          $this->validate();
  61  
  62          $basepath = $this->getOutputDirectory();
  63  
  64          // Get new Capsule context
  65          $generator = $this->createContext();
  66          $generator->put("basepath", $basepath); // make available to other templates
  67  
  68          $targetPlatform = $this->getTargetPlatform(); // convenience for embedding in strings below
  69  
  70          // we need some values that were loaded into the template context
  71          $basePrefix = $generator->get('basePrefix');
  72          $project = $generator->get('project');
  73  
  74          foreach ($this->getDataModels() as $dataModel) {
  75              $this->log("Processing Datamodel : " . $dataModel->getName());
  76  
  77              foreach ($dataModel->getDatabases() as $database) {
  78  
  79                  $this->log("  - processing database : " . $database->getName());
  80                  $generator->put("platform", $database->getPlatform());
  81  
  82  
  83                  foreach ($database->getTables() as $table) {
  84  
  85                      if (!$table->isForReferenceOnly()) {
  86                          if ($table->getPackage()) {
  87                              $package = $table->getPackage();
  88                          } else {
  89                              $package = $this->targetPackage;
  90                          }
  91  
  92                          $pkbase = "$package.om";
  93                          $pkpeer = "$package";
  94                          $pkmap = "$package.map";
  95  
  96                          // make these available
  97                          $generator->put("package", $package);
  98                          $generator->put("pkbase", $pkbase);
  99                          //$generator->put("pkpeer", $pkpeer); -- we're not using this yet
 100                          $generator->put("pkmap", $pkmap);
 101  
 102                          foreach(array($pkpeer, $pkmap, $pkbase) as $pk) {
 103                              $path = strtr($pk, '.', '/');
 104                              $f = new PhingFile($this->getOutputDirectory(), $path);
 105                              if (!$f->exists()) {
 106                                  if (!$f->mkdirs()) {
 107                                      throw new Exception("Error creating directories: ". $f->getPath());
 108                                  }
 109                              }
 110                          } // for each package
 111  
 112  
 113                          $this->log("\t+ " . $table->getName());
 114  
 115                          $generator->put("table", $table);
 116  
 117                          // Create the Base Peer class
 118                          $this->log("\t\t-> " . $basePrefix . $table->getPhpName() . "Peer");
 119                          $path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . "Peer");
 120                          $generator->parse("om/$targetPlatform/Peer.tpl", $path);
 121  
 122                          // Create the Base object class
 123                          $this->log("\t\t-> " . $basePrefix . $table->getPhpName());
 124                          $path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName());
 125                          $generator->parse("om/$targetPlatform/Object.tpl", $path);
 126  
 127                          if ($table->isTree()) {
 128                              // Create the Base NodePeer class
 129                              $this->log("\t\t-> " . $basePrefix . $table->getPhpName() . "NodePeer");
 130                              $path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . "NodePeer");
 131                              $generator->parse("om/$targetPlatform/NodePeer.tpl", $path);
 132  
 133                              // Create the Base Node class if the table is a tree
 134                              $this->log("\t\t-> " . $basePrefix . $table->getPhpName() . "Node");
 135                              $path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . "Node");
 136                              $generator->parse("om/$targetPlatform/Node.tpl", $path);
 137                          }
 138  
 139                          // Create MapBuilder class if this table is not an alias
 140                          if (!$table->isAlias()) {
 141                              $this->log("\t\t-> " . $table->getPhpName() . "MapBuilder");
 142                              $path = ClassTools::getFilePath($pkmap, $table->getPhpName() . "MapBuilder");
 143                              $generator->parse("om/$targetPlatform/MapBuilder.tpl", $path);
 144                          } // if !$table->isAlias()
 145  
 146                          // Create [empty] stub Peer class if it does not already exist
 147                          $path = ClassTools::getFilePath($package, $table->getPhpName() . "Peer");
 148                          $_f = new PhingFile($basepath, $path);
 149                          if (!$_f->exists()) {
 150                              $this->log("\t\t-> " . $table->getPhpName() . "Peer");
 151                              $generator->parse("om/$targetPlatform/ExtensionPeer.tpl", $path);
 152                          } else {
 153                              $this->log("\t\t-> (exists) " . $table->getPhpName() . "Peer");
 154                          }
 155  
 156                          // Create [empty] stub object class if it does not already exist
 157                          $path = ClassTools::getFilePath($package, $table->getPhpName());
 158                          $_f = new PhingFile($basepath, $path);
 159                          if (!$_f->exists()) {
 160                              $this->log("\t\t-> " . $table->getPhpName());
 161                              $generator->parse("om/$targetPlatform/ExtensionObject.tpl", $path);
 162                          } else {
 163                              $this->log("\t\t-> (exists) " . $table->getPhpName());
 164                          }
 165  
 166                          if ($table->isTree()) {
 167                              // Create [empty] stub Node Peer class if it does not already exist
 168                              $path = ClassTools::getFilePath($package, $table->getPhpName() . "NodePeer");
 169                              $_f = new PhingFile($basepath, $path);
 170                              if (!$_f->exists()) {
 171                                  $this->log("\t\t-> " . $table->getPhpName() . "NodePeer");
 172                                  $generator->parse("om/$targetPlatform/ExtensionNodePeer.tpl", $path);
 173                              } else {
 174                                  $this->log("\t\t-> (exists) " . $table->getPhpName() . "NodePeer");
 175                              }
 176  
 177                              // Create [empty] stub Node class if it does not already exist
 178                              $path = ClassTools::getFilePath($package, $table->getPhpName() . "Node");
 179                              $_f = new PhingFile($basepath, $path);
 180                              if (!$_f->exists()) {
 181                                  $this->log("\t\t-> " . $table->getPhpName() . "Node");
 182                                  $generator->parse("om/$targetPlatform/ExtensionNode.tpl", $path);
 183                              } else {
 184                                  $this->log("\t\t-> (exists) " . $table->getPhpName() . "Node");
 185                              }
 186                          }
 187  
 188                          // Create [empty] interface if it does not already exist
 189                          if ($table->getInterface()) {
 190                              $path = ClassTools::getFilePath($table->getInterface());
 191                              $_f = new PhingFile($basepath, $path);
 192                              if (!$_f->exists()) {
 193                              
 194                                  $_dir = new PhingFile(dirname($_f->getAbsolutePath()));
 195                                  $_dir->mkdirs();
 196                                  
 197                                  $this->log("\t\t-> " . $table->getInterface());
 198                                  $generator->parse("om/$targetPlatform/Interface.tpl", $path);
 199                                  
 200                              } else {
 201                                  $this->log("\t\t-> (exists) " . $table->getInterface());
 202                              }
 203                          }
 204  
 205                          // If table has enumerated children (uses inheritance) then create the empty child stub classes
 206                          // if they don't already exist.
 207                          if ($table->getChildrenColumn()) {
 208                              $col = $table->getChildrenColumn();
 209                              if ($col->isEnumeratedClasses()) {
 210                                  foreach ($col->getChildren() as $child) {
 211                                      $childpkg = ($child->getPackage() ? $child->getPackage() : $package);
 212                                      $generator->put("child", $child);
 213                                      $generator->put("package", $childpkg);
 214                                      $path = ClassTools::getFilePath($childpkg, $child->getClassName());
 215                                      $_f = new PhingFile($basepath, $path);
 216                                      if (!$_f->exists()) {
 217                                          $this->log("\t\t-> " . $child->getClassName());
 218                                          $generator->parse("om/$targetPlatform/MultiExtendObject.tpl", $path);
 219                                      } else {
 220                                          $this->log("\t\t-> (exists) " . $child->getClassName());
 221                                      }
 222                                  } // foreach
 223                              } // if col->is enumerated
 224                          } // if tbl->getChildrenCol
 225  
 226                      } // if !$table->isForReferenceOnly()
 227  
 228                  } // foreach table
 229  
 230              } // foreach database
 231  
 232          } // foreach dataModel
 233  
 234  
 235      } // main()
 236  }


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