Definition.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Zend 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://framework.zend.com/license/new-bsd
  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 license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Db
  17. * @subpackage Table
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * Class for SQL table interface.
  23. *
  24. * @category Zend
  25. * @package Zend_Db
  26. * @subpackage Table
  27. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. class Zend_Db_Table_Definition
  31. {
  32. /**
  33. * @var array
  34. */
  35. protected $_tableConfigs = array();
  36. /**
  37. * __construct()
  38. *
  39. * @param array|Zend_Config $options
  40. */
  41. public function __construct($options = null)
  42. {
  43. if ($options instanceof Zend_Config) {
  44. $this->setConfig($options);
  45. } elseif (is_array($options)) {
  46. $this->setOptions($options);
  47. }
  48. }
  49. /**
  50. * setConfig()
  51. *
  52. * @param Zend_Config $config
  53. * @return Zend_Db_Table_Definition
  54. */
  55. public function setConfig(Zend_Config $config)
  56. {
  57. $this->setOptions($config->toArray());
  58. return $this;
  59. }
  60. /**
  61. * setOptions()
  62. *
  63. * @param array $options
  64. * @return Zend_Db_Table_Definition
  65. */
  66. public function setOptions(Array $options)
  67. {
  68. foreach ($options as $optionName => $optionValue) {
  69. $this->setTableConfig($optionName, $optionValue);
  70. }
  71. return $this;
  72. }
  73. /**
  74. * @var string $tableName
  75. * @var array $tableConfig
  76. * @return Zend_Db_Table_Definition
  77. */
  78. public function setTableConfig($tableName, array $tableConfig)
  79. {
  80. // @todo logic here
  81. $tableConfig[Zend_Db_Table::DEFINITION_CONFIG_NAME] = $tableName;
  82. $tableConfig[Zend_Db_Table::DEFINITION] = $this;
  83. if (!isset($tableConfig[Zend_Db_Table::NAME])) {
  84. $tableConfig[Zend_Db_Table::NAME] = $tableName;
  85. }
  86. $this->_tableConfigs[$tableName] = $tableConfig;
  87. return $this;
  88. }
  89. /**
  90. * getTableConfig()
  91. *
  92. * @param string $tableName
  93. * @return array
  94. */
  95. public function getTableConfig($tableName)
  96. {
  97. return $this->_tableConfigs[$tableName];
  98. }
  99. /**
  100. * removeTableConfig()
  101. *
  102. * @param string $tableName
  103. */
  104. public function removeTableConfig($tableName)
  105. {
  106. unset($this->_tableConfigs[$tableName]);
  107. }
  108. /**
  109. * hasTableConfig()
  110. *
  111. * @param string $tableName
  112. * @return bool
  113. */
  114. public function hasTableConfig($tableName)
  115. {
  116. return (isset($this->_tableConfigs[$tableName]));
  117. }
  118. }