Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Deprecate Zend\Db\Metadata\Metadata in favor of Zend\Db\Metadata\Source\Factory #22

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 20 additions & 110 deletions src/Metadata/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@

use Zend\Db\Adapter\Adapter;

/**
* @deprecated Use Zend\Db\Metadata\Source\Factory::createSourceFromAdapter($adapter)
*/
class Metadata implements MetadataInterface
{
/**
* Adapter
*
* @var Adapter
*/
protected $adapter = null;

/**
* @var MetadataInterface
*/
Expand All @@ -32,217 +28,131 @@ class Metadata implements MetadataInterface
*/
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
$this->source = $this->createSourceFromAdapter($adapter);
$this->source = Source\Factory::createSourceFromAdapter($adapter);
}

/**
* Create source from adapter
*
* @param Adapter $adapter
* @return Source\AbstractSource
*/
protected function createSourceFromAdapter(Adapter $adapter)
{
switch ($adapter->getPlatform()->getName()) {
case 'MySQL':
return new Source\MysqlMetadata($adapter);
case 'SQLServer':
return new Source\SqlServerMetadata($adapter);
case 'SQLite':
return new Source\SqliteMetadata($adapter);
case 'PostgreSQL':
return new Source\PostgresqlMetadata($adapter);
case 'Oracle':
return new Source\OracleMetadata($adapter);
}

throw new \Exception('cannot create source from adapter');
}

// @todo methods

/**
* Get base tables and views
*
* @param string $schema
* @param bool $includeViews
* @return Object\TableObject[]
* {@inheritdoc}
*/
public function getTables($schema = null, $includeViews = false)
{
return $this->source->getTables($schema, $includeViews);
}

/**
* Get base tables and views
*
* @param string $schema
* @return Object\TableObject[]
* {@inheritdoc}
*/
public function getViews($schema = null)
{
return $this->source->getViews($schema);
}

/**
* Get triggers
*
* @param string $schema
* @return array
* {@inheritdoc}
*/
public function getTriggers($schema = null)
{
return $this->source->getTriggers($schema);
}

/**
* Get constraints
*
* @param string $table
* @param string $schema
* @return array
* {@inheritdoc}
*/
public function getConstraints($table, $schema = null)
{
return $this->source->getConstraints($table, $schema);
}

/**
* Get columns
*
* @param string $table
* @param string $schema
* @return array
* {@inheritdoc}
*/
public function getColumns($table, $schema = null)
{
return $this->source->getColumns($table, $schema);
}

/**
* Get constraint keys
*
* @param string $constraint
* @param string $table
* @param string $schema
* @return array
* {@inheritdoc}
*/
public function getConstraintKeys($constraint, $table, $schema = null)
{
return $this->source->getConstraintKeys($constraint, $table, $schema);
}

/**
* Get constraints
*
* @param string $constraintName
* @param string $table
* @param string $schema
* @return Object\ConstraintObject
* {@inheritdoc}
*/
public function getConstraint($constraintName, $table, $schema = null)
{
return $this->source->getConstraint($constraintName, $table, $schema);
}

/**
* Get schemas
* {@inheritdoc}
*/
public function getSchemas()
{
return $this->source->getSchemas();
}

/**
* Get table names
*
* @param string $schema
* @param bool $includeViews
* @return array
* {@inheritdoc}
*/
public function getTableNames($schema = null, $includeViews = false)
{
return $this->source->getTableNames($schema, $includeViews);
}

/**
* Get table
*
* @param string $tableName
* @param string $schema
* @return Object\TableObject
* {@inheritdoc}
*/
public function getTable($tableName, $schema = null)
{
return $this->source->getTable($tableName, $schema);
}

/**
* Get views names
*
* @param string $schema
* @return \Zend\Db\Metadata\Object\TableObject
* {@inheritdoc}
*/
public function getViewNames($schema = null)
{
return $this->source->getViewNames($schema);
}

/**
* Get view
*
* @param string $viewName
* @param string $schema
* @return \Zend\Db\Metadata\Object\TableObject
* {@inheritdoc}
*/
public function getView($viewName, $schema = null)
{
return $this->source->getView($viewName, $schema);
}

/**
* Get trigger names
*
* @param string $schema
* @return array
* {@inheritdoc}
*/
public function getTriggerNames($schema = null)
{
return $this->source->getTriggerNames($schema);
}

/**
* Get trigger
*
* @param string $triggerName
* @param string $schema
* @return \Zend\Db\Metadata\Object\TriggerObject
* {@inheritdoc}
*/
public function getTrigger($triggerName, $schema = null)
{
return $this->source->getTrigger($triggerName, $schema);
}

/**
* Get column names
*
* @param string $table
* @param string $schema
* @return array
* {@inheritdoc}
*/
public function getColumnNames($table, $schema = null)
{
return $this->source->getColumnNames($table, $schema);
}

/**
* Get column
*
* @param string $columnName
* @param string $table
* @param string $schema
* @return \Zend\Db\Metadata\Object\ColumnObject
* {@inheritdoc}
*/
public function getColumn($columnName, $table, $schema = null)
{
Expand Down
119 changes: 119 additions & 0 deletions src/Metadata/MetadataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,144 @@

interface MetadataInterface
{
/**
* Get schemas.
*
* @return string[]
*/
public function getSchemas();

/**
* Get table names.
*
* @param null|string $schema
* @param bool $includeViews
* @return string[]
*/
public function getTableNames($schema = null, $includeViews = false);

/**
* Get tables.
*
* @param null|string $schema
* @param bool $includeViews
* @return Object\TableObject[]
*/
public function getTables($schema = null, $includeViews = false);

/**
* Get table
*
* @param string $tableName
* @param null|string $schema
* @return Object\TableObject
*/
public function getTable($tableName, $schema = null);

/**
* Get view names
*
* @param null|string $schema
* @return string[]
*/
public function getViewNames($schema = null);

/**
* Get views
*
* @param null|string $schema
* @return Object\ViewObject[]
*/
public function getViews($schema = null);

/**
* Get view
*
* @param string $viewName
* @param null|string $schema
* @return Object\ViewObject
*/
public function getView($viewName, $schema = null);

/**
* Get column names
*
* @param string $table
* @param null|string $schema
* @return string[]
*/
public function getColumnNames($table, $schema = null);

/**
* Get columns
*
* @param string $table
* @param null|string $schema
* @return Object\ColumnObject[]
*/
public function getColumns($table, $schema = null);

/**
* Get column
*
* @param string $columnName
* @param string $table
* @param null|string $schema
* @return Object\ColumnObject
*/
public function getColumn($columnName, $table, $schema = null);

/**
* Get constraints
*
* @param string $table
* @param null|string $schema
* @return Object\ConstraintObject[]
*/
public function getConstraints($table, $schema = null);

/**
* Get constraint
*
* @param string $constraintName
* @param string $table
* @param null|string $schema
* @return Object\ConstraintObject
*/
public function getConstraint($constraintName, $table, $schema = null);

/**
* Get constraint keys
*
* @param string $constraint
* @param string $table
* @param null|string $schema
* @return Object\ConstraintKeyObject[]
*/
public function getConstraintKeys($constraint, $table, $schema = null);

/**
* Get trigger names
*
* @param null|string $schema
* @return string[]
*/
public function getTriggerNames($schema = null);

/**
* Get triggers
*
* @param null|string $schema
* @return Object\TriggerObject[]
*/
public function getTriggers($schema = null);

/**
* Get trigger
*
* @param string $triggerName
* @param null|string $schema
* @return Object\TriggerObject
*/
public function getTrigger($triggerName, $schema = null);
}
Loading