table = $table; // adapter $this->adapter = $adapter; // process features if ($features !== null) { if ($features instanceof Feature\AbstractFeature) { $features = [$features]; } if (is_array($features)) { $this->featureSet = new Feature\FeatureSet($features); } elseif ($features instanceof Feature\FeatureSet) { $this->featureSet = $features; } else { throw new Exception\InvalidArgumentException( 'TableGateway expects $feature to be an instance of an AbstractFeature or a FeatureSet, or an ' . 'array of AbstractFeatures' ); } } else { $this->featureSet = new Feature\FeatureSet(); } // result prototype $this->resultSetPrototype = $resultSetPrototype ?: new ResultSet(); // Sql object (factory for select, insert, update, delete) $this->sql = $sql ?: new Sql($this->adapter, $this->table); // check sql object bound to same table if ($this->sql->getTable() !== $this->table) { throw new Exception\InvalidArgumentException( 'The table inside the provided Sql object must match the table of this TableGateway' ); } $this->initialize(); } }