Merge pull request #4928 from owncloud/interfaces

Add a couple of interface definitions
remotes/origin/stable6
Thomas Tanghus 12 years ago
commit 200e9691de
  1. 77
      lib/allconfig.php
  2. 31
      lib/app.php
  3. 2
      lib/db/connection.php
  4. 64
      lib/navigationmanager.php
  5. 16
      lib/public/app.php
  6. 65
      lib/public/iconfig.php
  7. 74
      lib/public/idbconnection.php
  8. 27
      lib/public/inavigationmanager.php
  9. 24
      lib/public/iservercontainer.php
  10. 30
      lib/public/iusersession.php
  11. 90
      lib/server.php
  12. 43
      lib/user.php
  13. 2
      lib/user/session.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);
}
}

@ -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;
}

@ -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
*/

@ -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;
}
}

@ -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 );

@ -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);
}

@ -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();
}

@ -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);
}

@ -62,6 +62,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
*
@ -76,4 +93,11 @@ interface IServerContainer {
*/
function getSession();
/**
* Returns the current session
*
* @return \OCP\IDBConnection
*/
function getDatabaseConnection();
}

@ -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();
}

@ -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();
});
@ -97,6 +148,33 @@ class Server extends SimpleContainer implements IServerContainer {
return $this->query('RootFolder');
}
/**
* @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
*
@ -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();
}
}

@ -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();

@ -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
*/

Loading…
Cancel
Save