/library/Zend/Db/Table/Definition.php

https://bitbucket.org/hamidrezas/melobit · PHP · 131 lines · 47 code · 12 blank · 72 comment · 2 complexity · 979c2d15e4261694a31ac33f763d0c72 MD5 · raw file

  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Definition.php 24594 2012-01-05 21:27:01Z matthew $
  21. */
  22. /**
  23. * Class for SQL table interface.
  24. *
  25. * @category Zend
  26. * @package Zend_Db
  27. * @subpackage Table
  28. * @copyright Copyright (c) 2005-2012 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. }