From 4a7e0561caebd470fbaaf88655619930260a573e Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 19 Apr 2014 19:30:12 +0200 Subject: move db into iservercontainer --- lib/private/appframework/db/db.php | 2 +- .../dependencyinjection/dicontainer.php | 7 --- lib/private/server.php | 13 ++++++ lib/public/appframework/db/idb.php | 51 ---------------------- lib/public/appframework/db/mapper.php | 2 + lib/public/idb.php | 51 ++++++++++++++++++++++ lib/public/iservercontainer.php | 8 ++++ 7 files changed, 75 insertions(+), 59 deletions(-) delete mode 100644 lib/public/appframework/db/idb.php create mode 100644 lib/public/idb.php (limited to 'lib') diff --git a/lib/private/appframework/db/db.php b/lib/private/appframework/db/db.php index 713b39175c6..fc77a38f814 100644 --- a/lib/private/appframework/db/db.php +++ b/lib/private/appframework/db/db.php @@ -23,7 +23,7 @@ namespace OC\AppFramework\Db; -use \OCP\AppFramework\Db\IDb; +use \OCP\IDb; /** diff --git a/lib/private/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php index 0faa507c76e..73d356e9852 100644 --- a/lib/private/appframework/dependencyinjection/dicontainer.php +++ b/lib/private/appframework/dependencyinjection/dicontainer.php @@ -61,13 +61,6 @@ class DIContainer extends SimpleContainer implements IAppContainer{ return new API($c['AppName']); }); - /** - * Database - */ - $this['Db'] = $this->share(function($c){ - return new Db(); - }); - /** * Http */ diff --git a/lib/private/server.php b/lib/private/server.php index 5d90a0b19fc..e977c643832 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -3,6 +3,7 @@ namespace OC; use OC\AppFramework\Http\Request; +use OC\AppFramework\Db\Db; use OC\AppFramework\Utility\SimpleContainer; use OC\Cache\UserCache; use OC\DB\ConnectionWrapper; @@ -177,6 +178,9 @@ class Server extends SimpleContainer implements IServerContainer { } return $router; }); + $this['Db'] = $this->share(function($c){ + return new Db(); + }); } /** @@ -392,4 +396,13 @@ class Server extends SimpleContainer implements IServerContainer { function getRouter(){ return $this->query('Router'); } + + + /** + * Returns an instance of the db facade + * @return \OCP\IDb + */ + function getDb() { + return $this->query('Db'); + } } diff --git a/lib/public/appframework/db/idb.php b/lib/public/appframework/db/idb.php deleted file mode 100644 index e5313476f40..00000000000 --- a/lib/public/appframework/db/idb.php +++ /dev/null @@ -1,51 +0,0 @@ -. - * - */ - -namespace OCP\AppFramework\Db; - - -/** - * Small Facade for being able to inject the database connection for tests - */ -interface IDb { - - - /** - * Used to abstract the owncloud database access away - * @param string $sql the sql query with ? placeholder for params - * @param int $limit the maximum number of rows - * @param int $offset from which row we want to start - * @return \OC_DB_StatementWrapper prepared SQL query - */ - public function prepareQuery($sql, $limit=null, $offset=null); - - - /** - * Used to get the id of the just inserted element - * @param string $tableName the name of the table where we inserted the item - * @return int the id of the inserted element - */ - public function getInsertId($tableName); - - -} diff --git a/lib/public/appframework/db/mapper.php b/lib/public/appframework/db/mapper.php index 3e9778dbc61..46240649c77 100644 --- a/lib/public/appframework/db/mapper.php +++ b/lib/public/appframework/db/mapper.php @@ -26,6 +26,8 @@ namespace OCP\AppFramework\Db; +use \OCP\IDb; + /** * Simple parent class for inheriting your data access layer from. This class diff --git a/lib/public/idb.php b/lib/public/idb.php new file mode 100644 index 00000000000..82a8a681500 --- /dev/null +++ b/lib/public/idb.php @@ -0,0 +1,51 @@ +. + * + */ + +namespace OCP; + + +/** + * Small Facade for being able to inject the database connection for tests + */ +interface IDb { + + + /** + * Used to abstract the owncloud database access away + * @param string $sql the sql query with ? placeholder for params + * @param int $limit the maximum number of rows + * @param int $offset from which row we want to start + * @return \OC_DB_StatementWrapper prepared SQL query + */ + public function prepareQuery($sql, $limit=null, $offset=null); + + + /** + * Used to get the id of the just inserted element + * @param string $tableName the name of the table where we inserted the item + * @return int the id of the inserted element + */ + public function getInsertId($tableName); + + +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 600d81d83af..22176c36b8a 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -113,6 +113,14 @@ interface IServerContainer { */ function getConfig(); + + /** + * Returns an instance of the db facade + * @return \OCP\IDb + */ + function getDb(); + + /** * Returns the app config manager * -- cgit v1.2.3