PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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