diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 8 | ||||
-rw-r--r-- | lib/private/appframework/core/api.php | 164 | ||||
-rw-r--r-- | lib/private/appframework/dependencyinjection/dicontainer.php | 52 | ||||
-rw-r--r-- | lib/private/appframework/http/dispatcher.php | 2 | ||||
-rw-r--r-- | lib/private/appframework/middleware/middlewaredispatcher.php | 2 | ||||
-rw-r--r-- | lib/private/appframework/middleware/security/securitymiddleware.php | 34 | ||||
-rw-r--r-- | lib/private/apphelper.php (renamed from lib/apphelper.php) | 0 | ||||
-rw-r--r-- | lib/private/helper.php | 2 | ||||
-rw-r--r-- | lib/private/l10n/factory.php | 2 | ||||
-rw-r--r-- | lib/private/server.php | 3 | ||||
-rw-r--r-- | lib/private/urlgenerator.php (renamed from lib/urlgenerator.php) | 18 | ||||
-rw-r--r-- | lib/public/appframework/controller.php (renamed from lib/private/appframework/controller/controller.php) | 23 | ||||
-rw-r--r-- | lib/public/appframework/http/templateresponse.php | 18 | ||||
-rw-r--r-- | lib/public/appframework/iapi.php | 73 | ||||
-rw-r--r-- | lib/public/appframework/iappcontainer.php | 22 | ||||
-rw-r--r-- | lib/public/appframework/middleware.php | 1 |
16 files changed, 125 insertions, 299 deletions
diff --git a/lib/base.php b/lib/base.php index 9068fe76981..7bebb5f93a0 100644 --- a/lib/base.php +++ b/lib/base.php @@ -69,8 +69,9 @@ class OC { * check if owncloud runs in cli mode */ public static $CLI = false; - /* - * OC router + + /** + * @var OC_Router */ protected static $router = null; @@ -343,6 +344,9 @@ class OC { return OC_Config::getValue('session_lifetime', 60 * 60 * 24); } + /** + * @return OC_Router + */ public static function getRouter() { if (!isset(OC::$router)) { OC::$router = new OC_Router(); diff --git a/lib/private/appframework/core/api.php b/lib/private/appframework/core/api.php index 39522ee3dd5..e7269373bb0 100644 --- a/lib/private/appframework/core/api.php +++ b/lib/private/appframework/core/api.php @@ -100,89 +100,6 @@ class API implements IApi{ /** - * Returns the translation object - * @return \OC_L10N the translation object - */ - public function getTrans(){ - # TODO: use public api - return \OC_L10N::get($this->appName); - } - - - /** - * Returns the URL for a route - * @param string $routeName the name of the route - * @param array $arguments an array with arguments which will be filled into the url - * @return string the url - */ - public function linkToRoute($routeName, $arguments=array()){ - return \OCP\Util::linkToRoute($routeName, $arguments); - } - - - /** - * Returns an URL for an image or file - * @param string $file the name of the file - * @param string $appName the name of the app, defaults to the current one - */ - public function linkTo($file, $appName=null){ - if($appName === null){ - $appName = $this->appName; - } - return \OCP\Util::linkTo($appName, $file); - } - - - /** - * Returns the link to an image, like link to but only with prepending img/ - * @param string $file the name of the file - * @param string $appName the name of the app, defaults to the current one - */ - public function imagePath($file, $appName=null){ - if($appName === null){ - $appName = $this->appName; - } - return \OCP\Util::imagePath($appName, $file); - } - - - /** - * Makes an URL absolute - * @param string $url the url - * @return string the absolute url - */ - public function getAbsoluteURL($url){ - # TODO: use public api - return \OC_Helper::makeURLAbsolute($url); - } - - - /** - * links to a file - * @param string $file the name of the file - * @param string $appName the name of the app, defaults to the current one - * @deprecated replaced with linkToRoute() - * @return string the url - */ - public function linkToAbsolute($file, $appName=null){ - if($appName === null){ - $appName = $this->appName; - } - return \OCP\Util::linkToAbsolute($appName, $file); - } - - - /** - * Checks if the CSRF check was correct - * @return bool true if CSRF check passed - */ - public function passesCSRFCheck(){ - # TODO: use public api - return \OC_Util::isCallRegistered(); - } - - - /** * Checks if an app is enabled * @param string $appName the name of an app * @return bool true if app is enabled @@ -193,44 +110,6 @@ class API implements IApi{ /** - * Writes a function into the error log - * @param string $msg the error message to be logged - * @param int $level the error level - */ - public function log($msg, $level=null){ - switch($level){ - case 'debug': - $level = \OCP\Util::DEBUG; - break; - case 'info': - $level = \OCP\Util::INFO; - break; - case 'warn': - $level = \OCP\Util::WARN; - break; - case 'fatal': - $level = \OCP\Util::FATAL; - break; - default: - $level = \OCP\Util::ERROR; - break; - } - \OCP\Util::writeLog($this->appName, $msg, $level); - } - - - /** - * turns an owncloud path into a path on the filesystem - * @param string path the path to the file on the oc filesystem - * @return string the filepath in the filesystem - */ - public function getLocalFilePath($path){ - # TODO: use public api - return \OC_Filesystem::getLocalFile($path); - } - - - /** * used to return and open a new eventsource * @return \OC_EventSource a new open EventSource class */ @@ -275,15 +154,6 @@ class API implements IApi{ } } - /** - * Gets the content of an URL by using CURL or a fallback if it is not - * installed - * @param string $url the url that should be fetched - * @return string the content of the webpage - */ - public function getUrlContent($url) { - return \OC_Util::getUrlContent($url); - } /** * Register a backgroundjob task @@ -295,25 +165,6 @@ class API implements IApi{ \OCP\Backgroundjob::addRegularTask($className, $methodName); } - /** - * Returns a template - * @param string $templateName the name of the template - * @param string $renderAs how it should be rendered - * @param string $appName the name of the app - * @return \OCP\Template a new template - */ - public function getTemplate($templateName, $renderAs='user', $appName=null){ - if($appName === null){ - $appName = $this->appName; - } - - if($renderAs === 'blank'){ - return new \OCP\Template($appName, $templateName); - } else { - return new \OCP\Template($appName, $templateName, $renderAs); - } - } - /** * Tells ownCloud to include a template in the admin overview @@ -330,19 +181,4 @@ class API implements IApi{ } - /** - * get the filesystem info - * - * @param string $path - * @return array with the following keys: - * - size - * - mtime - * - mimetype - * - encrypted - * - versioned - */ - public function getFileInfo($path) { - return \OC\Files\Filesystem::getFileInfo($path); - } - } diff --git a/lib/private/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php index 523a4153e01..81910df6990 100644 --- a/lib/private/appframework/dependencyinjection/dicontainer.php +++ b/lib/private/appframework/dependencyinjection/dicontainer.php @@ -35,6 +35,7 @@ use OC\AppFramework\Utility\TimeFactory; use OCP\AppFramework\IApi; use OCP\AppFramework\IAppContainer; use OCP\AppFramework\IMiddleWare; +use OCP\AppFramework\Middleware; use OCP\IServerContainer; @@ -88,7 +89,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{ * Middleware */ $this['SecurityMiddleware'] = $this->share(function($c){ - return new SecurityMiddleware($c['API'], $c['Request']); + return new SecurityMiddleware($this, $c['Request']); }); $middleWares = $this->middleWares; @@ -132,10 +133,10 @@ class DIContainer extends SimpleContainer implements IAppContainer{ } /** - * @param IMiddleWare $middleWare + * @param Middleware $middleWare * @return boolean */ - function registerMiddleWare(IMiddleWare $middleWare) { + function registerMiddleWare(Middleware $middleWare) { array_push($this->middleWares, $middleWare); } @@ -146,4 +147,49 @@ class DIContainer extends SimpleContainer implements IAppContainer{ function getAppName() { return $this->query('AppName'); } + + /** + * @return boolean + */ + function isLoggedIn() { + return \OC_User::isLoggedIn(); + } + + /** + * @return boolean + */ + function isAdminUser() { + $uid = $this->getUserId(); + return \OC_User::isAdminUser($uid); + } + + private function getUserId() { + return \OC::$session->get('user_id'); + } + + /** + * @param $message + * @param $level + * @return mixed + */ + function log($message, $level) { + switch($level){ + case 'debug': + $level = \OCP\Util::DEBUG; + break; + case 'info': + $level = \OCP\Util::INFO; + break; + case 'warn': + $level = \OCP\Util::WARN; + break; + case 'fatal': + $level = \OCP\Util::FATAL; + break; + default: + $level = \OCP\Util::ERROR; + break; + } + \OCP\Util::writeLog($this->getAppName(), $message, $level); + } } diff --git a/lib/private/appframework/http/dispatcher.php b/lib/private/appframework/http/dispatcher.php index ea57a6860cc..51283fd64e7 100644 --- a/lib/private/appframework/http/dispatcher.php +++ b/lib/private/appframework/http/dispatcher.php @@ -24,8 +24,8 @@ namespace OC\AppFramework\Http; -use \OC\AppFramework\Controller\Controller; use \OC\AppFramework\Middleware\MiddlewareDispatcher; +use OCP\AppFramework\Controller; /** diff --git a/lib/private/appframework/middleware/middlewaredispatcher.php b/lib/private/appframework/middleware/middlewaredispatcher.php index c2377b8844b..681140c2242 100644 --- a/lib/private/appframework/middleware/middlewaredispatcher.php +++ b/lib/private/appframework/middleware/middlewaredispatcher.php @@ -24,7 +24,7 @@ namespace OC\AppFramework\Middleware; -use OC\AppFramework\Controller\Controller; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; use OCP\AppFramework\MiddleWare; diff --git a/lib/private/appframework/middleware/security/securitymiddleware.php b/lib/private/appframework/middleware/security/securitymiddleware.php index d6dbcb6b8be..f103a40ee7f 100644 --- a/lib/private/appframework/middleware/security/securitymiddleware.php +++ b/lib/private/appframework/middleware/security/securitymiddleware.php @@ -24,15 +24,14 @@ namespace OC\AppFramework\Middleware\Security; -use OC\AppFramework\Controller\Controller; use OC\AppFramework\Http\Http; -use OC\AppFramework\Http\Request; use OC\AppFramework\Http\RedirectResponse; use OC\AppFramework\Utility\MethodAnnotationReader; -use OC\AppFramework\Core\API; use OCP\AppFramework\Middleware; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\IAppContainer; +use OCP\IRequest; /** @@ -43,18 +42,22 @@ use OCP\AppFramework\Http\JSONResponse; */ class SecurityMiddleware extends Middleware { - private $api; + /** + * @var \OCP\AppFramework\IAppContainer + */ + private $app; /** - * @var \OC\AppFramework\Http\Request + * @var \OCP\IRequest */ private $request; /** - * @param API $api an instance of the api + * @param IAppContainer $app + * @param IRequest $request */ - public function __construct(API $api, Request $request){ - $this->api = $api; + public function __construct(IAppContainer $app, IRequest $request){ + $this->app = $app; $this->request = $request; } @@ -74,24 +77,24 @@ class SecurityMiddleware extends Middleware { // this will set the current navigation entry of the app, use this only // for normal HTML requests and not for AJAX requests - //$this->api->activateNavigationEntry(); + $this->app->getServer()->getNavigationManager()->setActiveEntry($this->app->getAppName()); // security checks $isPublicPage = $annotationReader->hasAnnotation('PublicPage'); if(!$isPublicPage) { - if(!\OC_User::isLoggedIn()) { + if(!$this->app->isLoggedIn()) { throw new SecurityException('Current user is not logged in', Http::STATUS_UNAUTHORIZED); } if(!$annotationReader->hasAnnotation('NoAdminRequired')) { - if(!$this->api->isAdminUser($this->api->getUserId())) { + if(!$this->app->isAdminUser()) { throw new SecurityException('Logged in user must be an admin', Http::STATUS_FORBIDDEN); } } } if(!$annotationReader->hasAnnotation('NoCSRFRequired')) { - if(!$this->api->passesCSRFCheck()) { + if(!$this->request->passesCSRFCheck()) { throw new SecurityException('CSRF check failed', Http::STATUS_PRECONDITION_FAILED); } } @@ -118,12 +121,13 @@ class SecurityMiddleware extends Middleware { array('message' => $exception->getMessage()), $exception->getCode() ); - $this->api->log($exception->getMessage(), 'debug'); + $this->app->log($exception->getMessage(), 'debug'); } else { - $url = $this->api->linkToAbsolute('index.php', ''); // TODO: replace with link to route + // TODO: replace with link to route + $url = $this->app->getServer()->getURLGenerator()->getAbsoluteURL('index.php'); $response = new RedirectResponse($url); - $this->api->log($exception->getMessage(), 'debug'); + $this->app->log($exception->getMessage(), 'debug'); } return $response; diff --git a/lib/apphelper.php b/lib/private/apphelper.php index bd02f3aabfa..bd02f3aabfa 100644 --- a/lib/apphelper.php +++ b/lib/private/apphelper.php diff --git a/lib/private/helper.php b/lib/private/helper.php index 1236e748256..e9b129db0ca 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -81,7 +81,7 @@ class OC_Helper { * Returns a absolute url to the given app and file. */ public static function makeURLAbsolute($url) { - return OC::$server->getURLGenerator()->makeURLAbsolute($url); + return OC::$server->getURLGenerator()->getAbsoluteURL($url); } /** diff --git a/lib/private/l10n/factory.php b/lib/private/l10n/factory.php index ba168872acd..8c65f368171 100644 --- a/lib/private/l10n/factory.php +++ b/lib/private/l10n/factory.php @@ -22,7 +22,7 @@ class Factory { * get an L10N instance * @param $app string * @param $lang string|null - * @return OC_L10N + * @return \OC_L10N */ public function get($app) { if (!isset($this->instances[$app])) { diff --git a/lib/private/server.php b/lib/private/server.php index 73a0cbd6ce6..e55f59f6a1c 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -34,7 +34,6 @@ class Server extends SimpleContainer implements IServerContainer { $requesttoken = false; } - return new Request( array( 'get' => $_GET, @@ -46,7 +45,6 @@ class Server extends SimpleContainer implements IServerContainer { 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) ? $_SERVER['REQUEST_METHOD'] : null, - 'params' => $params, 'urlParams' => $urlParams, 'requesttoken' => $requesttoken, ) @@ -290,4 +288,5 @@ class Server extends SimpleContainer implements IServerContainer { function getDatabaseConnection() { return \OC_DB::getConnection(); } + } diff --git a/lib/urlgenerator.php b/lib/private/urlgenerator.php index 1db4c36cc58..5c1d9d825b6 100644 --- a/lib/urlgenerator.php +++ b/lib/private/urlgenerator.php @@ -8,18 +8,20 @@ */ namespace OC; +use OCP\IURLGenerator; +use RuntimeException; /** * Class to generate URLs */ -class URLGenerator { +class URLGenerator implements IURLGenerator { /** * @brief Creates an url using a defined route * @param $route * @param array $parameters * @return * @internal param array $args with param=>value, will be appended to the returned url - * @returns the url + * @returns string the url * * Returns a url to the given app and file. */ @@ -97,15 +99,13 @@ class URLGenerator { } } + /** - * @brief Makes an $url absolute - * @param string $url the url - * @return string the absolute url - * - * Returns a absolute url to the given app and file. + * Makes an URL absolute + * @param string $url the url in the owncloud host + * @return string the absolute version of the url */ - public function makeURLAbsolute($url) { + public function getAbsoluteURL($url) { return \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . $url; } - } diff --git a/lib/private/appframework/controller/controller.php b/lib/public/appframework/controller.php index 0ea0a38cc09..1642b508572 100644 --- a/lib/private/appframework/controller/controller.php +++ b/lib/public/appframework/controller.php @@ -22,11 +22,11 @@ */ -namespace OC\AppFramework\Controller; +namespace OCP\AppFramework; -use OC\AppFramework\Http\Request; -use OC\AppFramework\Core\API; use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\IAppContainer; +use OCP\IRequest; /** @@ -35,18 +35,21 @@ use OCP\AppFramework\Http\TemplateResponse; abstract class Controller { /** - * @var API instance of the api layer + * @var \OCP\AppFramework\IAppContainer */ - protected $api; + protected $app; + /** + * @var \OCP\IRequest + */ protected $request; /** - * @param API $api an api wrapper instance - * @param Request $request an instance of the request + * @param IAppContainer $app interface to the app + * @param IRequest $request an instance of the request */ - public function __construct(API $api, Request $request){ - $this->api = $api; + public function __construct(IAppContainer $app, IRequest $request){ + $this->app = $app; $this->request = $request; } @@ -127,7 +130,7 @@ abstract class Controller { */ public function render($templateName, array $params=array(), $renderAs='user', array $headers=array()){ - $response = new TemplateResponse($this->api, $templateName); + $response = new TemplateResponse($this->app->getAppName(), $templateName); $response->setParams($params); $response->renderAs($renderAs); diff --git a/lib/public/appframework/http/templateresponse.php b/lib/public/appframework/http/templateresponse.php index 97678c96cba..594530651aa 100644 --- a/lib/public/appframework/http/templateresponse.php +++ b/lib/public/appframework/http/templateresponse.php @@ -24,8 +24,6 @@ namespace OCP\AppFramework\Http; -use OC\AppFramework\Core\API; - /** * Response for a normal template @@ -34,20 +32,16 @@ class TemplateResponse extends Response { protected $templateName; protected $params; - protected $api; protected $renderAs; protected $appName; /** - * @param API $api an API instance * @param string $templateName the name of the template - * @param string $appName optional if you want to include a template from - * a different app + * @param string $appName the name of the app to load the template from */ - public function __construct(API $api, $templateName, $appName=null) { + public function __construct($appName, $templateName) { $this->templateName = $templateName; $this->appName = $appName; - $this->api = $api; $this->params = array(); $this->renderAs = 'user'; } @@ -108,13 +102,7 @@ class TemplateResponse extends Response { */ public function render(){ - if($this->appName !== null){ - $appName = $this->appName; - } else { - $appName = $this->api->getAppName(); - } - - $template = $this->api->getTemplate($this->templateName, $this->renderAs, $appName); + $template = new \OCP\Template($this->appName, $this->templateName, $this->renderAs); foreach($this->params as $key => $value){ $template->assign($key, $value); diff --git a/lib/public/appframework/iapi.php b/lib/public/appframework/iapi.php index fa6af5f5965..3bde4c9d4e7 100644 --- a/lib/public/appframework/iapi.php +++ b/lib/public/appframework/iapi.php @@ -67,59 +67,6 @@ interface IApi { */ function add3rdPartyStyle($name); - /** - * Returns the translation object - * @return \OC_L10N the translation object - * - * FIXME: returns private object / should be retrieved from teh ServerContainer - */ - function getTrans(); - - - /** - * Returns the URL for a route - * @param string $routeName the name of the route - * @param array $arguments an array with arguments which will be filled into the url - * @return string the url - */ - function linkToRoute($routeName, $arguments=array()); - - - /** - * Returns an URL for an image or file - * @param string $file the name of the file - * @param string $appName the name of the app, defaults to the current one - */ - function linkTo($file, $appName=null); - - - /** - * Returns the link to an image, like link to but only with prepending img/ - * @param string $file the name of the file - * @param string $appName the name of the app, defaults to the current one - */ - function imagePath($file, $appName = null); - - - /** - * Makes an URL absolute - * @param string $url the url - * @return string the absolute url - * - * FIXME: function should live in Request / Response - */ - function getAbsoluteURL($url); - - - /** - * links to a file - * @param string $file the name of the file - * @param string $appName the name of the app, defaults to the current one - * @deprecated replaced with linkToRoute() - * @return string the url - */ - function linkToAbsolute($file, $appName = null); - /** * Checks if an app is enabled @@ -128,24 +75,4 @@ interface IApi { */ public function isAppEnabled($appName); - - /** - * Writes a function into the error log - * @param string $msg the error message to be logged - * @param int $level the error level - * - * FIXME: add logger instance to ServerContainer - */ - function log($msg, $level = null); - - - /** - * Returns a template - * @param string $templateName the name of the template - * @param string $renderAs how it should be rendered - * @param string $appName the name of the app - * @return \OCP\Template a new template - */ - function getTemplate($templateName, $renderAs='user', $appName=null); - } diff --git a/lib/public/appframework/iappcontainer.php b/lib/public/appframework/iappcontainer.php index 7d3b4b3bac7..7e6ec6016b7 100644 --- a/lib/public/appframework/iappcontainer.php +++ b/lib/public/appframework/iappcontainer.php @@ -50,8 +50,26 @@ interface IAppContainer extends IContainer{ function getServer(); /** - * @param IMiddleWare $middleWare + * @param Middleware $middleWare * @return boolean */ - function registerMiddleWare(IMiddleWare $middleWare); + function registerMiddleWare(Middleware $middleWare); + + /** + * @return boolean + */ + function isLoggedIn(); + + /** + * @return boolean + */ + function isAdminUser(); + + /** + * @param $message + * @param $level + * @return mixed + */ + function log($message, $level); + } diff --git a/lib/public/appframework/middleware.php b/lib/public/appframework/middleware.php index 12776c119c0..94f71ea8520 100644 --- a/lib/public/appframework/middleware.php +++ b/lib/public/appframework/middleware.php @@ -24,6 +24,7 @@ namespace OCP\AppFramework; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; |