summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-18 22:36:25 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-18 22:36:25 +0200
commit690e98d45afc46b69df0559dce1ed9da85091e1d (patch)
tree55bb45c2aadf78b304cbf3560651466dd9fb0efa /lib
parentb0762ad3bf5121ccd300ec6c22641c3bf323ba61 (diff)
parent69c28400b47a3a16ead6fc0d5ee5e2212d0d8ab0 (diff)
downloadnextcloud-server-690e98d45afc46b69df0559dce1ed9da85091e1d.tar.gz
nextcloud-server-690e98d45afc46b69df0559dce1ed9da85091e1d.zip
Merge branch 'appframework-master' into vcategories_public
Conflicts: lib/server.php
Diffstat (limited to 'lib')
-rw-r--r--lib/appframework/controller/controller.php10
-rw-r--r--lib/appframework/http/request.php51
-rw-r--r--lib/base.php6
-rw-r--r--lib/cache.php23
-rw-r--r--lib/cache/broker.php12
-rw-r--r--lib/cache/file.php13
-rw-r--r--lib/cache/fileglobal.php9
-rw-r--r--lib/cache/fileglobalgc.php5
-rw-r--r--lib/cache/usercache.php77
-rw-r--r--lib/filechunking.php2
-rw-r--r--lib/legacy/cache.php10
-rw-r--r--lib/public/icache.php55
-rw-r--r--lib/public/irequest.php9
-rw-r--r--lib/public/iservercontainer.php14
-rw-r--r--lib/public/isession.php56
-rw-r--r--lib/server.php51
-rw-r--r--lib/session/session.php2
17 files changed, 311 insertions, 94 deletions
diff --git a/lib/appframework/controller/controller.php b/lib/appframework/controller/controller.php
index a7498ba0e1e..0ea0a38cc09 100644
--- a/lib/appframework/controller/controller.php
+++ b/lib/appframework/controller/controller.php
@@ -107,16 +107,6 @@ abstract class Controller {
/**
- * Shortcut for getting session variables
- * @param string $key the key that will be taken from the $_SESSION array
- * @return array the value in the $_SESSION element
- */
- public function session($key) {
- return $this->request->getSession($key);
- }
-
-
- /**
* Shortcut for getting cookie variables
* @param string $key the key that will be taken from the $_COOKIE array
* @return array the value in the $_COOKIE element
diff --git a/lib/appframework/http/request.php b/lib/appframework/http/request.php
index 4f1775182a1..34605acdfea 100644
--- a/lib/appframework/http/request.php
+++ b/lib/appframework/http/request.php
@@ -33,16 +33,15 @@ class Request implements \ArrayAccess, \Countable, IRequest {
protected $items = array();
protected $allowedKeys = array(
- 'get',
- 'post',
- 'files',
- 'server',
- 'env',
- 'session',
- 'cookies',
- 'urlParams',
- 'params',
- 'parameters',
+ 'get',
+ 'post',
+ 'files',
+ 'server',
+ 'env',
+ 'cookies',
+ 'urlParams',
+ 'params',
+ 'parameters',
'method'
);
@@ -156,7 +155,6 @@ class Request implements \ArrayAccess, \Countable, IRequest {
case 'files':
case 'server':
case 'env':
- case 'session':
case 'cookies':
case 'parameters':
case 'params':
@@ -229,8 +227,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* @param mixed $default If the key is not found, this value will be returned
* @return mixed the content of the array
*/
- public function getParam($key, $default = null)
- {
+ public function getParam($key, $default = null) {
return isset($this->parameters[$key])
? $this->parameters[$key]
: $default;
@@ -241,8 +238,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* (as GET or POST) or throuh the URL by the route
* @return array the array with all parameters
*/
- public function getParams()
- {
+ public function getParams() {
return $this->parameters;
}
@@ -250,8 +246,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* Returns the method of the request
* @return string the method of the request (POST, GET, etc)
*/
- public function getMethod()
- {
+ public function getMethod() {
return $this->method;
}
@@ -260,8 +255,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* @param string $key the key that will be taken from the $_FILES array
* @return array the file in the $_FILES element
*/
- public function getUploadedFile($key)
- {
+ public function getUploadedFile($key) {
return isset($this->files[$key]) ? $this->files[$key] : null;
}
@@ -270,28 +264,16 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* @param string $key the key that will be taken from the $_ENV array
* @return array the value in the $_ENV element
*/
- public function getEnv($key)
- {
+ public function getEnv($key) {
return isset($this->env[$key]) ? $this->env[$key] : null;
}
/**
- * Shortcut for getting session variables
- * @param string $key the key that will be taken from the $_SESSION array
- * @return array the value in the $_SESSION element
- */
- function getSession($key)
- {
- return isset($this->session[$key]) ? $this->session[$key] : null;
- }
-
- /**
* Shortcut for getting cookie variables
* @param string $key the key that will be taken from the $_COOKIE array
* @return array the value in the $_COOKIE element
*/
- function getCookie($key)
- {
+ function getCookie($key) {
return isset($this->cookies[$key]) ? $this->cookies[$key] : null;
}
@@ -304,8 +286,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
*
* @throws \LogicException
*/
- function getContent($asResource = false)
- {
+ function getContent($asResource = false) {
return null;
// if (false === $this->content || (true === $asResource && null !== $this->content)) {
// throw new \LogicException('getContent() can only be called once when using the resource return type.');
diff --git a/lib/base.php b/lib/base.php
index 1720a5fd7e1..0650361be91 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -564,11 +564,13 @@ class OC {
if (OC_Config::getValue('installed', false)) { //don't try to do this before we are properly setup
// register cache cleanup jobs
try { //if this is executed before the upgrade to the new backgroundjob system is completed it will throw an exception
- \OCP\BackgroundJob::registerJob('OC_Cache_FileGlobalGC');
+ \OCP\BackgroundJob::registerJob('OC\Cache\FileGlobalGC');
} catch (Exception $e) {
}
- OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener');
+ // NOTE: This will be replaced to use OCP
+ $userSession = \OC_User::getUserSession();
+ $userSession->listen('postLogin', '\OC\Cache\File', 'loginListener');
}
}
diff --git a/lib/cache.php b/lib/cache.php
index 48b9964ba9d..a311f10a00f 100644
--- a/lib/cache.php
+++ b/lib/cache.php
@@ -6,34 +6,36 @@
* See the COPYING-README file.
*/
-class OC_Cache {
+namespace OC;
+
+class Cache {
/**
- * @var OC_Cache $user_cache
+ * @var Cache $user_cache
*/
static protected $user_cache;
/**
- * @var OC_Cache $global_cache
+ * @var Cache $global_cache
*/
static protected $global_cache;
/**
* get the global cache
- * @return OC_Cache
+ * @return Cache
*/
static public function getGlobalCache() {
if (!self::$global_cache) {
- self::$global_cache = new OC_Cache_FileGlobal();
+ self::$global_cache = new Cache\FileGlobal();
}
return self::$global_cache;
}
/**
* get the user cache
- * @return OC_Cache
+ * @return Cache
*/
static public function getUserCache() {
if (!self::$user_cache) {
- self::$user_cache = new OC_Cache_File();
+ self::$user_cache = new Cache\File();
}
return self::$user_cache;
}
@@ -85,7 +87,7 @@ class OC_Cache {
/**
* clear the user cache of all entries starting with a prefix
- * @param string prefix (optional)
+ * @param string $prefix (optional)
* @return bool
*/
static public function clear($prefix='') {
@@ -93,6 +95,11 @@ class OC_Cache {
return $user_cache->clear($prefix);
}
+ /**
+ * creates cache key based on the files given
+ * @param $files
+ * @return string
+ */
static public function generateCacheKeyFromFiles($files) {
$key = '';
sort($files);
diff --git a/lib/cache/broker.php b/lib/cache/broker.php
index a161dbfa3bb..9b7e837e1bc 100644
--- a/lib/cache/broker.php
+++ b/lib/cache/broker.php
@@ -6,8 +6,18 @@
* See the COPYING-README file.
*/
-class OC_Cache_Broker {
+namespace OC\Cache;
+
+class Broker {
+
+ /**
+ * @var \OC\Cache
+ */
protected $fast_cache;
+
+ /**
+ * @var \OC\Cache
+ */
protected $slow_cache;
public function __construct($fast_cache, $slow_cache) {
diff --git a/lib/cache/file.php b/lib/cache/file.php
index 361138e4736..2ab914d17b8 100644
--- a/lib/cache/file.php
+++ b/lib/cache/file.php
@@ -6,24 +6,25 @@
* See the COPYING-README file.
*/
+namespace OC\Cache;
-class OC_Cache_File{
+class File {
protected $storage;
protected function getStorage() {
if (isset($this->storage)) {
return $this->storage;
}
- if(OC_User::isLoggedIn()) {
- \OC\Files\Filesystem::initMountPoints(OC_User::getUser());
+ if(\OC_User::isLoggedIn()) {
+ \OC\Files\Filesystem::initMountPoints(\OC_User::getUser());
$subdir = 'cache';
- $view = new \OC\Files\View('/'.OC_User::getUser());
+ $view = new \OC\Files\View('/' . \OC_User::getUser());
if(!$view->file_exists($subdir)) {
$view->mkdir($subdir);
}
- $this->storage = new \OC\Files\View('/'.OC_User::getUser().'/'.$subdir);
+ $this->storage = new \OC\Files\View('/' . \OC_User::getUser().'/'.$subdir);
return $this->storage;
}else{
- OC_Log::write('core', 'Can\'t get cache storage, user not logged in', OC_Log::ERROR);
+ \OC_Log::write('core', 'Can\'t get cache storage, user not logged in', \OC_Log::ERROR);
return false;
}
}
diff --git a/lib/cache/fileglobal.php b/lib/cache/fileglobal.php
index c0bd8e45f39..bd049bba4d0 100644
--- a/lib/cache/fileglobal.php
+++ b/lib/cache/fileglobal.php
@@ -6,10 +6,11 @@
* See the COPYING-README file.
*/
+namespace OC\Cache;
-class OC_Cache_FileGlobal{
+class FileGlobal {
static protected function getCacheDir() {
- $cache_dir = get_temp_dir().'/owncloud-'.OC_Util::getInstanceId().'/';
+ $cache_dir = get_temp_dir().'/owncloud-' . \OC_Util::getInstanceId().'/';
if (!is_dir($cache_dir)) {
mkdir($cache_dir);
}
@@ -80,13 +81,13 @@ class OC_Cache_FileGlobal{
}
static public function gc() {
- $last_run = OC_AppConfig::getValue('core', 'global_cache_gc_lastrun', 0);
+ $last_run = \OC_AppConfig::getValue('core', 'global_cache_gc_lastrun', 0);
$now = time();
if (($now - $last_run) < 300) {
// only do cleanup every 5 minutes
return;
}
- OC_AppConfig::setValue('core', 'global_cache_gc_lastrun', $now);
+ \OC_AppConfig::setValue('core', 'global_cache_gc_lastrun', $now);
$cache_dir = self::getCacheDir();
if($cache_dir and is_dir($cache_dir)) {
$dh=opendir($cache_dir);
diff --git a/lib/cache/fileglobalgc.php b/lib/cache/fileglobalgc.php
index a29c31f9063..399dd5e6f94 100644
--- a/lib/cache/fileglobalgc.php
+++ b/lib/cache/fileglobalgc.php
@@ -1,8 +1,9 @@
<?php
+namespace OC\Cache;
-class OC_Cache_FileGlobalGC extends \OC\BackgroundJob\Job{
+class FileGlobalGC extends \OC\BackgroundJob\Job{
public function run($argument){
- OC_Cache_FileGlobal::gc();
+ FileGlobal::gc();
}
}
diff --git a/lib/cache/usercache.php b/lib/cache/usercache.php
new file mode 100644
index 00000000000..baa8820700b
--- /dev/null
+++ b/lib/cache/usercache.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Cache;
+
+/**
+ * This interface defines method for accessing the file based user cache.
+ */
+class UserCache implements \OCP\ICache {
+
+ /**
+ * @var \OC\Cache\File $userCache
+ */
+ protected $userCache;
+
+ public function __construct() {
+ $this->userCache = new File();
+ }
+
+ /**
+ * Get a value from the user cache
+ *
+ * @param string $key
+ * @return mixed
+ */
+ public function get($key) {
+ return $this->userCache->get($key);
+ }
+
+ /**
+ * Set a value in the user cache
+ *
+ * @param string $key
+ * @param mixed $value
+ * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
+ * @return bool
+ */
+ public function set($key, $value, $ttl = 0) {
+ if (empty($key)) {
+ return false;
+ }
+ return $this->userCache->set($key, $value, $ttl);
+ }
+
+ /**
+ * Check if a value is set in the user cache
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function hasKey($key) {
+ return $this->userCache->hasKey($key);
+ }
+
+ /**
+ * Remove an item from the user cache
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function remove($key) {
+ return $this->userCache->remove($key);
+ }
+
+ /**
+ * clear the user cache of all entries starting with a prefix
+ * @param string $prefix (optional)
+ * @return bool
+ */
+ public function clear($prefix = '') {
+ return $this->userCache->clear($prefix);
+ }
+}
diff --git a/lib/filechunking.php b/lib/filechunking.php
index e6d69273a44..313a6ee87d2 100644
--- a/lib/filechunking.php
+++ b/lib/filechunking.php
@@ -29,7 +29,7 @@ class OC_FileChunking {
protected function getCache() {
if (!isset($this->cache)) {
- $this->cache = new OC_Cache_File();
+ $this->cache = new \OC\Cache\File();
}
return $this->cache;
}
diff --git a/lib/legacy/cache.php b/lib/legacy/cache.php
new file mode 100644
index 00000000000..f915eb516b1
--- /dev/null
+++ b/lib/legacy/cache.php
@@ -0,0 +1,10 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class OC_Cache extends \OC\Cache {
+} \ No newline at end of file
diff --git a/lib/public/icache.php b/lib/public/icache.php
new file mode 100644
index 00000000000..436ee71b2b9
--- /dev/null
+++ b/lib/public/icache.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OCP;
+
+/**
+ * This interface defines method for accessing the file based user cache.
+ */
+interface ICache {
+
+ /**
+ * Get a value from the user cache
+ *
+ * @param string $key
+ * @return mixed
+ */
+ public function get($key);
+
+ /**
+ * Set a value in the user cache
+ *
+ * @param string $key
+ * @param mixed $value
+ * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
+ * @return bool
+ */
+ public function set($key, $value, $ttl = 0);
+
+ /**
+ * Check if a value is set in the user cache
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function hasKey($key);
+
+ /**
+ * Remove an item from the user cache
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function remove($key);
+
+ /**
+ * clear the user cache of all entries starting with a prefix
+ * @param string $prefix (optional)
+ * @return bool
+ */
+ public function clear($prefix = '');
+}
diff --git a/lib/public/irequest.php b/lib/public/irequest.php
index cd39855950b..9f335b06f2a 100644
--- a/lib/public/irequest.php
+++ b/lib/public/irequest.php
@@ -77,15 +77,6 @@ interface IRequest {
/**
- * Shortcut for getting session variables
- *
- * @param string $key the key that will be taken from the $_SESSION array
- * @return array the value in the $_SESSION element
- */
- function getSession($key);
-
-
- /**
* Shortcut for getting cookie variables
*
* @param string $key the key that will be taken from the $_COOKIE array
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index e44acee6533..a9c49a78737 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -69,4 +69,18 @@ interface IServerContainer {
*/
function getRootFolder();
+ /**
+ * Returns an ICache instance
+ *
+ * @return \OCP\ICache
+ */
+ function getCache();
+
+ /**
+ * Returns the current session
+ *
+ * @return \OCP\ISession
+ */
+ function getSession();
+
}
diff --git a/lib/public/isession.php b/lib/public/isession.php
new file mode 100644
index 00000000000..0a77b0c823b
--- /dev/null
+++ b/lib/public/isession.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
+ * @author Thomas Tanghus
+ * @author Robin Appelman
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP;
+
+/**
+ * Interface ISession
+ *
+ * wrap PHP's internal session handling into the ISession interface
+ */
+interface ISession {
+
+ /**
+ * Set a value in the session
+ *
+ * @param string $key
+ * @param mixed $value
+ */
+ public function set($key, $value);
+
+ /**
+ * Get a value from the session
+ *
+ * @param string $key
+ * @return mixed should return null if $key does not exist
+ */
+ public function get($key);
+
+ /**
+ * Check if a named key exists in the session
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function exists($key);
+
+ /**
+ * Remove a $key/$value pair from the session
+ *
+ * @param string $key
+ */
+ public function remove($key);
+
+ /**
+ * Reset and recreate the session
+ */
+ public function clear();
+
+}
diff --git a/lib/server.php b/lib/server.php
index f25216b746d..e97bc296ca0 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;
@@ -17,10 +18,10 @@ use OCP\IServerContainer;
class Server extends SimpleContainer implements IServerContainer {
function __construct() {
- $this->registerService('ContactsManager', function($c){
+ $this->registerService('ContactsManager', function($c) {
return new ContactsManager();
});
- $this->registerService('Request', function($c){
+ $this->registerService('Request', function($c) {
$params = array();
// we json decode the body only in case of content type json
@@ -36,7 +37,6 @@ class Server extends SimpleContainer implements IServerContainer {
'files' => $_FILES,
'server' => $_SERVER,
'env' => $_ENV,
- 'session' => $_SESSION,
'cookies' => $_COOKIE,
'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
? $_SERVER['REQUEST_METHOD']
@@ -46,13 +46,15 @@ class Server extends SimpleContainer implements IServerContainer {
)
);
});
- $this->registerService('PreviewManager', function($c){
+ $this->registerService('PreviewManager', function($c) {
return new PreviewManager();
});
- $this->registerService('TagManager', function($c){
- return new Tags();
+ $this->registerService('TagManager', function($c) {
+ // TODO: get user and user manager from container as well
+ $user = \OC_User::getUser();
+ return new Tags($user);
});
- $this->registerService('RootFolder', function($c){
+ $this->registerService('RootFolder', function($c) {
// TODO: get user and user manager from container as well
$user = \OC_User::getUser();
$user = \OC_User::getManager()->get($user);
@@ -60,6 +62,9 @@ class Server extends SimpleContainer implements IServerContainer {
$view = new View();
return new Root($manager, $view, $user);
});
+ $this->registerService('UserCache', function($c) {
+ return new UserCache();
+ });
}
/**
@@ -70,14 +75,13 @@ class Server extends SimpleContainer implements IServerContainer {
}
/**
- * The current request object holding all information about the request currently being processed
- * is returned from this method.
+ * The current request object holding all information about the request
+ * currently being processed is returned from this method.
* In case the current execution was not initiated by a web request null is returned
*
* @return \OCP\IRequest|null
*/
- function getRequest()
- {
+ function getRequest() {
return $this->query('Request');
}
@@ -86,8 +90,7 @@ class Server extends SimpleContainer implements IServerContainer {
*
* @return \OCP\IPreview
*/
- function getPreviewManager()
- {
+ function getPreviewManager() {
return $this->query('PreviewManager');
}
@@ -105,8 +108,26 @@ class Server extends SimpleContainer implements IServerContainer {
*
* @return \OCP\Files\Folder
*/
- function getRootFolder()
- {
+ function getRootFolder() {
return $this->query('RootFolder');
}
+
+ /**
+ * Returns an ICache instance
+ *
+ * @return \OCP\ICache
+ */
+ function getCache() {
+ return $this->query('UserCache');
+ }
+
+ /**
+ * Returns the current session
+ *
+ * @return \OCP\ISession
+ */
+ function getSession() {
+ return \OC::$session;
+ }
+
}
diff --git a/lib/session/session.php b/lib/session/session.php
index 55515f57a87..c55001eccac 100644
--- a/lib/session/session.php
+++ b/lib/session/session.php
@@ -8,7 +8,7 @@
namespace OC\Session;
-abstract class Session implements \ArrayAccess {
+abstract class Session implements \ArrayAccess, \OCP\ISession {
/**
* $name serves as a namespace for the session keys
*