3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Db\Metadata
;
12 use Zend\Db\Adapter\Adapter
;
14 class Metadata
implements MetadataInterface
21 protected $adapter = null;
24 * @var MetadataInterface
26 protected $source = null;
31 * @param Adapter $adapter
33 public function __construct(Adapter
$adapter)
35 $this->adapter
= $adapter;
36 $this->source
= $this->createSourceFromAdapter($adapter);
40 * Create source from adapter
42 * @param Adapter $adapter
43 * @return Source\AbstractSource
45 protected function createSourceFromAdapter(Adapter
$adapter)
47 switch ($adapter->getPlatform()->getName()) {
49 return new Source\
MysqlMetadata($adapter);
51 return new Source\
SqlServerMetadata($adapter);
53 return new Source\
SqliteMetadata($adapter);
55 return new Source\
PostgresqlMetadata($adapter);
58 throw new \
Exception('cannot create source from adapter');
64 * Get base tables and views
66 * @param string $schema
67 * @param bool $includeViews
68 * @return Object\TableObject[]
70 public function getTables($schema = null, $includeViews = false)
72 return $this->source
->getTables($schema, $includeViews);
76 * Get base tables and views
78 * @param string $schema
79 * @return Object\TableObject[]
81 public function getViews($schema = null)
83 return $this->source
->getViews($schema);
89 * @param string $schema
92 public function getTriggers($schema = null)
94 return $this->source
->getTriggers($schema);
100 * @param string $table
101 * @param string $schema
104 public function getConstraints($table, $schema = null)
106 return $this->source
->getConstraints($table, $schema);
112 * @param string $table
113 * @param string $schema
116 public function getColumns($table, $schema = null)
118 return $this->source
->getColumns($table, $schema);
122 * Get constraint keys
124 * @param string $constraint
125 * @param string $table
126 * @param string $schema
129 public function getConstraintKeys($constraint, $table, $schema = null)
131 return $this->source
->getConstraintKeys($constraint, $table, $schema);
137 * @param string $constraintName
138 * @param string $table
139 * @param string $schema
140 * @return Object\ConstraintObject
142 public function getConstraint($constraintName, $table, $schema = null)
144 return $this->source
->getConstraint($constraintName, $table, $schema);
150 public function getSchemas()
152 return $this->source
->getSchemas();
158 * @param string $schema
159 * @param bool $includeViews
162 public function getTableNames($schema = null, $includeViews = false)
164 return $this->source
->getTableNames($schema, $includeViews);
170 * @param string $tableName
171 * @param string $schema
172 * @return Object\TableObject
174 public function getTable($tableName, $schema = null)
176 return $this->source
->getTable($tableName, $schema);
182 * @param string $schema
183 * @return \Zend\Db\Metadata\Object\TableObject
185 public function getViewNames($schema = null)
187 return $this->source
->getTable($schema);
193 * @param string $viewName
194 * @param string $schema
195 * @return \Zend\Db\Metadata\Object\TableObject
197 public function getView($viewName, $schema = null)
199 return $this->source
->getView($viewName, $schema);
205 * @param string $schema
208 public function getTriggerNames($schema = null)
210 return $this->source
->getTriggerNames($schema);
216 * @param string $triggerName
217 * @param string $schema
218 * @return \Zend\Db\Metadata\Object\TriggerObject
220 public function getTrigger($triggerName, $schema = null)
222 return $this->source
->getTrigger($triggerName, $schema);
228 * @param string $table
229 * @param string $schema
232 public function getColumnNames($table, $schema = null)
234 return $this->source
->getColumnNames($table, $schema);
240 * @param string $columnName
241 * @param string $table
242 * @param string $schema
243 * @return \Zend\Db\Metadata\Object\ColumnObject
245 public function getColumn($columnName, $table, $schema = null)
247 return $this->source
->getColumn($columnName, $table, $schema);