Source of file MetadataFeature.php
Size: 2,393 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Db/TableGateway/Feature/MetadataFeature.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\TableGateway\Feature; use Zend\Db\Metadata\Metadata; use Zend\Db\Metadata\MetadataInterface; use Zend\Db\TableGateway\Exception; use Zend\Db\Metadata\Object\TableObject; class MetadataFeature extends AbstractFeature { /** * @var MetadataInterface */ protected $metadata = null; /** * Constructor * * @param MetadataInterface $metadata */ public function __construct(MetadataInterface $metadata = null) { if ($metadata) { $this->metadata = $metadata; } $this->sharedData['metadata'] = array( 'primaryKey' => null, 'columns' => array() ); } public function postInitialize() { if ($this->metadata == null) { $this->metadata = new Metadata($this->tableGateway->adapter); } // localize variable for brevity $t = $this->tableGateway; $m = $this->metadata; // get column named $columns = $m->getColumnNames($t->table); $t->columns = $columns; // set locally $this->sharedData['metadata']['columns'] = $columns; // process primary key only if table is a table; there are no PK constraints on views if (!($m->getTable($t->table) instanceof TableObject)) { return; } $pkc = null; foreach ($m->getConstraints($t->table) as $constraint) { /** @var $constraint \Zend\Db\Metadata\Object\ConstraintObject */ if ($constraint->getType() == 'PRIMARY KEY') { $pkc = $constraint; break; } } if ($pkc === null) { throw new Exception\RuntimeException('A primary key for this column could not be found in the metadata.'); } if (count($pkc->getColumns()) == 1) { $pkck = $pkc->getColumns(); $primaryKey = $pkck[0]; } else { $primaryKey = $pkc->getColumns(); } $this->sharedData['metadata']['primaryKey'] = $primaryKey; } } |