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

   1  <?php
   2  
   3  /*
   4   *  $Id: PropelGraphvizTask.php 350 2006-03-15 17:24:56Z 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  include_once 'propel/engine/database/model/AppData.php';
  24  //require_once 'phing/Task.php';
  25  
  26  /**
  27   * A task to generate Graphviz png images from propel datamodel.
  28   *
  29   * @author Mark Kimsal
  30   * @version $Revision: 350 $
  31   * @package propel.phing
  32   */
  33  class PropelGraphvizTask extends AbstractPropelDataModelTask {
  34  
  35      /**
  36       * The properties file that maps an SQL file to a particular database.
  37       * @var PhingFile
  38       */
  39      private $sqldbmap;
  40  
  41      /**
  42       * Name of the database.
  43       */
  44      private $database;
  45  
  46      /**
  47       * Name of the output directory.
  48       */
  49      private $outDir;
  50  
  51  
  52      /**
  53       * Set the sqldbmap.
  54       * @param PhingFile $sqldbmap The db map.
  55       */
  56      public function setOutputDirectory(PhingFile $out)
  57      {
  58          if (!$out->exists()) {
  59              $out->mkdirs();
  60          }
  61          $this->outDir = $out;
  62      }
  63  
  64  
  65      /**
  66       * Set the sqldbmap.
  67       * @param PhingFile $sqldbmap The db map.
  68       */
  69      public function setSqlDbMap(PhingFile $sqldbmap)
  70      {
  71          $this->sqldbmap = $sqldbmap;
  72      }
  73  
  74      /**
  75       * Get the sqldbmap.
  76       * @return PhingFile $sqldbmap.
  77       */
  78      public function getSqlDbMap()
  79      {
  80          return $this->sqldbmap;
  81      }
  82  
  83      /**
  84       * Set the database name.
  85       * @param string $database
  86       */
  87      public function setDatabase($database)
  88      {
  89          $this->database = $database;
  90      }
  91  
  92      /**
  93       * Get the database name.
  94       * @return string
  95       */
  96      public function getDatabase()
  97      {
  98          return $this->database;
  99      }
 100  
 101  
 102      public function main()
 103      {
 104  
 105          $count = 0;
 106  
 107          $dotSyntax = '';
 108  
 109          // file we are going to create
 110  
 111          $dbMaps = $this->getDataModelDbMap();
 112  
 113          foreach ($this->getDataModels() as $dataModel) {
 114  
 115              $dotSyntax .= "digraph G {\n";
 116              foreach ($dataModel->getDatabases() as $database) {
 117  
 118                  $this->log("db: " . $database->getName());
 119  
 120                  //print the tables
 121                  foreach($database->getTables() as $tbl) {
 122  
 123                      $this->log("\t+ " . $tbl->getName());
 124  
 125                      ++$count;
 126                      $dotSyntax .= 'node'.$tbl->getName().' [label="{<table>'.$tbl->getName().'|<cols>';
 127  
 128                      foreach ($tbl->getColumns() as $col) {
 129                          $dotSyntax .= $col->getName() . ' (' . $col->getType()  . ')';
 130                          if ($col->getForeignKey() != null ) {
 131                              $dotSyntax .= ' [FK]';
 132                          } elseif ($col->isPrimaryKey()) {
 133                              $dotSyntax .= ' [PK]';
 134                          }
 135                          $dotSyntax .= '\l';
 136                      }
 137                      $dotSyntax .= '}", shape=record];';
 138                      $dotSyntax .= "\n";
 139                  }
 140  
 141                  //print the relations
 142  
 143                  $count = 0;
 144                  $dotSyntax .= "\n";
 145                  foreach($database->getTables() as $tbl) {
 146                      ++$count;
 147  
 148                      foreach ($tbl->getColumns() as $col) {
 149                          $fk = $col->getForeignKey();
 150                          if ( $fk == null ) continue;
 151                          $dotSyntax .= 'node'.$tbl->getName() .':cols -> node'.$fk->getForeignTableName() . ':table [label="' . $col->getName() . '=' . implode(',', $fk->getForeignColumns()) . ' "];';
 152                          $dotSyntax .= "\n";
 153                      }
 154                  }
 155  
 156  
 157  
 158              } // foreach database
 159              $dotSyntax .= "}\n";
 160  
 161              $this->writeDot($dotSyntax,$this->outDir);
 162  
 163          } //foreach datamodels
 164  
 165      } // main()
 166  
 167  
 168      /**
 169       * probably insecure
 170       */
 171      function writeDot($dotSyntax, PhingFile $outputDir) {
 172          $file = new PhingFile($outputDir, 'schema.dot');
 173          $this->log("Writing dot file to " . $file->getAbsolutePath());
 174          file_put_contents($file->getAbsolutePath(), $dotSyntax);
 175      }
 176  
 177  }


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