diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2013-09-23 14:08:22 -0700 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2013-09-23 14:08:22 -0700 |
commit | 200e9691deea447e9380912bea38630c98bf863f (patch) | |
tree | a27fbaff7348c9c8878134e38aa8592fec3b15b0 | |
parent | 69c28400b47a3a16ead6fc0d5ee5e2212d0d8ab0 (diff) | |
parent | 0c6dcdba6b890dc170f59a461ab80961a85a53db (diff) | |
download | nextcloud-server-200e9691deea447e9380912bea38630c98bf863f.tar.gz nextcloud-server-200e9691deea447e9380912bea38630c98bf863f.zip |
Merge pull request #4928 from owncloud/interfaces
Add a couple of interface definitions
-rw-r--r-- | lib/allconfig.php | 77 | ||||
-rw-r--r-- | lib/app.php | 31 | ||||
-rw-r--r-- | lib/db/connection.php | 2 | ||||
-rw-r--r-- | lib/navigationmanager.php | 64 | ||||
-rw-r--r-- | lib/public/app.php | 16 | ||||
-rw-r--r-- | lib/public/iconfig.php | 65 | ||||
-rw-r--r-- | lib/public/idbconnection.php | 74 | ||||
-rw-r--r-- | lib/public/inavigationmanager.php | 27 | ||||
-rw-r--r-- | lib/public/iservercontainer.php | 24 | ||||
-rw-r--r-- | lib/public/iusersession.php | 30 | ||||
-rw-r--r-- | lib/server.php | 90 | ||||
-rw-r--r-- | lib/user.php | 43 | ||||
-rw-r--r-- | lib/user/session.php | 2 |
13 files changed, 473 insertions, 72 deletions
diff --git a/lib/allconfig.php b/lib/allconfig.php new file mode 100644 index 00000000000..72aabf60793 --- /dev/null +++ b/lib/allconfig.php @@ -0,0 +1,77 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OC; + +/** + * Class to combine all the configuration options ownCloud offers + */ +class AllConfig implements \OCP\IConfig { + /** + * Sets a new system wide value + * @param string $key the key of the value, under which will be saved + * @param string $value the value that should be stored + * @todo need a use case for this + */ +// public function setSystemValue($key, $value) { +// \OCP\Config::setSystemValue($key, $value); +// } + + /** + * Looks up a system wide defined value + * @param string $key the key of the value, under which it was saved + * @return string the saved value + */ + public function getSystemValue($key) { + return \OCP\Config::getSystemValue($key, ''); + } + + + /** + * Writes a new app wide value + * @param string $appName the appName that we want to store the value under + * @param string $key the key of the value, under which will be saved + * @param string $value the value that should be stored + */ + public function setAppValue($appName, $key, $value) { + \OCP\Config::setAppValue($appName, $key, $value); + } + + /** + * Looks up an app wide defined value + * @param string $appName the appName that we stored the value under + * @param string $key the key of the value, under which it was saved + * @return string the saved value + */ + public function getAppValue($appName, $key) { + return \OCP\Config::getAppValue($appName, $key, ''); + } + + + /** + * Set a user defined value + * @param string $userId the userId of the user that we want to store the value under + * @param string $appName the appName that we want to store the value under + * @param string $key the key under which the value is being stored + * @param string $value the value that you want to store + */ + public function setUserValue($userId, $appName, $key, $value) { + \OCP\Config::setUserValue($userId, $appName, $key, $value); + } + + /** + * Shortcut for getting a user defined value + * @param string $userId the userId of the user that we want to store the value under + * @param string $appName the appName that we stored the value under + * @param string $key the key under which the value is being stored + */ + public function getUserValue($userId, $appName, $key){ + return \OCP\Config::getUserValue($userId, $appName, $key); + } +} diff --git a/lib/app.php b/lib/app.php index d98af2dc296..0ab1ee57f63 100644 --- a/lib/app.php +++ b/lib/app.php @@ -27,8 +27,6 @@ * upgrading and removing apps. */ class OC_App{ - static private $activeapp = ''; - static private $navigation = array(); static private $settingsForms = array(); static private $adminForms = array(); static private $personalForms = array(); @@ -271,7 +269,7 @@ class OC_App{ /** * @brief adds an entry to the navigation - * @param string $data array containing the data + * @param array $data array containing the data * @return bool * * This function adds a new entry to the navigation visible to users. $data @@ -287,11 +285,7 @@ class OC_App{ * the navigation. Lower values come first. */ public static function addNavigationEntry( $data ) { - $data['active']=false; - if(!isset($data['icon'])) { - $data['icon']=''; - } - OC_App::$navigation[] = $data; + OC::$server->getNavigationManager()->add($data); return true; } @@ -305,9 +299,7 @@ class OC_App{ * highlighting the current position of the user. */ public static function setActiveNavigationEntry( $id ) { - // load all the apps, to make sure we have all the navigation entries - self::loadApps(); - self::$activeapp = $id; + OC::$server->getNavigationManager()->setActiveEntry($id); return true; } @@ -315,15 +307,14 @@ class OC_App{ * @brief Get the navigation entries for the $app * @param string $app app * @return array of the $data added with addNavigationEntry + * + * Warning: destroys the existing entries */ public static function getAppNavigationEntries($app) { if(is_file(self::getAppPath($app).'/appinfo/app.php')) { - $save = self::$navigation; - self::$navigation = array(); + OC::$server->getNavigationManager()->clear(); require $app.'/appinfo/app.php'; - $app_entries = self::$navigation; - self::$navigation = $save; - return $app_entries; + return OC::$server->getNavigationManager()->getAll(); } return array(); } @@ -336,7 +327,7 @@ class OC_App{ * setActiveNavigationEntry */ public static function getActiveNavigationEntry() { - return self::$activeapp; + return OC::$server->getNavigationManager()->getActiveEntry(); } /** @@ -419,8 +410,9 @@ class OC_App{ // This is private as well. It simply works, so don't ask for more details private static function proceedNavigation( $list ) { + $activeapp = OC::$server->getNavigationManager()->getActiveEntry(); foreach( $list as &$naventry ) { - if( $naventry['id'] == self::$activeapp ) { + if( $naventry['id'] == $activeapp ) { $naventry['active'] = true; } else{ @@ -572,7 +564,8 @@ class OC_App{ * - active: boolean, signals if the user is on this navigation entry */ public static function getNavigation() { - $navigation = self::proceedNavigation( self::$navigation ); + $entries = OC::$server->getNavigationManager()->getAll(); + $navigation = self::proceedNavigation( $entries ); return $navigation; } diff --git a/lib/db/connection.php b/lib/db/connection.php index 2581969dbd0..2d3193a148a 100644 --- a/lib/db/connection.php +++ b/lib/db/connection.php @@ -12,7 +12,7 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\Common\EventManager; -class Connection extends \Doctrine\DBAL\Connection { +class Connection extends \Doctrine\DBAL\Connection implements \OCP\IDBConnection { /** * @var string $tablePrefix */ diff --git a/lib/navigationmanager.php b/lib/navigationmanager.php new file mode 100644 index 00000000000..1f657b9ad80 --- /dev/null +++ b/lib/navigationmanager.php @@ -0,0 +1,64 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OC; + +/** + * Manages the ownCloud navigation + */ +class NavigationManager implements \OCP\INavigationManager { + protected $entries = array(); + protected $activeEntry; + + /** + * Creates a new navigation entry + * @param array $entry containing: id, name, order, icon and href key + */ + public function add(array $entry) { + $entry['active'] = false; + if(!isset($entry['icon'])) { + $entry['icon'] = ''; + } + $this->entries[] = $entry; + } + + /** + * @brief returns all the added Menu entries + * @return array of the added entries + */ + public function getAll() { + return $this->entries; + } + + /** + * @brief removes all the entries + */ + public function clear() { + $this->entries = array(); + } + + /** + * Sets the current navigation entry of the currently running app + * @param string $id of the app entry to activate (from added $entry) + */ + public function setActiveEntry($id) { + $this->activeEntry = $id; + } + + /** + * @brief gets the active Menu entry + * @return string id or empty string + * + * This function returns the id of the active navigation entry (set by + * setActiveEntry + */ + public function getActiveEntry() { + return $this->activeEntry; + } +} diff --git a/lib/public/app.php b/lib/public/app.php index a1ecf524cc8..0a5721b334e 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -35,10 +35,10 @@ namespace OCP; */ class App { /** - * @brief Makes owncloud aware of this app + * @brief Makes ownCloud aware of this app * @brief This call is deprecated and not necessary to use. * @param $data array with all information - * @returns true/false + * @returns boolean * * @deprecated this method is deprecated * Do not call it anymore @@ -52,7 +52,7 @@ class App { /** * @brief adds an entry to the navigation * @param $data array containing the data - * @returns true/false + * @returns boolean * * This function adds a new entry to the navigation visible to users. $data * is an associative array. @@ -72,8 +72,8 @@ class App { /** * @brief marks a navigation entry as active - * @param $id id of the entry - * @returns true/false + * @param $id string id of the entry + * @returns boolean * * This function sets a navigation entry as active and removes the 'active' * property from all other entries. The templates can use this for @@ -104,7 +104,7 @@ class App { /** * @brief Read app metadata from the info.xml file * @param string $app id of the app or the path of the info.xml file - * @param boolean path (optional) + * @param boolean $path (optional) * @returns array */ public static function getAppInfo( $app, $path=false ) { @@ -114,7 +114,7 @@ class App { /** * @brief checks whether or not an app is enabled * @param $app app - * @returns true/false + * @returns boolean * * This function checks whether or not an app is enabled. */ @@ -133,7 +133,7 @@ class App { /** * @brief Get the last version of the app, either from appinfo/version or from appinfo/info.xml * @param $app app - * @returns true/false + * @returns boolean */ public static function getAppVersion( $app ) { return \OC_App::getAppVersion( $app ); diff --git a/lib/public/iconfig.php b/lib/public/iconfig.php new file mode 100644 index 00000000000..850bddf6935 --- /dev/null +++ b/lib/public/iconfig.php @@ -0,0 +1,65 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OCP; + +/** + * Access to all the configuration options ownCloud offers + */ +interface IConfig { + /** + * Sets a new system wide value + * @param string $key the key of the value, under which will be saved + * @param string $value the value that should be stored + * @todo need a use case for this + */ +// public function setSystemValue($key, $value); + + /** + * Looks up a system wide defined value + * @param string $key the key of the value, under which it was saved + * @return string the saved value + */ + public function getSystemValue($key); + + + /** + * Writes a new app wide value + * @param string $appName the appName that we want to store the value under + * @param string $key the key of the value, under which will be saved + * @param string $value the value that should be stored + */ + public function setAppValue($appName, $key, $value); + + /** + * Looks up an app wide defined value + * @param string $appName the appName that we stored the value under + * @param string $key the key of the value, under which it was saved + * @return string the saved value + */ + public function getAppValue($appName, $key); + + + /** + * Set a user defined value + * @param string $userId the userId of the user that we want to store the value under + * @param string $appName the appName that we want to store the value under + * @param string $key the key under which the value is being stored + * @param string $value the value that you want to store + */ + public function setUserValue($userId, $appName, $key, $value); + + /** + * Shortcut for getting a user defined value + * @param string $userId the userId of the user that we want to store the value under + * @param string $appName the appName that we stored the value under + * @param string $key the key under which the value is being stored + */ + public function getUserValue($userId, $appName, $key); +} diff --git a/lib/public/idbconnection.php b/lib/public/idbconnection.php new file mode 100644 index 00000000000..c741a0f061a --- /dev/null +++ b/lib/public/idbconnection.php @@ -0,0 +1,74 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OCP; + +/** + * TODO: Description + */ +interface IDBConnection { + /** + * 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 \Doctrine\DBAL\Driver\Statement The prepared statement. + */ + public function prepare($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 lastInsertId($table = null); + + /** + * @brief Insert a row if a matching row doesn't exists. + * @param $table string The table name (will replace *PREFIX*) to perform the replace on. + * @param $input array + * + * The input array if in the form: + * + * array ( 'id' => array ( 'value' => 6, + * 'key' => true + * ), + * 'name' => array ('value' => 'Stoyan'), + * 'family' => array ('value' => 'Stefanov'), + * 'birth_date' => array ('value' => '1975-06-20') + * ); + * @return bool + * + */ + public function insertIfNotExist($table, $input); + + /** + * @brief Start a transaction + * @return bool TRUE on success or FALSE on failure + */ + public function beginTransaction(); + + /** + * @brief Commit the database changes done during a transaction that is in progress + * @return bool TRUE on success or FALSE on failure + */ + public function commit(); + + /** + * @brief Rollback the database changes done during a transaction that is in progress + * @return bool TRUE on success or FALSE on failure + */ + public function rollBack(); + + /** + * returns the error code and message as a string for logging + * @return string + */ + public function getError(); +} diff --git a/lib/public/inavigationmanager.php b/lib/public/inavigationmanager.php new file mode 100644 index 00000000000..f89e790c1d0 --- /dev/null +++ b/lib/public/inavigationmanager.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OCP; + +/** + * Manages the ownCloud navigation + */ +interface INavigationManager { + /** + * Creates a new navigation entry + * @param array $entry containing: id, name, order, icon and href key + */ + public function add(array $entry); + + /** + * Sets the current navigation entry of the currently running app + * @param string $appId id of the app entry to activate (from added $entry) + */ + public function setActiveEntry($appId); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 1725b7c74e0..4478a4e8a6c 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -63,6 +63,23 @@ interface IServerContainer { function getRootFolder(); /** + * Returns the user session + * + * @return \OCP\IUserSession + */ + function getUserSession(); + + /** + * @return \OCP\INavigationManager + */ + function getNavigationManager(); + + /** + * @return \OCP\IConfig + */ + function getConfig(); + + /** * Returns an ICache instance * * @return \OCP\ICache @@ -76,4 +93,11 @@ interface IServerContainer { */ function getSession(); + /** + * Returns the current session + * + * @return \OCP\IDBConnection + */ + function getDatabaseConnection(); + } diff --git a/lib/public/iusersession.php b/lib/public/iusersession.php new file mode 100644 index 00000000000..5dc1ecf71e6 --- /dev/null +++ b/lib/public/iusersession.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OCP; + +/** + * User session + */ +interface IUserSession { + /** + * Do a user login + * @param string $user the username + * @param string $password the password + * @return bool true if successful + */ + public function login($user, $password); + + /** + * @brief Logs the user out including all the session data + * Logout, destroys session + */ + public function logout(); + +} diff --git a/lib/server.php b/lib/server.php index f4dc22a2be4..804af6b0eac 100644 --- a/lib/server.php +++ b/lib/server.php @@ -4,6 +4,7 @@ namespace OC; use OC\AppFramework\Http\Request; use OC\AppFramework\Utility\SimpleContainer; +use OC\Cache\UserCache; use OC\Files\Node\Root; use OC\Files\View; use OCP\IServerContainer; @@ -49,13 +50,63 @@ class Server extends SimpleContainer implements IServerContainer { return new PreviewManager(); }); $this->registerService('RootFolder', function($c) { - // TODO: get user and user manager from container as well + // TODO: get user from container as well $user = \OC_User::getUser(); - $user = \OC_User::getManager()->get($user); + /** @var $c SimpleContainer */ + $userManager = $c->query('UserManager'); + $user = $userManager->get($user); $manager = \OC\Files\Filesystem::getMountManager(); $view = new View(); return new Root($manager, $view, $user); }); + $this->registerService('UserManager', function($c) { + return new \OC\User\Manager(); + }); + $this->registerService('UserSession', function($c) { + /** @var $c SimpleContainer */ + $manager = $c->query('UserManager'); + $userSession = new \OC\User\Session($manager, \OC::$session); + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); + }); + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { + /** @var $user \OC\User\User */ + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); + }); + $userSession->listen('\OC\User', 'preDelete', function ($user) { + /** @var $user \OC\User\User */ + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); + }); + $userSession->listen('\OC\User', 'postDelete', function ($user) { + /** @var $user \OC\User\User */ + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); + }); + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { + /** @var $user \OC\User\User */ + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); + }); + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { + /** @var $user \OC\User\User */ + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); + }); + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); + }); + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { + /** @var $user \OC\User\User */ + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); + }); + $userSession->listen('\OC\User', 'logout', function () { + \OC_Hook::emit('OC_User', 'logout', array()); + }); + return $userSession; + }); + $this->registerService('NavigationManager', function($c) { + return new \OC\NavigationManager(); + }); + $this->registerService('AllConfig', function($c) { + return new \OC\AllConfig(); + }); $this->registerService('UserCache', function($c) { return new UserCache(); }); @@ -98,6 +149,33 @@ class Server extends SimpleContainer implements IServerContainer { } /** + * @return \OC\User\Manager + */ + function getUserManager() { + return $this->query('UserManager'); + } + + /** + * @return \OC\User\Session + */ + function getUserSession() { + return $this->query('UserSession'); + } + + /** + * @return \OC\NavigationManager + */ + function getNavigationManager() { + return $this->query('NavigationManager'); + } + + /** + * @return \OC\Config + */ + function getConfig() { + return $this->query('AllConfig'); + } + /** * Returns an ICache instance * * @return \OCP\ICache @@ -115,4 +193,12 @@ class Server extends SimpleContainer implements IServerContainer { return \OC::$session; } + /** + * Returns the current session + * + * @return \OCP\IDBConnection + */ + function getDatabaseConnection() { + return \OC_DB::getConnection(); + } } diff --git a/lib/user.php b/lib/user.php index 0f6f40aec9a..7f6a296c3ea 100644 --- a/lib/user.php +++ b/lib/user.php @@ -37,54 +37,15 @@ * logout() */ class OC_User { - public static $userSession = null; - public static function getUserSession() { - if (!self::$userSession) { - $manager = new \OC\User\Manager(); - self::$userSession = new \OC\User\Session($manager, \OC::$session); - self::$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); - }); - self::$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { - /** @var $user \OC\User\User */ - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); - }); - self::$userSession->listen('\OC\User', 'preDelete', function ($user) { - /** @var $user \OC\User\User */ - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); - }); - self::$userSession->listen('\OC\User', 'postDelete', function ($user) { - /** @var $user \OC\User\User */ - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); - }); - self::$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { - /** @var $user \OC\User\User */ - OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); - }); - self::$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { - /** @var $user \OC\User\User */ - OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); - }); - self::$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); - }); - self::$userSession->listen('\OC\User', 'postLogin', function ($user, $password) { - /** @var $user \OC\User\User */ - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); - }); - self::$userSession->listen('\OC\User', 'logout', function () { - \OC_Hook::emit('OC_User', 'logout', array()); - }); - } - return self::$userSession; + return OC::$server->getUserSession(); } /** * @return \OC\User\Manager */ public static function getManager() { - return self::getUserSession()->getManager(); + return OC::$server->getUserManager(); } private static $_backends = array(); diff --git a/lib/user/session.php b/lib/user/session.php index 9a6c669e935..98a24d5bb00 100644 --- a/lib/user/session.php +++ b/lib/user/session.php @@ -27,7 +27,7 @@ use OC\Hooks\Emitter; * * @package OC\User */ -class Session implements Emitter { +class Session implements Emitter, \OCP\IUserSession { /** * @var \OC\User\Manager $manager */ |