| 1 |
|
<?php |
| 2 |
|
/** |
| 3 |
|
* Xyster Framework |
| 4 |
|
* |
| 5 |
|
* LICENSE |
| 6 |
|
* |
| 7 |
|
* This source file is subject to the new BSD license that is bundled |
| 8 |
|
* with this package in the file LICENSE.txt. |
| 9 |
|
* It is also available through the world-wide-web at this URL: |
| 10 |
|
* http://www.opensource.org/licenses/bsd-license.php |
| 11 |
|
* If you did not receive a copy of the license and are unable to |
| 12 |
|
* obtain it through the world-wide-web, please send an email |
| 13 |
|
* to xyster@devweblog.org so we can send you a copy immediately. |
| 14 |
|
* |
| 15 |
|
* @category Xyster |
| 16 |
|
* @package Xyster_Orm |
| 17 |
|
* @copyright Copyright (c) 2007 Irrational Logic (http://devweblog.org) |
| 18 |
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| 19 |
|
* @version $Id: Field.php 60 2007-08-09 00:27:12Z doublecompile $ |
| 20 |
|
*/ |
| 21 |
|
/** |
| 22 |
|
* An field description object |
| 23 |
|
* |
| 24 |
|
* @category Xyster |
| 25 |
|
* @package Xyster_Orm |
| 26 |
|
* @copyright Copyright (c) 2007 Irrational Logic (http://devweblog.org) |
| 27 |
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| 28 |
|
*/ |
| 29 |
|
class Xyster_Orm_Entity_Field |
| 30 |
|
{ |
| 31 |
|
protected $_name; |
| 32 |
|
protected $_original; |
| 33 |
|
protected $_type; |
| 34 |
|
protected $_length; |
| 35 |
|
protected $_default; |
| 36 |
|
protected $_null; |
| 37 |
|
protected $_primary; |
| 38 |
|
protected $_primaryPosition; |
| 39 |
|
protected $_identity; |
| 40 |
|
|
| 41 |
|
/** |
| 42 |
|
* Create a new entity field |
| 43 |
|
* |
| 44 |
|
* The array passed should be in the format returned by the describeTable |
| 45 |
|
* method of the Zend_Db_Adapter_Abstract class |
| 46 |
|
* |
| 47 |
|
* @see Zend_Db_Adapter_Abstract::describeTable |
| 48 |
|
* @param array $details |
| 49 |
|
*/ |
| 50 |
|
public function __construct( $name, array $details ) |
| 51 |
|
{ |
| 52 |
221 |
$this->_name = $name; |
| 53 |
221 |
$this->_original = $details['COLUMN_NAME']; |
| 54 |
221 |
$this->_type = $details['DATA_TYPE']; |
| 55 |
221 |
$this->_length = $details['LENGTH']; |
| 56 |
221 |
$this->_null = $details['NULLABLE']; |
| 57 |
221 |
$this->_default = $details['DEFAULT']; |
| 58 |
221 |
$this->_primary = $details['PRIMARY']; |
| 59 |
221 |
$this->_primaryPosition = $details['PRIMARY_POSITION']; |
| 60 |
221 |
$this->_identity = (isset($details['IDENTITY'])) ? $details['IDENTITY'] : null; |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
/** |
| 64 |
|
* Gets the name of the field |
| 65 |
|
* |
| 66 |
|
* @return string |
| 67 |
|
*/ |
| 68 |
|
public function getName() |
| 69 |
|
{ |
| 70 |
1 |
return $this->_name; |
| 71 |
|
} |
| 72 |
|
/** |
| 73 |
|
* Gets the original name |
| 74 |
|
* |
| 75 |
|
* @return string |
| 76 |
|
*/ |
| 77 |
|
public function getOriginalName() |
| 78 |
|
{ |
| 79 |
1 |
return $this->_original; |
| 80 |
|
} |
| 81 |
|
/** |
| 82 |
|
* Gets the native type of the field |
| 83 |
|
* |
| 84 |
|
* @return string |
| 85 |
|
*/ |
| 86 |
|
public function getType() |
| 87 |
|
{ |
| 88 |
1 |
return $this->_type; |
| 89 |
|
} |
| 90 |
|
/** |
| 91 |
|
* Gets the length of the field |
| 92 |
|
* |
| 93 |
|
* @return int |
| 94 |
|
*/ |
| 95 |
|
public function getLength() |
| 96 |
|
{ |
| 97 |
1 |
return $this->_length; |
| 98 |
|
} |
| 99 |
|
/** |
| 100 |
|
* Gets whether the field can have a null value |
| 101 |
|
* |
| 102 |
|
* @return boolean |
| 103 |
|
*/ |
| 104 |
|
public function isNullable() |
| 105 |
|
{ |
| 106 |
1 |
return $this->_null; |
| 107 |
|
} |
| 108 |
|
/** |
| 109 |
|
* Gets the default value for the field |
| 110 |
|
* |
| 111 |
|
* @return boolean |
| 112 |
|
*/ |
| 113 |
|
public function getDefault() |
| 114 |
|
{ |
| 115 |
1 |
return $this->_default; |
| 116 |
|
} |
| 117 |
|
/** |
| 118 |
|
* Gets whether the field is part of a primary key |
| 119 |
|
* |
| 120 |
|
* @return boolean |
| 121 |
|
*/ |
| 122 |
|
public function isPrimary() |
| 123 |
|
{ |
| 124 |
221 |
return $this->_primary; |
| 125 |
|
} |
| 126 |
|
/** |
| 127 |
|
* Gets the index of this field in the primary key |
| 128 |
|
* |
| 129 |
|
* @return int |
| 130 |
|
*/ |
| 131 |
|
public function getPrimaryPosition() |
| 132 |
|
{ |
| 133 |
4 |
return $this->_primaryPosition; |
| 134 |
|
} |
| 135 |
|
/** |
| 136 |
|
* Gets whether the field uses an autonumbering scheme |
| 137 |
|
* |
| 138 |
|
* @return boolean |
| 139 |
|
*/ |
| 140 |
|
public function isIdentity() |
| 141 |
|
{ |
| 142 |
4 |
return $this->_identity; |
| 143 |
|
} |
| 144 |
|
} |