PageRenderTime 37ms CodeModel.GetById 13ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/database/model/Column.php

https://bitbucket.org/ealexandru/jobeet
PHP | 1184 lines | 700 code | 119 blank | 365 comment | 71 complexity | 279cd90312bfcbc163f12ad7856f3228 MD5 | raw file
   1<?php
   2/*
   3 *  $Id: Column.php 1594 2010-03-15 09:16:23Z francois $
   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
  22require_once 'propel/engine/database/model/XMLElement.php';
  23include_once 'propel/engine/EngineException.php';
  24include_once 'propel/engine/database/model/PropelTypes.php';
  25include_once 'propel/engine/database/model/Inheritance.php';
  26include_once 'propel/engine/database/model/Domain.php';
  27include_once 'propel/engine/database/model/ColumnDefaultValue.php';
  28
  29/**
  30 * A Class for holding data about a column used in an Application.
  31 *
  32 * @author     Hans Lellelid <hans@xmpl.org> (Propel)
  33 * @author     Leon Messerschmidt <leon@opticode.co.za> (Torque)
  34 * @author     Jason van Zyl <jvanzyl@apache.org> (Torque)
  35 * @author     Jon S. Stevens <jon@latchkey.com> (Torque)
  36 * @author     Daniel Rall <dlr@finemaltcoding.com> (Torque)
  37 * @author     Byron Foster <byron_foster@yahoo.com> (Torque)
  38 * @author     Bernd Goldschmidt <bgoldschmidt@rapidsoft.de>
  39 * @version    $Revision: 1594 $
  40 * @package    propel.engine.database.model
  41 */
  42class Column extends XMLElement {
  43
  44  const DEFAULT_TYPE = "VARCHAR";
  45  const DEFAULT_VISIBILITY = 'public';
  46  public static $valid_visibilities = array('public', 'protected', 'private');
  47
  48  private $name;
  49  private $description;
  50  private $phpName = null;
  51  private $phpNamingMethod;
  52  private $isNotNull = false;
  53  private $size;
  54  private $namePrefix;
  55  private $accessorVisibility;
  56  private $mutatorVisibility;
  57
  58  /**
  59   * The name to use for the Peer constant that identifies this column.
  60   * (Will be converted to all-uppercase in the templates.)
  61   * @var        string
  62   */
  63  private $peerName;
  64
  65  /**
  66   * Native PHP type (scalar or class name)
  67   * @var        string "string", "boolean", "int", "double"
  68   */
  69  private $phpType;
  70
  71  /**
  72   * @var        Table
  73   */
  74  private $parentTable;
  75
  76  private $position;
  77  private $isPrimaryKey = false;
  78  private $isNodeKey = false;
  79  private $nodeKeySep;
  80  private $isNestedSetLeftKey = false;
  81  private $isNestedSetRightKey = false;
  82  private $isTreeScopeKey = false;
  83  private $isUnique = false;
  84  private $isAutoIncrement = false;
  85  private $isLazyLoad = false;
  86  private $defaultValue;
  87  private $referrers;
  88  private $isPrimaryString = false;
  89
  90  // only one type is supported currently, which assumes the
  91  // column either contains the classnames or a key to
  92  // classnames specified in the schema.  Others may be
  93  // supported later.
  94  private $inheritanceType;
  95  private $isInheritance;
  96  private $isEnumeratedClasses;
  97  private $inheritanceList;
  98  private $needsTransactionInPostgres; //maybe this can be retrieved from vendorSpecificInfo
  99
 100  /** class name to do input validation on this column */
 101  private $inputValidator = null;
 102
 103  /**
 104   * @var        Domain The domain object associated with this Column.
 105   */
 106  private $domain;
 107
 108  /**
 109   * Creates a new column and set the name
 110   *
 111   * @param      name column name
 112   */
 113  public function __construct($name = null)
 114  {
 115    $this->name = $name;
 116  }
 117
 118  /**
 119   * Return a comma delimited string listing the specified columns.
 120   *
 121   * @param      columns Either a list of <code>Column</code> objects, or
 122   * a list of <code>String</code> objects with column names.
 123   * @deprecated Use the DDLBuilder->getColumnList() method instead; this will be removed in 1.3
 124   */
 125  public static function makeList($columns, Platform $platform)
 126  {
 127    $list = array();
 128    foreach ($columns as $col) {
 129      if ($col instanceof Column) {
 130        $col = $col->getName();
 131      }
 132      $list[] = $platform->quoteIdentifier($col);
 133    }
 134    return implode(", ", $list);
 135  }
 136
 137  /**
 138   * Sets up the Column object based on the attributes that were passed to loadFromXML().
 139   * @see        parent::loadFromXML()
 140   */
 141  protected function setupObject()
 142  {
 143    try {
 144      $dom = $this->getAttribute("domain");
 145      if ($dom)  {
 146        $this->getDomain()->copy($this->getTable()->getDatabase()->getDomain($dom));
 147      } else {
 148        $type = strtoupper($this->getAttribute("type"));
 149        if ($type) {
 150          $this->getDomain()->copy($this->getPlatform()->getDomainForType($type));
 151        } else {
 152          $this->getDomain()->copy($this->getPlatform()->getDomainForType(self::DEFAULT_TYPE));
 153        }
 154      }
 155
 156      $this->name = $this->getAttribute("name");
 157      $this->phpName = $this->getAttribute("phpName");
 158      $this->phpType = $this->getAttribute("phpType");
 159
 160      if ($this->getAttribute("prefix", null) !== null) {
 161        $this->namePrefix = $this->getAttribute("prefix");
 162      } elseif ($this->getTable()->getAttribute('columnPrefix', null) !== null) {
 163        $this->namePrefix = $this->getTable()->getAttribute('columnPrefix');
 164      } else {
 165        $this->namePrefix = '';
 166      }
 167
 168      // Accessor visibility
 169      if ($this->getAttribute('accessorVisibility', null) !==  null) {
 170        $this->setAccessorVisibility($this->getAttribute('accessorVisibility'));
 171      } elseif ($this->getTable()->getAttribute('defaultAccessorVisibility', null) !== null) {
 172        $this->setAccessorVisibility($this->getTable()->getAttribute('defaultAccessorVisibility'));
 173      } elseif ($this->getTable()->getDatabase()->getAttribute('defaultAccessorVisibility', null) !== null) {
 174        $this->setAccessorVisibility($this->getTable()->getDatabase()->getAttribute('defaultAccessorVisibility'));
 175      } else {
 176        $this->setAccessorVisibility(self::DEFAULT_VISIBILITY);
 177      }
 178
 179      // Mutator visibility
 180      if ($this->getAttribute('mutatorVisibility', null) !==  null) {
 181        $this->setMutatorVisibility($this->getAttribute('mutatorVisibility'));
 182      } elseif ($this->getTable()->getAttribute('defaultMutatorVisibility', null) !== null) {
 183        $this->setMutatorVisibility($this->getTable()->getAttribute('defaultMutatorVisibility'));
 184      } elseif ($this->getTable()->getDatabase()->getAttribute('defaultMutatorVisibility', null) !== null) {
 185        $this->setMutatorVisibility($this->getTable()->getDatabase()->getAttribute('defaultMutatorVisibility'));
 186      } else {
 187        $this->setMutatorVisibility(self::DEFAULT_VISIBILITY);
 188      }
 189
 190      $this->peerName = $this->getAttribute("peerName");
 191
 192      // retrieves the method for converting from specified name to a PHP name, defaulting to parent tables default method
 193      $this->phpNamingMethod = $this->getAttribute("phpNamingMethod", $this->parentTable->getDatabase()->getDefaultPhpNamingMethod());
 194
 195      $this->isPrimaryString = $this->booleanValue($this->getAttribute("primaryString"));
 196      
 197      $this->isPrimaryKey = $this->booleanValue($this->getAttribute("primaryKey"));
 198
 199      $this->isNodeKey = $this->booleanValue($this->getAttribute("nodeKey"));
 200      $this->nodeKeySep = $this->getAttribute("nodeKeySep", ".");
 201
 202      $this->isNestedSetLeftKey = $this->booleanValue($this->getAttribute("nestedSetLeftKey"));
 203      $this->isNestedSetRightKey = $this->booleanValue($this->getAttribute("nestedSetRightKey"));
 204      $this->isTreeScopeKey = $this->booleanValue($this->getAttribute("treeScopeKey"));
 205
 206      $this->isNotNull = ($this->booleanValue($this->getAttribute("required"), false) || $this->isPrimaryKey); // primary keys are required
 207
 208      //AutoIncrement/Sequences
 209      $this->isAutoIncrement = $this->booleanValue($this->getAttribute("autoIncrement"));
 210      $this->isLazyLoad = $this->booleanValue($this->getAttribute("lazyLoad"));
 211
 212      // Add type, size information to associated Domain object
 213      $this->getDomain()->replaceSqlType($this->getAttribute("sqlType"));
 214      if (!$this->getAttribute("size") && $this->getDomain()->getType() == 'VARCHAR' && !$this->getAttribute("sqlType")) {
 215        $size = 255;
 216      } else {
 217        $size = $this->getAttribute("size");
 218      }
 219      $this->getDomain()->replaceSize($size);
 220      $this->getDomain()->replaceScale($this->getAttribute("scale"));
 221
 222      $defval = $this->getAttribute("defaultValue", $this->getAttribute("default"));
 223      if ($defval !== null && strtolower($defval) !== 'null') {
 224        $this->getDomain()->setDefaultValue(new ColumnDefaultValue($defval, ColumnDefaultValue::TYPE_VALUE));
 225      } elseif ($this->getAttribute("defaultExpr") !== null) {
 226        $this->getDomain()->setDefaultValue(new ColumnDefaultValue($this->getAttribute("defaultExpr"), ColumnDefaultValue::TYPE_EXPR));
 227      }
 228
 229      $this->inheritanceType = $this->getAttribute("inheritance");
 230      $this->isInheritance = ($this->inheritanceType !== null
 231      && $this->inheritanceType !== "false"); // here we are only checking for 'false', so don't
 232      // use boleanValue()
 233
 234      $this->inputValidator = $this->getAttribute("inputValidator");
 235      $this->description = $this->getAttribute("description");
 236    } catch (Exception $e) {
 237      throw new EngineException("Error setting up column " . var_export($this->getAttribute("name"), true) . ": " . $e->getMessage());
 238    }
 239  }
 240
 241  /**
 242   * Gets domain for this column, creating a new empty domain object if none is set.
 243   * @return     Domain
 244   */
 245  public function getDomain()
 246  {
 247    if ($this->domain === null) {
 248      $this->domain = new Domain();
 249    }
 250    return $this->domain;
 251  }
 252
 253  /**
 254   * Returns table.column
 255   */
 256  public function getFullyQualifiedName()
 257  {
 258    return ($this->parentTable->getName() . '.' . $this->getName());
 259  }
 260
 261  /**
 262   * Get the name of the column
 263   */
 264  public function getName()
 265  {
 266    return $this->name;
 267  }
 268
 269  /**
 270   * Set the name of the column
 271   */
 272  public function setName($newName)
 273  {
 274    $this->name = $newName;
 275  }
 276
 277  /**
 278   * Get the description for the Table
 279   */
 280  public function getDescription()
 281  {
 282    return $this->description;
 283  }
 284
 285  /**
 286   * Set the description for the Table
 287   *
 288   * @param      newDescription description for the Table
 289   */
 290  public function setDescription($newDescription)
 291  {
 292    $this->description = $newDescription;
 293  }
 294
 295  /**
 296   * Get name to use in PHP sources. It will set & return
 297   * a self-generated phpName from it's name if it's
 298   * not already set.
 299   * @return     string
 300   */
 301  public function getPhpName()
 302  {
 303    if ($this->phpName === null) {
 304      $this->setPhpName();
 305    }
 306    return $this->phpName;
 307  }
 308
 309  /**
 310   * Set name to use in PHP sources.
 311   * 
 312   * It will generate a phpName from it's name if no
 313   * $phpName is passed.
 314   * 
 315   * @param   String $phpName PhpName to be set
 316   */
 317  public function setPhpName($phpName = null)
 318  {
 319    if ($phpName == null) {
 320      $this->phpName = self::generatePhpName($this->name, $this->phpNamingMethod, $this->namePrefix);
 321    } else {
 322      $this->phpName = $phpName;
 323    }
 324  }
 325
 326  /**
 327   * Get studly version of PHP name.
 328   *
 329   * The studly name is the PHP name with the first character lowercase.
 330   *
 331   * @return     string
 332   */
 333  public function getStudlyPhpName()
 334  {
 335    $phpname = $this->getPhpName();
 336    if (strlen($phpname) > 1) {
 337      return strtolower(substr($phpname, 0, 1)) . substr($phpname, 1);
 338    } else { // 0 or 1 chars (I suppose that's rare)
 339      return strtolower($phpname);
 340    }
 341  }
 342
 343  /**
 344   * Get the visibility of the accessors of this column / attribute
 345   * @return     string
 346   */
 347  public function getAccessorVisibility() {
 348    if ($this->accessorVisibility !== null) {
 349      return $this->accessorVisibility;
 350    } else {
 351      return self::DEFAULT_VISIBILITY;
 352    }
 353  }
 354
 355  /**
 356   * Set the visibility of the accessor methods for this column / attribute
 357   * @param      $newVisibility string
 358   */
 359  public function setAccessorVisibility($newVisibility) {
 360    if (in_array($newVisibility, self::$valid_visibilities)) {
 361      $this->accessorVisibility = $newVisibility;
 362    } else {
 363      $this->accessorVisibility = self::DEFAULT_VISIBILITY;
 364    }
 365
 366  }
 367
 368  /**
 369   * Get the visibility of the mutator of this column / attribute
 370   * @return     string
 371   */
 372  public function getMutatorVisibility() {
 373    if ($this->mutatorVisibility !== null) {
 374      return $this->mutatorVisibility;
 375    } else {
 376      return self::DEFAULT_VISIBILITY;
 377    }
 378  }
 379
 380  /**
 381   * Set the visibility of the mutator methods for this column / attribute
 382   * @param      $newVisibility string
 383   */
 384  public function setMutatorVisibility($newVisibility) {
 385    if (in_array($newVisibility, self::$valid_visibilities)) {
 386      $this->mutatorVisibility = $newVisibility;
 387    } else {
 388      $this->mutatorVisibility = self::DEFAULT_VISIBILITY;
 389    }
 390
 391  }
 392
 393  /**
 394   * Get the column constant name (e.g. PeerName::COLUMN_NAME).
 395   *
 396   * @return     string A column constant name for insertion into PHP code
 397   */
 398  public function getConstantName()
 399  {
 400    $classname = $this->getTable()->getPhpName() . 'Peer';
 401    // was it overridden in schema.xml ?
 402    if ($this->getPeerName()) {
 403      $const = strtoupper($this->getPeerName());
 404    } else {
 405      $const = strtoupper($this->getName());
 406    }
 407    return $classname.'::'.$const;
 408  }
 409
 410  /**
 411   * Get the Peer constant name that will identify this column.
 412   * @return     string
 413   */
 414  public function getPeerName() {
 415    return $this->peerName;
 416  }
 417
 418  /**
 419   * Set the Peer constant name that will identify this column.
 420   * @param      $name string
 421   */
 422  public function setPeerName($name) {
 423    $this->peerName = $name;
 424  }
 425
 426  /**
 427   * Get type to use in PHP sources.
 428   *
 429   * If no type has been specified, then uses results of getPhpNative().
 430   *
 431   * @return     string The type name.
 432   * @see        getPhpNative()
 433   */
 434  public function getPhpType()
 435  {
 436    if ($this->phpType !== null) {
 437      return $this->phpType;
 438    }
 439    return $this->getPhpNative();
 440  }
 441
 442  /**
 443   * Get the location of this column within the table (one-based).
 444   * @return     int value of position.
 445   */
 446  public function getPosition()
 447  {
 448    return $this->position;
 449  }
 450
 451  /**
 452   * Get the location of this column within the table (one-based).
 453   * @param      int $v Value to assign to position.
 454   */
 455  public function setPosition($v)
 456  {
 457    $this->position = $v;
 458  }
 459
 460  /**
 461   * Set the parent Table of the column
 462   */
 463  public function setTable(Table $parent)
 464  {
 465    $this->parentTable = $parent;
 466  }
 467
 468  /**
 469   * Get the parent Table of the column
 470   */
 471  public function getTable()
 472  {
 473    return $this->parentTable;
 474  }
 475
 476  /**
 477   * Returns the Name of the table the column is in
 478   */
 479  public function getTableName()
 480  {
 481    return $this->parentTable->getName();
 482  }
 483
 484  /**
 485   * Adds a new inheritance definition to the inheritance list and set the
 486   * parent column of the inheritance to the current column
 487   * @param      mixed $inhdata Inheritance or XML data.
 488   */
 489  public function addInheritance($inhdata)
 490  {
 491    if ($inhdata instanceof Inheritance) {
 492      $inh = $inhdata;
 493      $inh->setColumn($this);
 494      if ($this->inheritanceList === null) {
 495        $this->inheritanceList = array();
 496        $this->isEnumeratedClasses = true;
 497      }
 498      $this->inheritanceList[] = $inh;
 499      return $inh;
 500    } else {
 501      $inh = new Inheritance();
 502      $inh->loadFromXML($inhdata);
 503      return $this->addInheritance($inh);
 504    }
 505  }
 506
 507  /**
 508   * Get the inheritance definitions.
 509   */
 510  public function getChildren()
 511  {
 512    return $this->inheritanceList;
 513  }
 514
 515  /**
 516   * Determine if this column is a normal property or specifies a
 517   * the classes that are represented in the table containing this column.
 518   */
 519  public function isInheritance()
 520  {
 521    return $this->isInheritance;
 522  }
 523
 524  /**
 525   * Determine if possible classes have been enumerated in the xml file.
 526   */
 527  public function isEnumeratedClasses()
 528  {
 529    return $this->isEnumeratedClasses;
 530  }
 531
 532  /**
 533   * Return the isNotNull property of the column
 534   */
 535  public function isNotNull()
 536  {
 537    return $this->isNotNull;
 538  }
 539
 540  /**
 541   * Set the isNotNull property of the column
 542   */
 543  public function setNotNull($status)
 544  {
 545    $this->isNotNull = (boolean) $status;
 546  }
 547
 548  /**
 549   * Return NOT NULL String for this column
 550   *
 551   * @return     "NOT NULL" if null values are not allowed or an empty string.
 552   */
 553  public function getNotNullString()
 554  {
 555    return $this->getTable()->getDatabase()->getPlatform()->getNullString($this->isNotNull());
 556  }
 557
 558  /**
 559   * Set whether the column is the primary string, 
 560   * i.e. whether its value is the default string representation of the table
 561   * @param      boolean $v
 562   */
 563  public function setPrimaryString($v)
 564  {
 565    $this->isPrimaryString = (boolean) $v;
 566  }
 567
 568  /**
 569   * Return true if the column is the primary string,
 570   * i.e. if its value is the default string representation of the table
 571   */
 572  public function isPrimaryString()
 573  {
 574    return $this->isPrimaryString;
 575  }
 576
 577  /**
 578   * Set whether the column is a primary key or not.
 579   * @param      boolean $v
 580   */
 581  public function setPrimaryKey($v)
 582  {
 583    $this->isPrimaryKey = (boolean) $v;
 584  }
 585
 586  /**
 587   * Return true if the column is a primary key
 588   */
 589  public function isPrimaryKey()
 590  {
 591    return $this->isPrimaryKey;
 592  }
 593
 594  /**
 595   * Set if the column is the node key of a tree
 596   */
 597  public function setNodeKey($nk)
 598  {
 599    $this->isNodeKey = (boolean) $nk;
 600  }
 601
 602  /**
 603   * Return true if the column is a node key of a tree
 604   */
 605  public function isNodeKey()
 606  {
 607    return $this->isNodeKey;
 608  }
 609
 610  /**
 611   * Set if the column is the node key of a tree
 612   */
 613  public function setNodeKeySep($sep)
 614  {
 615    $this->nodeKeySep = (string) $sep;
 616  }
 617
 618  /**
 619   * Return true if the column is a node key of a tree
 620   */
 621  public function getNodeKeySep()
 622  {
 623    return $this->nodeKeySep;
 624  }
 625
 626  /**
 627   * Set if the column is the nested set left key of a tree
 628   */
 629  public function setNestedSetLeftKey($nslk)
 630  {
 631    $this->isNestedSetLeftKey = (boolean) $nslk;
 632  }
 633
 634  /**
 635   * Return true if the column is a nested set key of a tree
 636   */
 637  public function isNestedSetLeftKey()
 638  {
 639    return $this->isNestedSetLeftKey;
 640  }
 641
 642  /**
 643   * Set if the column is the nested set right key of a tree
 644   */
 645  public function setNestedSetRightKey($nsrk)
 646  {
 647    $this->isNestedSetRightKey = (boolean) $nsrk;
 648  }
 649
 650  /**
 651   * Return true if the column is a nested set right key of a tree
 652   */
 653  public function isNestedSetRightKey()
 654  {
 655    return $this->isNestedSetRightKey;
 656  }
 657
 658  /**
 659   * Set if the column is the scope key of a tree
 660   */
 661  public function setTreeScopeKey($tsk)
 662  {
 663    $this->isTreeScopeKey = (boolean) $tsk;
 664  }
 665
 666  /**
 667   * Return true if the column is a scope key of a tree
 668   * @return     boolean
 669   */
 670  public function isTreeScopeKey()
 671  {
 672    return $this->isTreeScopeKey;
 673  }
 674
 675  /**
 676   * Set true if the column is UNIQUE
 677   * @param      boolean $u
 678   */
 679  public function setUnique($u)
 680  {
 681    $this->isUnique = $u;
 682  }
 683
 684  /**
 685   * Get the UNIQUE property.
 686   * @return     boolean
 687   */
 688  public function isUnique()
 689  {
 690    return $this->isUnique;
 691  }
 692
 693  /**
 694   * Return true if the column requires a transaction in Postgres
 695   * @return     boolean
 696   */
 697  public function requiresTransactionInPostgres()
 698  {
 699    return $this->needsTransactionInPostgres;
 700  }
 701
 702  /**
 703   * Utility method to determine if this column is a foreign key.
 704   * @return     boolean
 705   */
 706  public function isForeignKey()
 707  {
 708    return (count($this->getForeignKeys()) > 0);
 709  }
 710
 711  /**
 712   * Whether this column is a part of more than one foreign key.
 713   * @return     boolean
 714   */
 715  public function hasMultipleFK()
 716  {
 717    return (count($this->getForeignKeys()) > 1);
 718  }
 719
 720  /**
 721   * Get the foreign key objects for this column (if it is a foreign key or part of a foreign key)
 722   * @return     array
 723   */
 724  public function getForeignKeys()
 725  {
 726    return $this->parentTable->getColumnForeignKeys($this->name);
 727  }
 728
 729  /**
 730   * Adds the foreign key from another table that refers to this column.
 731   */
 732  public function addReferrer(ForeignKey $fk)
 733  {
 734    if ($this->referrers === null) {
 735      $this->referrers = array();
 736    }
 737    $this->referrers[] = $fk;
 738  }
 739
 740  /**
 741   * Get list of references to this column.
 742   */
 743  public function getReferrers()
 744  {
 745    if ($this->referrers === null) {
 746      $this->referrers = array();
 747    }
 748    return $this->referrers;
 749  }
 750
 751  /**
 752   * Sets the domain up for specified Propel type.
 753   *
 754   * Calling this method will implicitly overwrite any previously set type,
 755   * size, scale (or other domain attributes).
 756   *
 757   * @param      string $propelType
 758   */
 759  public function setDomainForType($propelType)
 760  {
 761    $this->getDomain()->copy($this->getPlatform()->getDomainForType($propelType));
 762  }
 763
 764  /**
 765   * Sets the propel colunm type.
 766   * @param      string $propelType
 767   * @see        Domain::setType()
 768   */
 769  public function setType($propelType)
 770  {
 771    $this->getDomain()->setType($propelType);
 772    if ($propelType == PropelTypes::VARBINARY|| $propelType == PropelTypes::LONGVARBINARY || $propelType == PropelTypes::BLOB) {
 773      $this->needsTransactionInPostgres = true;
 774    }
 775  }
 776
 777  /**
 778   * Returns the Propel column type as a string.
 779   * @return     string The constant representing Creole type: e.g. "VARCHAR".
 780   * @see        Domain::getType()
 781   */
 782  public function getType()
 783  {
 784    return $this->getDomain()->getType();
 785  }
 786
 787  /**
 788   * Returns the column PDO type integer for this column's Propel type.
 789   * @return     int The integer value representing PDO type param: e.g. PDO::PARAM_INT
 790   */
 791  public function getPDOType()
 792  {
 793    return PropelTypes::getPDOType($this->getType());
 794  }
 795
 796  /**
 797   * Returns the column type as given in the schema as an object
 798   */
 799  public function getPropelType()
 800  {
 801    return $this->getType();
 802  }
 803
 804  /**
 805   * Utility method to know whether column needs Blob/Lob handling.
 806   * @return     boolean
 807   */
 808  public function isLobType()
 809  {
 810    return PropelTypes::isLobType($this->getType());
 811  }
 812
 813  /**
 814   * Utility method to see if the column is text type.
 815   */
 816  public function isTextType()
 817  {
 818    return PropelTypes::isTextType($this->getType());
 819  }
 820
 821  /**
 822   * Utility method to see if the column is numeric type.
 823   * @return     boolean
 824   */
 825  public function isNumericType()
 826  {
 827    return PropelTypes::isNumericType($this->getType());
 828  }
 829
 830  /**
 831   * Utility method to know whether column is a temporal column.
 832   * @return     boolean
 833   */
 834  public function isTemporalType()
 835  {
 836    return PropelTypes::isTemporalType($this->getType());
 837  }
 838
 839  /**
 840   * @see        XMLElement::appendXml(DOMNode)
 841   */
 842  public function appendXml(DOMNode $node)
 843  {
 844    $doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
 845
 846    $colNode = $node->appendChild($doc->createElement('column'));
 847    $colNode->setAttribute('name', $this->name);
 848
 849    if ($this->phpName !== null) {
 850      $colNode->setAttribute('phpName', $this->getPhpName());
 851    }
 852
 853    $colNode->setAttribute('type', $this->getType());
 854
 855    $domain = $this->getDomain();
 856
 857    if ($domain->getSize() !== null) {
 858      $colNode->setAttribute('size', $domain->getSize());
 859    }
 860
 861    if ($domain->getScale() !== null) {
 862      $colNode->setAttribute('scale', $domain->getScale());
 863    }
 864
 865    if ($this->isPrimaryKey) {
 866      $colNode->setAttribute('primaryKey', var_export($this->isPrimaryKey, true));
 867    }
 868
 869    if ($this->isAutoIncrement) {
 870      $colNode->setAttribute('autoIncrement', var_export($this->isAutoIncrement, true));
 871    }
 872
 873    if ($this->isNotNull) {
 874      $colNode->setAttribute('required', 'true');
 875    } else {
 876      $colNode->setAttribute('required', 'false');
 877    }
 878
 879    if ($domain->getDefaultValue() !== null) {
 880      $def = $domain->getDefaultValue();
 881      if ($def->isExpression()) {
 882        $colNode->setAttribute('defaultExpr', $def->getValue());
 883      } else {
 884        $colNode->setAttribute('defaultValue', $def->getValue());
 885      }
 886    }
 887
 888    if ($this->isInheritance()) {
 889      $colNode->setAttribute('inheritance', $this->inheritanceType);
 890      foreach ($this->inheritanceList as $inheritance) {
 891        $inheritance->appendXml($colNode);
 892      }
 893    }
 894
 895    if ($this->isNodeKey()) {
 896      $colNode->setAttribute('nodeKey', 'true');
 897      if ($this->getNodeKeySep() !== null) {
 898        $colNode->setAttribute('nodeKeySep', $this->nodeKeySep);
 899      }
 900    }
 901
 902    foreach ($this->vendorInfos as $vi) {
 903      $vi->appendXml($colNode);
 904    }
 905  }
 906
 907  /**
 908   * Returns the size of the column
 909   * @return     string
 910   */
 911  public function getSize()
 912  {
 913    return $this->domain->getSize();
 914  }
 915
 916  /**
 917   * Set the size of the column
 918   * @param      string $newSize
 919   */
 920  public function setSize($newSize)
 921  {
 922    $this->domain->setSize($newSize);
 923  }
 924
 925  /**
 926   * Returns the scale of the column
 927   * @return     string
 928   */
 929  public function getScale()
 930  {
 931    return $this->domain->getScale();
 932  }
 933
 934  /**
 935   * Set the scale of the column
 936   * @param      string $newScale
 937   */
 938  public function setScale($newScale)
 939  {
 940    $this->domain->setScale($newScale);
 941  }
 942
 943  /**
 944   * Return the size in brackets for use in an sql
 945   * schema if the type is String.  Otherwise return an empty string
 946   */
 947  public function printSize()
 948  {
 949    return $this->domain->printSize();
 950  }
 951
 952  /**
 953   * Return a string that will give this column a default value.
 954   * @return     string
 955   */
 956  public function getDefaultSetting()
 957  {
 958    $dflt = "";
 959    $defaultValue = $this->getDefaultValue();
 960    if ($defaultValue !== null) {
 961      $dflt .= "default ";
 962
 963      if ($this->getDefaultValue()->isExpression()) {
 964        $dflt .= $this->getDefaultValue()->getValue();
 965      } else {
 966        if ($this->isTextType()) {
 967          $dflt .= $this->getPlatform()->quote($defaultValue->getValue());
 968        } elseif ($this->getType() == PropelTypes::BOOLEAN) {
 969          $dflt .= $this->getPlatform()->getBooleanString($defaultValue->getValue());
 970        } else {
 971          $dflt .= $defaultValue->getValue();
 972        }
 973      }
 974    }
 975    return $dflt;
 976  }
 977
 978  /**
 979   * Return a string that will give this column a default value in PHP
 980   * @return     string
 981   */
 982  public function getDefaultValueString()
 983  {
 984    $defaultValue = $this->getDefaultValue();
 985    if ($defaultValue !== null) {
 986      if ($this->isNumericType()) {
 987        $dflt = (float) $defaultValue->getValue();
 988      } elseif ($this->isTextType() || $this->getDefaultValue()->isExpression()) {
 989        $dflt = "'" . str_replace("'", "\'", $defaultValue->getValue()) . "'";
 990      } elseif ($this->getType() == PropelTypes::BOOLEAN) {
 991        $dflt = $this->booleanValue($defaultValue->getValue()) ? 'true' : 'false';
 992      } else {
 993        $dflt = "'" . $defaultValue->getValue() . "'";
 994      }
 995    } else {
 996      $dflt = "null";
 997    }
 998    return $dflt;
 999  }
1000  
1001  /**
1002   * Set a string that will give this column a default value.
1003   */
1004  public function setDefaultValue($def)
1005  {
1006    $this->domain->setDefaultValue($def);
1007  }
1008
1009  /**
1010   * Get the default value object for this column.
1011   * @return     ColumnDefaultValue
1012   * @see        Domain::getDefaultValue()
1013   */
1014  public function getDefaultValue()
1015  {
1016    return $this->domain->getDefaultValue();
1017  }
1018
1019  /**
1020   * Get the default value suitable for use in PHP.
1021   * @return     mixed
1022   * @see        Domain::getPhpDefaultValue()
1023   */
1024  public function getPhpDefaultValue()
1025  {
1026    return $this->domain->getPhpDefaultValue();
1027  }
1028
1029  /**
1030   * Returns the class name to do input validation
1031   */
1032  public function getInputValidator()
1033  {
1034    return $this->inputValidator;
1035  }
1036
1037  /**
1038   * Return auto increment/sequence string for the target database. We need to
1039   * pass in the props for the target database!
1040   */
1041  public function isAutoIncrement()
1042  {
1043    return $this->isAutoIncrement;
1044  }
1045
1046  /**
1047   * Return auto increment/sequence string for the target database. We need to
1048   * pass in the props for the target database!
1049   */
1050  public function isLazyLoad()
1051  {
1052    return $this->isLazyLoad;
1053  }
1054
1055  /**
1056   * Gets the auto-increment string.
1057   * @return     string
1058   */
1059  public function getAutoIncrementString()
1060  {
1061    if ($this->isAutoIncrement()&& IDMethod::NATIVE === $this->getTable()->getIdMethod()) {
1062      return $this->getPlatform()->getAutoIncrement();
1063    } elseif ($this->isAutoIncrement()) {
1064      throw new EngineException("You have specified autoIncrement for column '" . $this->name . "' but you have not specified idMethod=\"native\" for table '" . $this->getTable()->getName() . "'.");
1065    }
1066    return "";
1067  }
1068
1069  /**
1070   * Set the auto increment value.
1071   * Use isAutoIncrement() to find out if it is set or not.
1072   */
1073  public function setAutoIncrement($value)
1074  {
1075    $this->isAutoIncrement = (boolean) $value;
1076  }
1077
1078  /**
1079   * Set the column type from a string property
1080   * (normally a string from an sql input file)
1081   *
1082   * @deprecated Do not use; this will be removed in next release.
1083   */
1084  public function setTypeFromString($typeName, $size)
1085  {
1086    $tn = strtoupper($typeName);
1087    $this->setType($tn);
1088
1089    if ($size !== null) {
1090      $this->size = $size;
1091    }
1092
1093    if (strpos($tn, "CHAR") !== false) {
1094      $this->domain->setType(PropelTypes::VARCHAR);
1095    } elseif (strpos($tn, "INT") !== false) {
1096      $this->domain->setType(PropelTypes::INTEGER);
1097    } elseif (strpos($tn, "FLOAT") !== false) {
1098      $this->domain->setType(PropelTypes::FLOAT);
1099    } elseif (strpos($tn, "DATE") !== false) {
1100      $this->domain->setType(PropelTypes::DATE);
1101    } elseif (strpos($tn, "TIME") !== false) {
1102      $this->domain->setType(PropelTypes::TIMESTAMP);
1103    } else if (strpos($tn, "BINARY") !== false) {
1104      $this->domain->setType(PropelTypes::LONGVARBINARY);
1105    } else {
1106      $this->domain->setType(PropelTypes::VARCHAR);
1107    }
1108  }
1109
1110  /**
1111   * Return a string representation of the native PHP type which corresponds
1112   * to the propel type of this column. Use in the generation of Base objects.
1113   *
1114   * @return     string PHP datatype used by propel.
1115   */
1116  public function getPhpNative()
1117  {
1118    return PropelTypes::getPhpNative($this->getType());
1119  }
1120
1121  /**
1122   * Returns true if the column's PHP native type is an boolean, int, long, float, double, string.
1123   * @return     boolean
1124   * @see        PropelTypes::isPhpPrimitiveType()
1125   */
1126  public function isPhpPrimitiveType()
1127  {
1128    return PropelTypes::isPhpPrimitiveType($this->getPhpType());
1129  }
1130
1131  /**
1132   * Return true if column's PHP native type is an boolean, int, long, float, double.
1133   * @return     boolean
1134   * @see        PropelTypes::isPhpPrimitiveNumericType()
1135   */
1136  public function isPhpPrimitiveNumericType()
1137  {
1138    return PropelTypes::isPhpPrimitiveNumericType($this->getPhpType());
1139  }
1140
1141  /**
1142   * Returns true if the column's PHP native type is a class name.
1143   * @return     boolean
1144   * @see        PropelTypes::isPhpObjectType()
1145   */
1146  public function isPhpObjectType()
1147  {
1148    return PropelTypes::isPhpObjectType($this->getPhpType());
1149  }
1150
1151  /**
1152   * Get the platform/adapter impl.
1153   *
1154   * @return     Platform
1155   */
1156  public function getPlatform()
1157  {
1158    return $this->getTable()->getDatabase()->getPlatform();
1159  }
1160
1161  /**
1162   *
1163   * @return     string
1164   * @deprecated Use DDLBuilder->getColumnDDL() instead; this will be removed in 1.3
1165   */
1166  public function getSqlString()
1167  {
1168    $sb = "";
1169    $sb .= $this->getPlatform()->quoteIdentifier($this->getName()) . " ";
1170    $sb .= $this->getDomain()->getSqlType();
1171    if ($this->getPlatform()->hasSize($this->getDomain()->getSqlType())) {
1172      $sb .= $this->getDomain()->printSize();
1173    }
1174    $sb .= " ";
1175    $sb .= $this->getDefaultSetting() . " ";
1176    $sb .= $this->getNotNullString() . " ";
1177    $sb .= $this->getAutoIncrementString();
1178    return trim($sb);
1179  }
1180  
1181  public static function generatePhpName($name, $phpNamingMethod = PhpNameGenerator::CONV_METHOD_CLEAN, $namePrefix = null) {
1182    return NameFactory::generateName(NameFactory::PHP_GENERATOR, array($name, $phpNamingMethod, $namePrefix));
1183  }
1184}