ZendDbSchema
Schema management for Zend Framework
 All Classes Namespaces Functions Pages
Index.php
1 <?php
31 {
32  const COLUMNS_KEY = 'columns';
33  const TYPE_KEY = 'type';
34 
40  protected function _getSchemaKey()
41  {
42  return ZendDbSchema_Db_Schema_Table::INDEXES_KEY;
43  }
44 
48  protected function _getDropSql()
49  {
50  return $this->getTable()->getGenerator()->dropIndex($this);
51  }
52 
56  protected function _getAlterSql()
57  {
58  return $this->getTable()->getGenerator()->alterIndex($this);
59  }
60 
64  protected function _getCreateSql()
65  {
66  return $this->getTable()->getGenerator()->createIndex($this);
67  }
68 
75  public function setColumns(array $columns)
76  {
77  $this->__set(self::COLUMNS_KEY, array_unique($columns));
78  return $this;
79  }
80 
87  public function hasColumn($columnName)
88  {
89  return in_array($columnName, $this->getColumns());
90  }
91 
98  public function addColumn($columnName)
99  {
100  if (!$this->hasColumn($columnName)) {
101  $columns = $this->getColumns();
102  $columns[] = $columnName;
103  $this->setColumns($columns);
104  }
105  return $this;
106  }
107 
113  public function getColumns()
114  {
115  $columns = $this->__get(self::COLUMNS_KEY);
116  return is_array($columns) ? $columns : array();
117  }
118 
125  public function removeColumn($columnName)
126  {
127  if ($this->hasColumn($columnName)) {
128  $columns = array_flip($this->getColumns());
129  unset($columns[$columnName]);
130  $this->setColumns(array_flip($columns));
131  }
132  return $this;
133  }
134 }