ZendDbSchema
Schema management for Zend Framework
 All Classes Namespaces Functions Pages
Database.php
1 <?php
31 {
32  const CHARSET_KEY = 'charset';
33 
37  protected $_loader;
38 
48  public function __construct(
49  $name = null,
53  {
54  if (!$adapter) {
55  $adapter = self::getDefaultAdapter();
56  }
57 
58  if (!$loader || !$generator) {
59  switch (true) {
60  case $adapter instanceof Zend_Db_Adapter_Mysqli:
61  case $adapter instanceof Zend_Db_Adapter_Pdo_Mysql:
62  if (!$loader) {
64  }
65  if (!$generator) {
67  }
68  break;
69  }
70  }
71  //TODO check that adapter, generator and loader are same type
72 
73  $this->_generator = $generator;
74  $this->_loader = $loader;
75  $this->_adapter = $adapter;
76 
77  parent::__construct($name);
78  }
79 
83  protected function _getAlterSql()
84  {
85  return $this->getGenerator()->alterDatabase($this);
86  }
87 
91  protected function _getCreateSql()
92  {
93  return $this->getGenerator()->createDatabase($this);
94  }
95 
99  protected function _getDropSql()
100  {
101  return $this->getGenerator()->dropDatabase($this);
102  }
103 
109  protected function _doReload()
110  {
111  $this->_cleanSchema = $this->_loader->load(
112  $this->getAdapter(),
113  $this->getOriginName()
114  );
115  }
116 
123  public function setCharset($charset)
124  {
125  $this->__set(self::CHARSET_KEY, (string) $charset);
126  return $this;
127  }
128 
134  public function getCharset()
135  {
136  return $this->__get(self::CHARSET_KEY);
137  }
138 
145  public function __set($name, $value)
146  {
147  if (self::NAME_KEY == $name && $value) {
148  if ($this->_name != $value && $this->getAdapter()->hasDatabase($value)) {
149  throw new ZendDbSchema_Db_Schema_Exception("Database with name '{$value}' already exists");
150  }
151  }
152  parent::__set($name, $value);
153  }
154 }