[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/propel/map/ -> ColumnMap.php (source)

   1  <?php
   2  
   3  /*
   4   *  $Id: ColumnMap.php 272 2005-11-08 15:02:48Z 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/map/ValidatorMap.php';
  24  
  25  /**
  26   * ColumnMap is used to model a column of a table in a database.
  27   * 
  28   * GENERAL NOTE
  29   * ------------
  30   * The propel.map classes are abstract building-block classes for modeling
  31   * the database at runtime.  These classes are similar (a lite version) to the
  32   * propel.engine.database.model classes, which are build-time modeling classes.
  33   * These classes in themselves do not do any database metadata lookups, but instead 
  34   * are used by the MapBuilder classes that were generated for your datamodel. The 
  35   * MapBuilder that was created for your datamodel build a representation of your
  36   * database by creating instances of the DatabaseMap, TableMap, ColumnMap, etc. 
  37   * classes. See propel/templates/om/php5/MapBuilder.tpl and the classes generated
  38   * by that template for your datamodel to further understand how these are put 
  39   * together.
  40   * 
  41   * @author Hans Lellelid <hans@xmpl.org> (Propel)
  42   * @author John D. McNally <jmcnally@collab.net> (Torque)
  43   * @version $Revision: 272 $
  44   * @package propel.map
  45   */
  46  class ColumnMap {
  47  
  48      /** @var int Creole type for this column. */
  49      private $creoleType;
  50      
  51      /** @var string Native PHP type of the column. */
  52      private $type = null;
  53  
  54      /** Size of the column. */
  55      private $size = 0;
  56  
  57      /** Is it a primary key? */
  58      private $pk = false;
  59  
  60      /** Is null value allowed ?*/
  61      private $notNull = false;
  62  
  63      /** Name of the table that this column is related to. */
  64      private $relatedTableName = "";
  65  
  66      /** Name of the column that this column is related to. */
  67      private $relatedColumnName = "";
  68  
  69      /** The TableMap for this column. */
  70      private $table;
  71  
  72      /** The name of the column. */
  73      private $columnName;
  74  
  75      /** The php name of the column. */
  76      private $phpName;
  77  
  78      /** validators for this column */
  79      private $validators = array();
  80      
  81      /**
  82       * Constructor.
  83       *
  84       * @param string $name The name of the column.
  85       * @param TableMap containingTable TableMap of the table this column is in.
  86       */
  87      public function __construct($name, TableMap $containingTable)
  88      {
  89          $this->columnName = $name;
  90          $this->table = $containingTable;
  91      }
  92  
  93      /**
  94       * Get the name of a column.
  95       *
  96       * @return string A String with the column name.
  97       */
  98      public function getColumnName()
  99      {
 100          return $this->columnName;
 101      }
 102  
 103      /**
 104       * Set the php anme of this column.
 105       *
 106       * @param string $phpName A string representing the PHP name.
 107       * @return void
 108       */
 109      public function setPhpName($phpName)
 110      {
 111          $this->phpName = $phpName;
 112      }
 113  
 114      /**
 115       * Get the name of a column.
 116       *
 117       * @return string A String with the column name.
 118       */
 119      public function getPhpName()
 120      {
 121          return $this->phpName;
 122      }
 123  
 124      /**
 125       * Get the table name + column name.
 126       *
 127       * @return string A String with the full column name.
 128       */
 129      public function getFullyQualifiedName()
 130      {
 131          return $this->table->getName() . "." . $this->columnName;
 132      }
 133  
 134      /**
 135       * Get the table map this column belongs to.
 136       * @return TableMap
 137       */
 138      public function getTable()
 139      {
 140          return $this->table;
 141      }
 142  
 143      /**
 144       * Get the name of the table this column is in.
 145       *
 146       * @return string A String with the table name.
 147       */
 148      public function getTableName()
 149      {
 150          return $this->table->getName();
 151      }
 152  
 153      /**
 154       * Set the type of this column.
 155       *
 156       * @param string $type A string representing the PHP native type.
 157       * @return void
 158       */
 159      public function setType($type)
 160      {
 161          $this->type = $type;
 162      }
 163  
 164       /**
 165       * Set the Creole type of this column.
 166       *
 167       * @param int $type An int representing Creole type for this column.
 168       * @return void
 169       */
 170      public function setCreoleType($type)
 171      {
 172          $this->creoleType = $type;
 173      }
 174      
 175      /**
 176       * Set the size of this column.
 177       *
 178       * @param int $size An int specifying the size.
 179       * @return void
 180       */
 181      public function setSize($size)
 182      {
 183          $this->size = $size;
 184      }
 185  
 186      /**
 187       * Set if this column is a primary key or not.
 188       *
 189       * @param boolean $pk True if column is a primary key.
 190       * @return void
 191       */
 192      public function setPrimaryKey($pk)
 193      {
 194          $this->pk = $pk;
 195      }
 196  
 197      /**
 198       * Set if this column may be null.
 199       *
 200       * @param boolean nn True if column may be null.
 201       * @return void
 202       */
 203      public function setNotNull($nn)
 204      {
 205          $this->notNull = $nn;
 206      }
 207      
 208      /**
 209       * Gets the default value for this column.
 210       * @return mixed String or NULL
 211       */
 212  	public function getDefaultValue()
 213      {
 214          return $this->defaultValue;
 215      }
 216      
 217      /**
 218       * Set the foreign key for this column.
 219       *
 220       * @param string tableName The name of the table that is foreign.
 221       * @param string columnName The name of the column that is foreign.
 222       * @return void
 223       */
 224      public function setForeignKey($tableName, $columnName)
 225      {
 226          if ($tableName && $columnName) {
 227              $this->relatedTableName = $tableName;
 228              $this->relatedColumnName = $columnName;
 229          } else {
 230              $this->relatedTableName = "";
 231              $this->relatedColumnName = "";
 232          }
 233      }
 234  
 235      public function addValidator($validator)
 236      {
 237        $this->validators[] = $validator;
 238      }
 239  
 240      public function hasValidators()
 241      {
 242        return count($this->validators) > 0;
 243      }
 244  
 245      public function getValidators()
 246      {
 247        return $this->validators;
 248      }
 249  
 250      
 251      /**
 252       * Get the native PHP type of this column.
 253       *
 254       * @return string A string specifying the native PHP type.
 255       */
 256      public function getType()
 257      {
 258          return $this->type;
 259      }
 260  
 261      /**
 262       * Get the Creole type of this column.
 263       *
 264       * @return string A string specifying the native PHP type.
 265       */
 266      public function getCreoleType()
 267      {
 268          return $this->creoleType;
 269      }
 270  
 271      /**
 272       * Get the size of this column.
 273       *
 274       * @return int An int specifying the size.
 275       */
 276      public function getSize()
 277      {
 278          return $this->size;
 279      }
 280  
 281      /**
 282       * Is this column a primary key?
 283       *
 284       * @return boolean True if column is a primary key.
 285       */
 286      public function isPrimaryKey()
 287      {
 288          return $this->pk;
 289      }
 290  
 291      /**
 292       * Is null value allowed ?
 293       *
 294       * @return boolean True if column may be null.
 295       */
 296      public function isNotNull()
 297      {
 298          return ($this->notNull || $this->isPrimaryKey());
 299      }
 300  
 301      /**
 302       * Is this column a foreign key?
 303       *
 304       * @return boolean True if column is a foreign key.
 305       */
 306      public function isForeignKey()
 307      {
 308          if ($this->relatedTableName) {
 309              return true;
 310          } else {
 311              return false;
 312          }
 313      }
 314  
 315      /**
 316       * Get the table.column that this column is related to.
 317       *
 318       * @return string A String with the full name for the related column.
 319       */
 320      public function getRelatedName()
 321      {
 322          return $this->relatedTableName . "." . $this->relatedColumnName;
 323      }
 324  
 325      /**
 326       * Get the table name that this column is related to.
 327       *
 328       * @return string A String with the name for the related table.
 329       */
 330      public function getRelatedTableName()
 331      {
 332          return $this->relatedTableName;
 333      }
 334  
 335      /**
 336       * Get the column name that this column is related to.
 337       *
 338       * @return string A String with the name for the related column.
 339       */
 340      public function getRelatedColumnName()
 341      {
 342          return $this->relatedColumnName;
 343      }
 344  }


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