/** * Use the connection to create an adapter that will service the request. * Every request has a code that the connection object uses to determine * which adapter will be used. * * @param DbRequestInterface $request * @param DbResponseInterface $response * @param string $key * @return DbResponse */ public function execute(DbRequestInterface $request, DbResponseInterface $response = null, $key = null) { $connector = $this->getConnector($key); if (!$connector instanceof DbConnectorInterface) { $err = "Database startup task has not been run or your "; $err .= "configuration has no database connectors, could not "; $err .= "find database connector for -({$key})"; throw new LogicException($err); } if (null === $response) { $response = $this->createResponse(); } $conn = $connector->getConnection($request->getStrategy()); if (!$conn instanceof DbConnInterface) { $err = 'Database connector has not been correctly instatiated '; $err .= 'connection object must implment an Appfuel\\DataSource'; $err .= '\\Db\\DbConnInterface'; throw new LogicException($err); } if (!$conn->isConnected()) { $conn->connect(); } $handler = $conn->createDbAdapter($request->getType()); if (!$handler instanceof DbHandlerInterface) { $class = get_class($handler); $err = "database vendor adapter -({$class}) does not implement "; $err .= "Appfuel\\DataSource\\Db\\DbAdapterInterface"; throw new LogicException($err); } return $handler->execute($request, $response); }
/** * @param DbRequestInterface $request * @return DbReponseInterface */ public function execute(DbRequestInterface $request, DbResponseInterface $response) { $className = ucfirst($request->getType()) . 'Adapter'; if (!$this->isAdapterSupported($className)) { $err = "can not execute request on the database server because "; $err .= "Mysqli adapter -({$className}) is not support by appfuel"; throw new RunTimeException($err); } $class = __NAMESPACE__ . "\\{$className}"; $adapter = new $class(); if (!$adapter instanceof MysqliAdapterInterface) { $err = "can not execute -({$className}) because it does not "; $err .= "implment Appfuel\\DataSource\\Db\\DbAdapterInterface"; throw new LogicException($err); } return $adapter->execute($this->getDriver(), $request, $response); }