2013-08-21 02:58:15 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OC;
|
|
|
|
|
2013-09-05 01:45:11 +04:00
|
|
|
use OC\AppFramework\Http\Request;
|
2013-08-27 01:48:18 +04:00
|
|
|
use OC\AppFramework\Utility\SimpleContainer;
|
2013-09-20 23:57:48 +04:00
|
|
|
use OC\Cache\UserCache;
|
2013-09-16 00:24:57 +04:00
|
|
|
use OC\Files\Node\Root;
|
|
|
|
use OC\Files\View;
|
2013-08-31 23:34:29 +04:00
|
|
|
use OCP\IServerContainer;
|
2013-08-21 02:58:15 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Server
|
|
|
|
* @package OC
|
|
|
|
*
|
|
|
|
* TODO: hookup all manager classes
|
|
|
|
*/
|
2013-08-27 01:48:18 +04:00
|
|
|
class Server extends SimpleContainer implements IServerContainer {
|
2013-08-21 02:58:15 +04:00
|
|
|
|
2013-08-27 01:48:18 +04:00
|
|
|
function __construct() {
|
2013-09-17 19:46:33 +04:00
|
|
|
$this->registerService('ContactsManager', function($c) {
|
2013-08-27 01:48:18 +04:00
|
|
|
return new ContactsManager();
|
|
|
|
});
|
2013-09-17 19:46:33 +04:00
|
|
|
$this->registerService('Request', function($c) {
|
2013-09-05 01:45:11 +04:00
|
|
|
$params = array();
|
|
|
|
|
|
|
|
// we json decode the body only in case of content type json
|
|
|
|
if (isset($_SERVER['CONTENT_TYPE']) && stripos($_SERVER['CONTENT_TYPE'],'json') === true ) {
|
|
|
|
$params = json_decode(file_get_contents('php://input'), true);
|
|
|
|
$params = is_array($params) ? $params: array();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Request(
|
|
|
|
array(
|
|
|
|
'get' => $_GET,
|
|
|
|
'post' => $_POST,
|
|
|
|
'files' => $_FILES,
|
|
|
|
'server' => $_SERVER,
|
|
|
|
'env' => $_ENV,
|
|
|
|
'cookies' => $_COOKIE,
|
|
|
|
'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
|
|
|
|
? $_SERVER['REQUEST_METHOD']
|
|
|
|
: null,
|
|
|
|
'params' => $params,
|
|
|
|
'urlParams' => $c['urlParams']
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
2013-09-17 19:46:33 +04:00
|
|
|
$this->registerService('PreviewManager', function($c) {
|
2013-09-05 01:45:11 +04:00
|
|
|
return new PreviewManager();
|
|
|
|
});
|
2013-09-17 19:46:33 +04:00
|
|
|
$this->registerService('RootFolder', function($c) {
|
2013-09-20 23:57:48 +04:00
|
|
|
// TODO: get user from container as well
|
2013-09-16 00:24:57 +04:00
|
|
|
$user = \OC_User::getUser();
|
2013-09-20 23:57:48 +04:00
|
|
|
/** @var $c SimpleContainer */
|
|
|
|
$userManager = $c->query('UserManager');
|
|
|
|
$user = $userManager->get($user);
|
2013-09-16 00:24:57 +04:00
|
|
|
$manager = \OC\Files\Filesystem::getMountManager();
|
|
|
|
$view = new View();
|
|
|
|
return new Root($manager, $view, $user);
|
|
|
|
});
|
2013-09-20 14:45:56 +04:00
|
|
|
$this->registerService('UserManager', function($c) {
|
|
|
|
return new \OC\User\Manager();
|
|
|
|
});
|
|
|
|
$this->registerService('UserSession', function($c) {
|
2013-09-20 23:57:48 +04:00
|
|
|
/** @var $c SimpleContainer */
|
2013-09-20 14:45:56 +04:00
|
|
|
$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;
|
|
|
|
});
|
2013-09-20 19:34:33 +04:00
|
|
|
$this->registerService('NavigationManager', function($c) {
|
|
|
|
return new \OC\NavigationManager();
|
|
|
|
});
|
2013-09-20 22:21:24 +04:00
|
|
|
$this->registerService('AllConfig', function($c) {
|
|
|
|
return new \OC\AllConfig();
|
|
|
|
});
|
2013-09-17 19:46:33 +04:00
|
|
|
$this->registerService('UserCache', function($c) {
|
|
|
|
return new UserCache();
|
|
|
|
});
|
2013-08-27 01:48:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-31 23:34:29 +04:00
|
|
|
* @return \OCP\Contacts\IManager
|
2013-08-27 01:48:18 +04:00
|
|
|
*/
|
|
|
|
function getContactsManager() {
|
|
|
|
return $this->query('ContactsManager');
|
|
|
|
}
|
2013-08-31 23:34:29 +04:00
|
|
|
|
|
|
|
/**
|
2013-09-17 19:46:33 +04:00
|
|
|
* The current request object holding all information about the request
|
|
|
|
* currently being processed is returned from this method.
|
2013-08-31 23:34:29 +04:00
|
|
|
* In case the current execution was not initiated by a web request null is returned
|
|
|
|
*
|
|
|
|
* @return \OCP\IRequest|null
|
|
|
|
*/
|
2013-09-17 19:46:33 +04:00
|
|
|
function getRequest() {
|
2013-08-31 23:34:29 +04:00
|
|
|
return $this->query('Request');
|
|
|
|
}
|
2013-09-05 01:45:11 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the preview manager which can create preview images for a given file
|
|
|
|
*
|
|
|
|
* @return \OCP\IPreview
|
|
|
|
*/
|
2013-09-17 19:46:33 +04:00
|
|
|
function getPreviewManager() {
|
2013-09-05 01:45:11 +04:00
|
|
|
return $this->query('PreviewManager');
|
|
|
|
}
|
2013-09-16 00:24:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the root folder of ownCloud's data directory
|
|
|
|
*
|
|
|
|
* @return \OCP\Files\Folder
|
|
|
|
*/
|
2013-09-17 19:46:33 +04:00
|
|
|
function getRootFolder() {
|
2013-09-16 00:24:57 +04:00
|
|
|
return $this->query('RootFolder');
|
|
|
|
}
|
2013-09-17 19:46:33 +04:00
|
|
|
|
2013-09-18 16:25:12 +04:00
|
|
|
/**
|
|
|
|
* Returns a view to ownCloud's files folder
|
|
|
|
*
|
|
|
|
* @return \OCP\Files\Folder
|
|
|
|
*/
|
|
|
|
function getUserFolder() {
|
|
|
|
|
|
|
|
$dir = '/files';
|
|
|
|
$root = $this->getRootFolder();
|
|
|
|
$folder = null;
|
|
|
|
if(!$root->nodeExists($dir)) {
|
|
|
|
$folder = $root->newFolder($dir);
|
|
|
|
} else {
|
|
|
|
$folder = $root->get($dir);
|
|
|
|
}
|
|
|
|
return $folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an app-specific view in ownClouds data directory
|
|
|
|
*
|
|
|
|
* @return \OCP\Files\Folder
|
|
|
|
*/
|
|
|
|
function getAppFolder() {
|
|
|
|
|
|
|
|
$dir = '/' . \OC_App::getCurrentApp();
|
|
|
|
$root = $this->getRootFolder();
|
|
|
|
$folder = null;
|
|
|
|
if(!$root->nodeExists($dir)) {
|
|
|
|
$folder = $root->newFolder($dir);
|
|
|
|
} else {
|
|
|
|
$folder = $root->get($dir);
|
|
|
|
}
|
|
|
|
return $folder;
|
|
|
|
}
|
|
|
|
|
2013-09-20 14:45:56 +04:00
|
|
|
/**
|
|
|
|
* @return \OC\User\Manager
|
|
|
|
*/
|
|
|
|
function getUserManager() {
|
|
|
|
return $this->query('UserManager');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \OC\User\Session
|
|
|
|
*/
|
|
|
|
function getUserSession() {
|
|
|
|
return $this->query('UserSession');
|
|
|
|
}
|
|
|
|
|
2013-09-20 19:34:33 +04:00
|
|
|
/**
|
|
|
|
* @return \OC\NavigationManager
|
|
|
|
*/
|
|
|
|
function getNavigationManager() {
|
|
|
|
return $this->query('NavigationManager');
|
|
|
|
}
|
|
|
|
|
2013-09-20 22:21:24 +04:00
|
|
|
/**
|
|
|
|
* @return \OC\Config
|
|
|
|
*/
|
|
|
|
function getConfig() {
|
|
|
|
return $this->query('AllConfig');
|
|
|
|
}
|
2013-09-24 02:09:21 +04:00
|
|
|
|
2013-09-17 19:46:33 +04:00
|
|
|
/**
|
|
|
|
* Returns an ICache instance
|
|
|
|
*
|
|
|
|
* @return \OCP\ICache
|
|
|
|
*/
|
|
|
|
function getCache() {
|
|
|
|
return $this->query('UserCache');
|
|
|
|
}
|
|
|
|
|
2013-09-17 20:31:14 +04:00
|
|
|
/**
|
|
|
|
* Returns the current session
|
|
|
|
*
|
|
|
|
* @return \OCP\ISession
|
|
|
|
*/
|
|
|
|
function getSession() {
|
|
|
|
return \OC::$session;
|
|
|
|
}
|
|
|
|
|
2013-09-20 16:33:45 +04:00
|
|
|
/**
|
|
|
|
* Returns the current session
|
|
|
|
*
|
|
|
|
* @return \OCP\IDBConnection
|
|
|
|
*/
|
|
|
|
function getDatabaseConnection() {
|
|
|
|
return \OC_DB::getConnection();
|
|
|
|
}
|
2013-08-21 02:58:15 +04:00
|
|
|
}
|