PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/map/ColumnMap.php

https://github.com/Kazuhiro-Murota/OpenPNE3
PHP | 417 lines | 157 code | 45 blank | 215 comment | 49 complexity | 4834cdc2c54e21e5e8d4624a26be637d MD5 | raw file
  1. <?php
  2. /*
  3. * $Id: ColumnMap.php 784 2007-11-08 10:15:50Z heltem $
  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. * ColumnMap is used to model a column of a table in a database.
  23. *
  24. * GENERAL NOTE
  25. * ------------
  26. * The propel.map classes are abstract building-block classes for modeling
  27. * the database at runtime. These classes are similar (a lite version) to the
  28. * propel.engine.database.model classes, which are build-time modeling classes.
  29. * These classes in themselves do not do any database metadata lookups, but instead
  30. * are used by the MapBuilder classes that were generated for your datamodel. The
  31. * MapBuilder that was created for your datamodel build a representation of your
  32. * database by creating instances of the DatabaseMap, TableMap, ColumnMap, etc.
  33. * classes. See propel/templates/om/php5/MapBuilder.tpl and the classes generated
  34. * by that template for your datamodel to further understand how these are put
  35. * together.
  36. *
  37. * @author Hans Lellelid <hans@xmpl.org> (Propel)
  38. * @author John D. McNally <jmcnally@collab.net> (Torque)
  39. * @version $Revision: 784 $
  40. * @package propel.map
  41. */
  42. class ColumnMap {
  43. /** @var string Propel type of the column. */
  44. private $type;
  45. /** Size of the column. */
  46. private $size = 0;
  47. /** Is it a primary key? */
  48. private $pk = false;
  49. /** Is null value allowed ?*/
  50. private $notNull = false;
  51. /** The default value for this column. */
  52. private $defaultValue;
  53. /** Name of the table that this column is related to. */
  54. private $relatedTableName = "";
  55. /** Name of the column that this column is related to. */
  56. private $relatedColumnName = "";
  57. /** The TableMap for this column. */
  58. private $table;
  59. /** The name of the column. */
  60. private $columnName;
  61. /** The php name of the column. */
  62. private $phpName;
  63. /** validators for this column */
  64. private $validators = array();
  65. /**
  66. * Constructor.
  67. *
  68. * @param string $name The name of the column.
  69. * @param TableMap containingTable TableMap of the table this column is in.
  70. */
  71. public function __construct($name, TableMap $containingTable)
  72. {
  73. $this->columnName = $name;
  74. $this->table = $containingTable;
  75. }
  76. /**
  77. * Gets column name (DEPRECATED).
  78. * @return string
  79. * @deprecated Use getName() instead.
  80. */
  81. public function getColumnName()
  82. {
  83. return $this->getName();
  84. }
  85. /**
  86. * Get the name of a column.
  87. *
  88. * @return string A String with the column name.
  89. */
  90. public function getName()
  91. {
  92. return $this->columnName;
  93. }
  94. /**
  95. * Get the name of a column.
  96. *
  97. * @return string A String with the column name.
  98. */
  99. public function getPhpName()
  100. {
  101. return $this->phpName;
  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. * Get the table name + column name.
  115. *
  116. * @return string A String with the full column name.
  117. */
  118. public function getFullyQualifiedName()
  119. {
  120. return $this->table->getName() . "." . $this->columnName;
  121. }
  122. /**
  123. * Get the table map this column belongs to.
  124. * @return TableMap
  125. */
  126. public function getTable()
  127. {
  128. return $this->table;
  129. }
  130. /**
  131. * Get the name of the table this column is in.
  132. *
  133. * @return string A String with the table name.
  134. */
  135. public function getTableName()
  136. {
  137. return $this->table->getName();
  138. }
  139. /**
  140. * Get the Propel type of this column.
  141. *
  142. * @return string A string representing the Propel type (e.g. PropelColumnTypes::DATE).
  143. */
  144. public function getType()
  145. {
  146. return $this->type;
  147. }
  148. /**
  149. * Set the Propel type of this column.
  150. *
  151. * @param string $type A string representing the Propel type (e.g. PropelColumnTypes::DATE).
  152. * @return void
  153. */
  154. public function setType($type)
  155. {
  156. $this->type = $type;
  157. }
  158. /**
  159. * Get the PHP type of this column.
  160. *
  161. * @return int The PDO::PARMA_* value
  162. */
  163. /*
  164. public function getPhpType()
  165. {
  166. return PropelColumnTypes::getPhpType($this->type);
  167. }
  168. */
  169. /**
  170. * Get the PDO type of this column.
  171. *
  172. * @return int The PDO::PARMA_* value
  173. */
  174. public function getPdoType()
  175. {
  176. return PropelColumnTypes::getPdoType($this->type);
  177. }
  178. /**
  179. * Whether this is a BLOB, LONGVARBINARY, or VARBINARY.
  180. * @return boolean
  181. */
  182. public function isLob()
  183. {
  184. return ($this->type == PropelColumnTypes::BLOB || $this->type == PropelColumnTypes::VARBINARY || $this->type == PropelColumnTypes::LONGVARBINARY);
  185. }
  186. /**
  187. * Whether this is a DATE/TIME/TIMESTAMP column that is post-epoch (1970).
  188. *
  189. * PHP cannot handle pre-epoch timestamps well -- hence the need to differentiate
  190. * between epoch and pre-epoch timestamps.
  191. *
  192. * @return boolean
  193. * @deprecated Propel supports non-epoch dates
  194. */
  195. public function isEpochTemporal()
  196. {
  197. return ($this->type == PropelColumnTypes::TIMESTAMP || $this->type == PropelColumnTypes::DATE || $this->type == PropelColumnTypes::TIME);
  198. }
  199. /**
  200. * Whether this column is numeric (int, decimal, bigint etc).
  201. * @return boolean
  202. */
  203. public function isNumeric()
  204. {
  205. return ($this->type == PropelColumnTypes::NUMERIC || $this->type == PropelColumnTypes::DECIMAL || $this->type == PropelColumnTypes::TINYINT || $this->type == PropelColumnTypes::SMALLINT || $this->type == PropelColumnTypes::INTEGER || $this->type == PropelColumnTypes::BIGINT || $this->type == PropelColumnTypes::REAL || $this->type == PropelColumnTypes::FLOAT || $this->type == PropelColumnTypes::DOUBLE);
  206. }
  207. /**
  208. * Whether this is a DATE/TIME/TIMESTAMP column.
  209. *
  210. * @return boolean
  211. * @since 1.3
  212. */
  213. public function isTemporal()
  214. {
  215. return ($this->type == PropelColumnTypes::TIMESTAMP || $this->type == PropelColumnTypes::DATE || $this->type == PropelColumnTypes::TIME || $this->type == PropelColumnTypes::BU_DATE || $this->type == PropelColumnTypes::BU_TIMESTAMP);
  216. }
  217. /**
  218. * Whether this column is a text column (varchar, char, longvarchar).
  219. * @return boolean
  220. */
  221. public function isText()
  222. {
  223. return ($this->type == PropelColumnTypes::VARCHAR || $this->type == PropelColumnTypes::LONGVARCHAR || $this->type == PropelColumnTypes::CHAR);
  224. }
  225. /**
  226. * Set the size of this column.
  227. *
  228. * @param int $size An int specifying the size.
  229. * @return void
  230. */
  231. public function setSize($size)
  232. {
  233. $this->size = $size;
  234. }
  235. /**
  236. * Set if this column is a primary key or not.
  237. *
  238. * @param boolean $pk True if column is a primary key.
  239. * @return void
  240. */
  241. public function setPrimaryKey($pk)
  242. {
  243. $this->pk = $pk;
  244. }
  245. /**
  246. * Set if this column may be null.
  247. *
  248. * @param boolean nn True if column may be null.
  249. * @return void
  250. */
  251. public function setNotNull($nn)
  252. {
  253. $this->notNull = $nn;
  254. }
  255. /**
  256. * Gets the default value for this column.
  257. * @return mixed String or NULL
  258. */
  259. public function getDefaultValue()
  260. {
  261. return $this->defaultValue;
  262. }
  263. /**
  264. * Set the foreign key for this column.
  265. *
  266. * @param string tableName The name of the table that is foreign.
  267. * @param string columnName The name of the column that is foreign.
  268. * @return void
  269. */
  270. public function setForeignKey($tableName, $columnName)
  271. {
  272. if ($tableName && $columnName) {
  273. $this->relatedTableName = $tableName;
  274. $this->relatedColumnName = $columnName;
  275. } else {
  276. $this->relatedTableName = "";
  277. $this->relatedColumnName = "";
  278. }
  279. }
  280. public function addValidator($validator)
  281. {
  282. $this->validators[] = $validator;
  283. }
  284. public function hasValidators()
  285. {
  286. return count($this->validators) > 0;
  287. }
  288. public function getValidators()
  289. {
  290. return $this->validators;
  291. }
  292. /**
  293. * Get the size of this column.
  294. *
  295. * @return int An int specifying the size.
  296. */
  297. public function getSize()
  298. {
  299. return $this->size;
  300. }
  301. /**
  302. * Is this column a primary key?
  303. *
  304. * @return boolean True if column is a primary key.
  305. */
  306. public function isPrimaryKey()
  307. {
  308. return $this->pk;
  309. }
  310. /**
  311. * Is null value allowed ?
  312. *
  313. * @return boolean True if column may not be null.
  314. */
  315. public function isNotNull()
  316. {
  317. return ($this->notNull || $this->isPrimaryKey());
  318. }
  319. /**
  320. * Is this column a foreign key?
  321. *
  322. * @return boolean True if column is a foreign key.
  323. */
  324. public function isForeignKey()
  325. {
  326. if ($this->relatedTableName) {
  327. return true;
  328. } else {
  329. return false;
  330. }
  331. }
  332. /**
  333. * Get the table.column that this column is related to.
  334. *
  335. * @return string A String with the full name for the related column.
  336. */
  337. public function getRelatedName()
  338. {
  339. return $this->relatedTableName . "." . $this->relatedColumnName;
  340. }
  341. /**
  342. * Get the table name that this column is related to.
  343. *
  344. * @return string A String with the name for the related table.
  345. */
  346. public function getRelatedTableName()
  347. {
  348. return $this->relatedTableName;
  349. }
  350. /**
  351. * Get the column name that this column is related to.
  352. *
  353. * @return string A String with the name for the related column.
  354. */
  355. public function getRelatedColumnName()
  356. {
  357. return $this->relatedColumnName;
  358. }
  359. /**
  360. * Performs DB-specific ignore case, but only if the column type necessitates it.
  361. * @param string $str The expression we want to apply the ignore case formatting to (e.g. the column name).
  362. * @param DBAdapter $db
  363. */
  364. public function ignoreCase($str, DBAdapter $db)
  365. {
  366. if ($this->isText()) {
  367. return $db->ignoreCase($str);
  368. } else {
  369. return $str;
  370. }
  371. }
  372. }