Definition.php 3.1 KB

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