Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Db / TableGateway / Feature / RowGatewayFeature.php
blob13f9239150a94056900ae2b04f06d2af040206b7
1 <?php
2 /**
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
8 */
10 namespace Zend\Db\TableGateway\Feature;
12 use Zend\Db\ResultSet\ResultSet;
13 use Zend\Db\RowGateway\RowGateway;
14 use Zend\Db\RowGateway\RowGatewayInterface;
15 use Zend\Db\TableGateway\Exception;
17 class RowGatewayFeature extends AbstractFeature
20 /**
21 * @var array
23 protected $constructorArguments = array();
25 /**
26 * @param null $primaryKey
28 public function __construct()
30 $this->constructorArguments = func_get_args();
33 public function postInitialize()
35 $args = $this->constructorArguments;
37 /** @var $resultSetPrototype ResultSet */
38 $resultSetPrototype = $this->tableGateway->resultSetPrototype;
40 if (!$this->tableGateway->resultSetPrototype instanceof ResultSet) {
41 throw new Exception\RuntimeException(
42 'This feature ' . __CLASS__ . ' expects the ResultSet to be an instance of Zend\Db\ResultSet\ResultSet'
46 if (isset($args[0])) {
47 if (is_string($args[0])) {
48 $primaryKey = $args[0];
49 $rowGatewayPrototype = new RowGateway($primaryKey, $this->tableGateway->table, $this->tableGateway->adapter, $this->tableGateway->sql);
50 $resultSetPrototype->setArrayObjectPrototype($rowGatewayPrototype);
51 } elseif ($args[0] instanceof RowGatewayInterface) {
52 $rowGatewayPrototype = $args[0];
53 $resultSetPrototype->setArrayObjectPrototype($rowGatewayPrototype);
55 } else {
56 // get from metadata feature
57 $metadata = $this->tableGateway->featureSet->getFeatureByClassName('Zend\Db\TableGateway\Feature\MetadataFeature');
58 if ($metadata === false || !isset($metadata->sharedData['metadata'])) {
59 throw new Exception\RuntimeException(
60 'No information was provided to the RowGatewayFeature and/or no MetadataFeature could be consulted to find the primary key necessary for RowGateway object creation.'
63 $primaryKey = $metadata->sharedData['metadata']['primaryKey'];
64 $rowGatewayPrototype = new RowGateway($primaryKey, $this->tableGateway->table, $this->tableGateway->adapter, $this->tableGateway->sql);
65 $resultSetPrototype->setArrayObjectPrototype($rowGatewayPrototype);