[ 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/database/model/ -> ForeignKey.php (source)

   1  <?php
   2  /*
   3   *  $Id: ForeignKey.php 351 2006-03-15 18:42:34Z hans $
   4   *
   5   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   6   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   7   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   8   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   9   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16   *
  17   * This software consists of voluntary contributions made by many individuals
  18   * and is licensed under the LGPL. For more information please see
  19   * <http://propel.phpdb.org>.
  20   */
  21  
  22  require_once 'propel/engine/database/model/XMLElement.php';
  23  
  24  /**
  25   * A Class for information about foreign keys of a table.
  26   *
  27   * @author Hans Lellelid <hans@xmpl.org>
  28   * @author Fedor <fedor.karpelevitch@home.com>
  29   * @author Daniel Rall <dlr@finemaltcoding.com>
  30   * @version $Revision: 351 $
  31   * @package propel.engine.database.model
  32   */
  33  class ForeignKey extends XMLElement {
  34  
  35      private $foreignTableName;
  36      private $name;
  37      private $onUpdate;
  38      private $onDelete;
  39      private $parentTable;
  40      private $localColumns = array();
  41      private $foreignColumns = array();
  42  
  43      // the uppercase equivalent of the onDelete/onUpdate values in the dtd
  44      const NONE     = "";            // No "ON [ DELETE | UPDATE]" behaviour specified.
  45      const NOACTION  = "NO ACTION";
  46      const CASCADE  = "CASCADE";
  47      const RESTRICT = "RESTRICT";
  48      const SETDEFAULT  = "SET DEFAULT";
  49      const SETNULL  = "SET NULL";
  50  
  51      /**
  52       * Sets up the ForeignKey object based on the attributes that were passed to loadFromXML().
  53       * @see parent::loadFromXML()
  54       */
  55      protected function setupObject()
  56      {
  57          $this->foreignTableName = $this->getAttribute("foreignTable");
  58          $this->name = $this->getAttribute("name");
  59          $this->onUpdate = $this->normalizeFKey($this->getAttribute("onUpdate"));
  60          $this->onDelete = $this->normalizeFKey($this->getAttribute("onDelete"));
  61      }
  62  
  63      /**
  64       * normalizes the input of onDelete, onUpdate attributes
  65       */
  66      private function normalizeFKey($attrib)
  67      {
  68          if ($attrib === null  || strtoupper($attrib) == "NONE") {
  69              $attrib = self::NONE;
  70          }
  71          $attrib = strtoupper($attrib);
  72          if ($attrib == "SETNULL") {
  73              $attrib =  self::SETNULL;
  74          }
  75          return $attrib;
  76      }
  77  
  78      /**
  79       * returns whether or not the onUpdate attribute is set
  80       */
  81      public function hasOnUpdate()
  82      {
  83         return ($this->onUpdate !== self::NONE);
  84      }
  85  
  86      /**
  87       * returns whether or not the onDelete attribute is set
  88       */
  89      public function hasOnDelete()
  90      {
  91         return ($this->onDelete !== self::NONE);
  92      }
  93  
  94      /**
  95       * returns the onUpdate attribute
  96       */
  97      public function getOnUpdate()
  98      {
  99         return $this->onUpdate;
 100      }
 101  
 102      /**
 103       * returns the onDelete attribute
 104       */
 105      public function getOnDelete()
 106      {
 107         return $this->onDelete;
 108      }
 109  
 110      /**
 111       * sets the onDelete attribute
 112       */
 113      public function setOnDelete($value)
 114      {
 115         $this->onDelete = $this->normalizeFKey($value);
 116      }
 117  
 118      /**
 119       * sets the onUpdate attribute
 120       */
 121      public function setOnUpdate($value)
 122      {
 123         $this->onUpdate = $this->normalizeFKey($value);
 124      }
 125  
 126      /**
 127       * Returns the name attribute.
 128       */
 129      public function getName()
 130      {
 131          return $this->name;
 132      }
 133  
 134      /**
 135       * Sets the name attribute.
 136       */
 137      public function setName($name)
 138      {
 139          $this->name = $name;
 140      }
 141  
 142      /**
 143       * Get the foreignTableName of the FK
 144       */
 145      public function getForeignTableName()
 146      {
 147          return $this->foreignTableName;
 148      }
 149  
 150      /**
 151       * Set the foreignTableName of the FK
 152       */
 153      public function setForeignTableName($tableName)
 154      {
 155          $this->foreignTableName = $tableName;
 156      }
 157  
 158      /**
 159       * Set the parent Table of the foreign key
 160       */
 161      public function setTable(Table $parent)
 162      {
 163          $this->parentTable = $parent;
 164      }
 165  
 166      /**
 167       * Get the parent Table of the foreign key
 168       */
 169      public function getTable()
 170      {
 171          return $this->parentTable;
 172      }
 173  
 174      /**
 175       * Returns the Name of the table the foreign key is in
 176       */
 177      public function getTableName()
 178      {
 179          return $this->parentTable->getName();
 180      }
 181  
 182      /**
 183       * adds a new reference entry to the foreign key
 184       */
 185      public function addReference($p1, $p2 = null)
 186      {
 187          if (is_array($p1)) {
 188              $this->addReference(@$p1["local"], @$p1["foreign"]);
 189          } else {
 190              $this->localColumns[] = $p1;
 191              $this->foreignColumns[] = $p2;
 192          }
 193      }
 194  
 195      /**
 196       * Return a comma delimited string of local column names
 197       * @deprecated because Column::makeList() is deprecated; use the array-returning getLocalColumns() and DDLBuilder->getColumnList() instead instead.
 198       */
 199      public function getLocalColumnNames()
 200      {
 201          return Column::makeList($this->getLocalColumns(), $this->getTable()->getDatabase()->getPlatform());
 202      }
 203  
 204      /**
 205       * Return a comma delimited string of foreign column names
 206       * @deprecated because Column::makeList() is deprecated; use the array-returning getForeignColumns() and DDLBuilder->getColumnList() instead instead.
 207       */
 208      public function getForeignColumnNames()
 209      {
 210          return Column::makeList($this->getForeignColumns(), $this->getTable()->getDatabase()->getPlatform());
 211      }
 212  
 213      /**
 214       * Return an array of local column names.
 215       * @return array string[]
 216       */
 217      public function getLocalColumns()
 218      {
 219          return $this->localColumns;
 220      }
 221  
 222      /**
 223       * Utility method to get local column to foreign column
 224       * mapping for this foreign key.
 225       */
 226      public function getLocalForeignMapping()
 227      {
 228          $h = array();
 229          for ($i=0, $size=count($this->localColumns); $i < $size; $i++) {
 230              $h[$this->localColumns[$i]] = $this->foreignColumns[$i];
 231          }
 232          return $h;
 233      }
 234  
 235      /**
 236       * Return an array of foreign column names.
 237       * @return array string[]
 238       */
 239      public function getForeignColumns()
 240      {
 241          return $this->foreignColumns;
 242      }
 243  
 244      /**
 245       * Utility method to get local column to foreign column
 246       * mapping for this foreign key.
 247       */
 248      public function getForeignLocalMapping()
 249      {
 250          $h = array();
 251          for ($i=0, $size=count($this->localColumns); $i < $size; $i++) {
 252              $h[ $this->foreignColumns[$i] ] = $this->localColumns[$i];
 253          }
 254          return $h;
 255      }
 256  
 257      /**
 258       * String representation of the foreign key. This is an xml representation.
 259       */
 260      public function toString()
 261      {
 262          $result = "    <foreign-key foreignTable=\""
 263              . $this->getForeignTableName()
 264              . "\" name=\""
 265              . $this->getName()
 266              . "\">\n";
 267  
 268          for ($i=0, $size=count($this->localColumns); $i < $size; $i++) {
 269              $result .= "        <reference local=\""
 270                  . $this->localColumns[$i]
 271                  . "\" foreign=\""
 272                  . $this->foreignColumns[$i]
 273                  . "\"/>\n";
 274          }
 275          $result .= "    </foreign-key>\n";
 276          return $result;
 277      }
 278  }
 279  


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