From 8603f956ab5982251de51ea403ee93c840a987ac Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 1 Oct 2013 19:01:52 +0200 Subject: Get urlParams registered before Request is instantiated --- lib/public/appframework/app.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'lib/public') diff --git a/lib/public/appframework/app.php b/lib/public/appframework/app.php index d97c5c81848..6ac48bf102a 100644 --- a/lib/public/appframework/app.php +++ b/lib/public/appframework/app.php @@ -31,8 +31,11 @@ namespace OCP\AppFramework; * to be registered using IContainer::registerService */ class App { - public function __construct($appName) { - $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName); + /** + * @param array $urlParams an array with variables extracted from the routes + */ + public function __construct($appName, $urlParams = array()) { + $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams); } private $container; @@ -50,8 +53,8 @@ class App { * Example code in routes.php of the task app: * $this->create('tasks_index', '/')->get()->action( * function($params){ - * $app = new TaskApp(); - * $app->dispatch('PageController', 'index', $params); + * $app = new TaskApp($params); + * $app->dispatch('PageController', 'index'); * } * ); * @@ -59,8 +62,8 @@ class App { * Example for for TaskApp implementation: * class TaskApp extends \OCP\AppFramework\App { * - * public function __construct(){ - * parent::__construct('tasks'); + * public function __construct($params){ + * parent::__construct('tasks', $params); * * $this->getContainer()->registerService('PageController', function(IAppContainer $c){ * $a = $c->query('API'); @@ -73,9 +76,8 @@ class App { * @param string $controllerName the name of the controller under which it is * stored in the DI container * @param string $methodName the method that you want to call - * @param array $urlParams an array with variables extracted from the routes */ - public function dispatch($controllerName, $methodName, array $urlParams) { - \OC\AppFramework\App::main($controllerName, $methodName, $urlParams, $this->container); + public function dispatch($controllerName, $methodName) { + \OC\AppFramework\App::main($controllerName, $methodName, $this->container); } } -- cgit v1.2.3 From 1f14ba6aedb3b777f148372305331261938be3b6 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Sun, 6 Oct 2013 23:16:40 +0200 Subject: move controller to OCP --- lib/private/appframework/controller/controller.php | 142 -------------------- lib/public/appframework/controller/controller.php | 147 +++++++++++++++++++++ 2 files changed, 147 insertions(+), 142 deletions(-) delete mode 100644 lib/private/appframework/controller/controller.php create mode 100644 lib/public/appframework/controller/controller.php (limited to 'lib/public') diff --git a/lib/private/appframework/controller/controller.php b/lib/private/appframework/controller/controller.php deleted file mode 100644 index 0ea0a38cc09..00000000000 --- a/lib/private/appframework/controller/controller.php +++ /dev/null @@ -1,142 +0,0 @@ -. - * - */ - - -namespace OC\AppFramework\Controller; - -use OC\AppFramework\Http\Request; -use OC\AppFramework\Core\API; -use OCP\AppFramework\Http\TemplateResponse; - - -/** - * Base class to inherit your controllers from - */ -abstract class Controller { - - /** - * @var API instance of the api layer - */ - protected $api; - - protected $request; - - /** - * @param API $api an api wrapper instance - * @param Request $request an instance of the request - */ - public function __construct(API $api, Request $request){ - $this->api = $api; - $this->request = $request; - } - - - /** - * Lets you access post and get parameters by the index - * @param string $key the key which you want to access in the URL Parameter - * placeholder, $_POST or $_GET array. - * The priority how they're returned is the following: - * 1. URL parameters - * 2. POST parameters - * 3. GET parameters - * @param mixed $default If the key is not found, this value will be returned - * @return mixed the content of the array - */ - public function params($key, $default=null){ - return $this->request->getParam($key, $default); - } - - - /** - * Returns all params that were received, be it from the request - * (as GET or POST) or throuh the URL by the route - * @return array the array with all parameters - */ - public function getParams() { - return $this->request->getParams(); - } - - - /** - * Returns the method of the request - * @return string the method of the request (POST, GET, etc) - */ - public function method() { - return $this->request->getMethod(); - } - - - /** - * Shortcut for accessing an uploaded file through the $_FILES array - * @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) { - return $this->request->getUploadedFile($key); - } - - - /** - * Shortcut for getting env variables - * @param string $key the key that will be taken from the $_ENV array - * @return array the value in the $_ENV element - */ - public function env($key) { - return $this->request->getEnv($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 - */ - public function cookie($key) { - return $this->request->getCookie($key); - } - - - /** - * Shortcut for rendering a template - * @param string $templateName the name of the template - * @param array $params the template parameters in key => value structure - * @param string $renderAs user renders a full page, blank only your template - * admin an entry in the admin settings - * @param array $headers set additional headers in name/value pairs - * @return \OCP\AppFramework\Http\TemplateResponse containing the page - */ - public function render($templateName, array $params=array(), - $renderAs='user', array $headers=array()){ - $response = new TemplateResponse($this->api, $templateName); - $response->setParams($params); - $response->renderAs($renderAs); - - foreach($headers as $name => $value){ - $response->addHeader($name, $value); - } - - return $response; - } - - -} diff --git a/lib/public/appframework/controller/controller.php b/lib/public/appframework/controller/controller.php new file mode 100644 index 00000000000..a832f89df42 --- /dev/null +++ b/lib/public/appframework/controller/controller.php @@ -0,0 +1,147 @@ +. + * + */ + + +namespace OCP\AppFramework\Controller; + +use OC\AppFramework\Http\Request; +use OC\AppFramework\Core\API; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\IAppContainer; +use OCP\IRequest; + + +/** + * Base class to inherit your controllers from + */ +abstract class Controller { + + /** + * @var \OCP\AppFramework\IAppContainer + */ + protected $app; + + /** + * @var \OCP\IRequest + */ + protected $request; + + /** + * @param IAppContainer $app interface to the app + * @param IRequest $request an instance of the request + */ + public function __construct(IAppContainer $app, IRequest $request){ + $this->app = $app; + $this->request = $request; + } + + + /** + * Lets you access post and get parameters by the index + * @param string $key the key which you want to access in the URL Parameter + * placeholder, $_POST or $_GET array. + * The priority how they're returned is the following: + * 1. URL parameters + * 2. POST parameters + * 3. GET parameters + * @param mixed $default If the key is not found, this value will be returned + * @return mixed the content of the array + */ + public function params($key, $default=null){ + return $this->request->getParam($key, $default); + } + + + /** + * Returns all params that were received, be it from the request + * (as GET or POST) or throuh the URL by the route + * @return array the array with all parameters + */ + public function getParams() { + return $this->request->getParams(); + } + + + /** + * Returns the method of the request + * @return string the method of the request (POST, GET, etc) + */ + public function method() { + return $this->request->getMethod(); + } + + + /** + * Shortcut for accessing an uploaded file through the $_FILES array + * @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) { + return $this->request->getUploadedFile($key); + } + + + /** + * Shortcut for getting env variables + * @param string $key the key that will be taken from the $_ENV array + * @return array the value in the $_ENV element + */ + public function env($key) { + return $this->request->getEnv($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 + */ + public function cookie($key) { + return $this->request->getCookie($key); + } + + + /** + * Shortcut for rendering a template + * @param string $templateName the name of the template + * @param array $params the template parameters in key => value structure + * @param string $renderAs user renders a full page, blank only your template + * admin an entry in the admin settings + * @param array $headers set additional headers in name/value pairs + * @return \OCP\AppFramework\Http\TemplateResponse containing the page + */ + public function render($templateName, array $params=array(), + $renderAs='user', array $headers=array()){ + $response = new TemplateResponse($this->app->getAppName(), $templateName); + $response->setParams($params); + $response->renderAs($renderAs); + + foreach($headers as $name => $value){ + $response->addHeader($name, $value); + } + + return $response; + } + + +} -- cgit v1.2.3 From e071bfc14476877b9731bfe84904858444eb1dbd Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 7 Oct 2013 00:33:54 +0200 Subject: fixing SecurityMiddleware to use OC6 API --- .../dependencyinjection/dicontainer.php | 52 ++++++++++++++++++++-- lib/private/appframework/http/dispatcher.php | 2 +- .../middleware/middlewaredispatcher.php | 2 +- .../middleware/security/securitymiddleware.php | 34 +++++++------- lib/public/appframework/http/templateresponse.php | 18 ++------ lib/public/appframework/iappcontainer.php | 22 ++++++++- lib/public/appframework/middleware.php | 1 + 7 files changed, 94 insertions(+), 37 deletions(-) (limited to 'lib/public') diff --git a/lib/private/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php index 3755d45fa09..7276a11e4d9 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; @@ -86,7 +87,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']); }); $this['MiddlewareDispatcher'] = $this->share(function($c){ @@ -129,10 +130,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); } @@ -143,4 +144,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..2a9ed121488 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\Controller; /** diff --git a/lib/private/appframework/middleware/middlewaredispatcher.php b/lib/private/appframework/middleware/middlewaredispatcher.php index c2377b8844b..c46ddc7cb02 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\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 d6daf737bb4..80f3f6d966f 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->api->getAppName()); // security checks $isPublicPage = $annotationReader->hasAnnotation('PublicPage'); if(!$isPublicPage) { - if(!$this->api->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/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/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..13b4b8cab99 100644 --- a/lib/public/appframework/middleware.php +++ b/lib/public/appframework/middleware.php @@ -24,6 +24,7 @@ namespace OCP\AppFramework; +use OCP\AppFramework\Controller\Controller; use OCP\AppFramework\Http\Response; -- cgit v1.2.3 From aefea2a408e0548ee1190923e7d2c42f49d26587 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 7 Oct 2013 11:25:06 +0200 Subject: remove unused classes --- lib/public/appframework/controller/controller.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/public') diff --git a/lib/public/appframework/controller/controller.php b/lib/public/appframework/controller/controller.php index a832f89df42..b3de8c991ad 100644 --- a/lib/public/appframework/controller/controller.php +++ b/lib/public/appframework/controller/controller.php @@ -24,8 +24,6 @@ namespace OCP\AppFramework\Controller; -use OC\AppFramework\Http\Request; -use OC\AppFramework\Core\API; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\IAppContainer; use OCP\IRequest; -- cgit v1.2.3 From 3ea2dfa5f9c0692f68ce64856bdf203a9bbc2018 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 7 Oct 2013 11:36:38 +0200 Subject: remove getTrans() from API class --- lib/private/appframework/core/api.php | 10 ---------- lib/public/appframework/iapi.php | 8 -------- .../dependencyinjection/DIContainerTest.php | 21 ++------------------- 3 files changed, 2 insertions(+), 37 deletions(-) (limited to 'lib/public') diff --git a/lib/private/appframework/core/api.php b/lib/private/appframework/core/api.php index c5991237ed1..31da0706a15 100644 --- a/lib/private/appframework/core/api.php +++ b/lib/private/appframework/core/api.php @@ -99,16 +99,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 diff --git a/lib/public/appframework/iapi.php b/lib/public/appframework/iapi.php index fa6af5f5965..818647c19fd 100644 --- a/lib/public/appframework/iapi.php +++ b/lib/public/appframework/iapi.php @@ -67,14 +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 diff --git a/tests/lib/appframework/dependencyinjection/DIContainerTest.php b/tests/lib/appframework/dependencyinjection/DIContainerTest.php index 25fdd202839..f3ebff0207f 100644 --- a/tests/lib/appframework/dependencyinjection/DIContainerTest.php +++ b/tests/lib/appframework/dependencyinjection/DIContainerTest.php @@ -29,23 +29,14 @@ namespace OC\AppFramework\DependencyInjection; use \OC\AppFramework\Http\Request; -//require_once(__DIR__ . "/../classloader.php"); - - class DIContainerTest extends \PHPUnit_Framework_TestCase { private $container; + private $api; protected function setUp(){ $this->container = new DIContainer('name'); - $this->api = $this->getMock('OC\AppFramework\Core\API', array('getTrans'), array('hi')); - } - - private function exchangeAPI(){ - $this->api->expects($this->any()) - ->method('getTrans') - ->will($this->returnValue('yo')); - $this->container['API'] = $this->api; + $this->api = $this->getMock('OC\AppFramework\Core\API', array(), array('hi')); } public function testProvidesAPI(){ @@ -87,12 +78,4 @@ class DIContainerTest extends \PHPUnit_Framework_TestCase { } - public function testMiddlewareDispatcherDoesNotIncludeTwigWhenTplDirectoryNotSet(){ - $this->container['Request'] = new Request(); - $this->exchangeAPI(); - $dispatcher = $this->container['MiddlewareDispatcher']; - - $this->assertEquals(1, count($dispatcher->getMiddlewares())); - } - } -- cgit v1.2.3 From 39be4dca67ea26aa7602aa8a1b6e556acb67af51 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 7 Oct 2013 11:38:23 +0200 Subject: removing all link/url related calls from API class --- lib/private/appframework/core/api.php | 63 ----------------------------------- lib/public/appframework/iapi.php | 45 ------------------------- 2 files changed, 108 deletions(-) (limited to 'lib/public') diff --git a/lib/private/appframework/core/api.php b/lib/private/appframework/core/api.php index 31da0706a15..299f3254e25 100644 --- a/lib/private/appframework/core/api.php +++ b/lib/private/appframework/core/api.php @@ -99,69 +99,6 @@ class API implements IApi{ } - /** - * 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 an app is enabled * @param string $appName the name of an app diff --git a/lib/public/appframework/iapi.php b/lib/public/appframework/iapi.php index 818647c19fd..c8722af6240 100644 --- a/lib/public/appframework/iapi.php +++ b/lib/public/appframework/iapi.php @@ -68,51 +68,6 @@ interface IApi { function add3rdPartyStyle($name); - /** - * 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 * @param string $appName the name of an app -- cgit v1.2.3 From c3286402a846bf874ae78a61880442f8ebfd7ba9 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 7 Oct 2013 11:41:28 +0200 Subject: removing log(), getTemplate(), getLocalFilePath(), getUrlContent(), getFileInfo() --- lib/private/appframework/core/api.php | 81 ----------------------------------- lib/public/appframework/iapi.php | 20 --------- 2 files changed, 101 deletions(-) (limited to 'lib/public') diff --git a/lib/private/appframework/core/api.php b/lib/private/appframework/core/api.php index 299f3254e25..e7269373bb0 100644 --- a/lib/private/appframework/core/api.php +++ b/lib/private/appframework/core/api.php @@ -109,44 +109,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 @@ -192,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 @@ -212,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 @@ -247,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/public/appframework/iapi.php b/lib/public/appframework/iapi.php index c8722af6240..3bde4c9d4e7 100644 --- a/lib/public/appframework/iapi.php +++ b/lib/public/appframework/iapi.php @@ -75,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); - } -- cgit v1.2.3 From d75d80ba133c40ec519422db85f1493cbdc9edeb Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 11 Oct 2013 10:07:57 +0200 Subject: OCP\AppFramework\Controller\Controller => OCP\AppFramework\Controller --- lib/private/appframework/http/dispatcher.php | 2 +- .../middleware/middlewaredispatcher.php | 2 +- lib/public/appframework/controller.php | 145 +++++++++++++++++++++ lib/public/appframework/controller/controller.php | 145 --------------------- lib/public/appframework/middleware.php | 2 +- tests/lib/appframework/AppTest.php | 2 +- .../lib/appframework/controller/ControllerTest.php | 2 +- tests/lib/appframework/http/DispatcherTest.php | 2 +- .../middleware/MiddlewareDispatcherTest.php | 2 +- .../lib/appframework/middleware/MiddlewareTest.php | 2 +- .../middleware/security/SecurityMiddlewareTest.php | 4 +- 11 files changed, 155 insertions(+), 155 deletions(-) create mode 100644 lib/public/appframework/controller.php delete mode 100644 lib/public/appframework/controller/controller.php (limited to 'lib/public') diff --git a/lib/private/appframework/http/dispatcher.php b/lib/private/appframework/http/dispatcher.php index 2a9ed121488..51283fd64e7 100644 --- a/lib/private/appframework/http/dispatcher.php +++ b/lib/private/appframework/http/dispatcher.php @@ -25,7 +25,7 @@ namespace OC\AppFramework\Http; use \OC\AppFramework\Middleware\MiddlewareDispatcher; -use OCP\AppFramework\Controller\Controller; +use OCP\AppFramework\Controller; /** diff --git a/lib/private/appframework/middleware/middlewaredispatcher.php b/lib/private/appframework/middleware/middlewaredispatcher.php index c46ddc7cb02..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 OCP\AppFramework\Controller\Controller; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; use OCP\AppFramework\MiddleWare; diff --git a/lib/public/appframework/controller.php b/lib/public/appframework/controller.php new file mode 100644 index 00000000000..1642b508572 --- /dev/null +++ b/lib/public/appframework/controller.php @@ -0,0 +1,145 @@ +. + * + */ + + +namespace OCP\AppFramework; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\IAppContainer; +use OCP\IRequest; + + +/** + * Base class to inherit your controllers from + */ +abstract class Controller { + + /** + * @var \OCP\AppFramework\IAppContainer + */ + protected $app; + + /** + * @var \OCP\IRequest + */ + protected $request; + + /** + * @param IAppContainer $app interface to the app + * @param IRequest $request an instance of the request + */ + public function __construct(IAppContainer $app, IRequest $request){ + $this->app = $app; + $this->request = $request; + } + + + /** + * Lets you access post and get parameters by the index + * @param string $key the key which you want to access in the URL Parameter + * placeholder, $_POST or $_GET array. + * The priority how they're returned is the following: + * 1. URL parameters + * 2. POST parameters + * 3. GET parameters + * @param mixed $default If the key is not found, this value will be returned + * @return mixed the content of the array + */ + public function params($key, $default=null){ + return $this->request->getParam($key, $default); + } + + + /** + * Returns all params that were received, be it from the request + * (as GET or POST) or throuh the URL by the route + * @return array the array with all parameters + */ + public function getParams() { + return $this->request->getParams(); + } + + + /** + * Returns the method of the request + * @return string the method of the request (POST, GET, etc) + */ + public function method() { + return $this->request->getMethod(); + } + + + /** + * Shortcut for accessing an uploaded file through the $_FILES array + * @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) { + return $this->request->getUploadedFile($key); + } + + + /** + * Shortcut for getting env variables + * @param string $key the key that will be taken from the $_ENV array + * @return array the value in the $_ENV element + */ + public function env($key) { + return $this->request->getEnv($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 + */ + public function cookie($key) { + return $this->request->getCookie($key); + } + + + /** + * Shortcut for rendering a template + * @param string $templateName the name of the template + * @param array $params the template parameters in key => value structure + * @param string $renderAs user renders a full page, blank only your template + * admin an entry in the admin settings + * @param array $headers set additional headers in name/value pairs + * @return \OCP\AppFramework\Http\TemplateResponse containing the page + */ + public function render($templateName, array $params=array(), + $renderAs='user', array $headers=array()){ + $response = new TemplateResponse($this->app->getAppName(), $templateName); + $response->setParams($params); + $response->renderAs($renderAs); + + foreach($headers as $name => $value){ + $response->addHeader($name, $value); + } + + return $response; + } + + +} diff --git a/lib/public/appframework/controller/controller.php b/lib/public/appframework/controller/controller.php deleted file mode 100644 index b3de8c991ad..00000000000 --- a/lib/public/appframework/controller/controller.php +++ /dev/null @@ -1,145 +0,0 @@ -. - * - */ - - -namespace OCP\AppFramework\Controller; - -use OCP\AppFramework\Http\TemplateResponse; -use OCP\AppFramework\IAppContainer; -use OCP\IRequest; - - -/** - * Base class to inherit your controllers from - */ -abstract class Controller { - - /** - * @var \OCP\AppFramework\IAppContainer - */ - protected $app; - - /** - * @var \OCP\IRequest - */ - protected $request; - - /** - * @param IAppContainer $app interface to the app - * @param IRequest $request an instance of the request - */ - public function __construct(IAppContainer $app, IRequest $request){ - $this->app = $app; - $this->request = $request; - } - - - /** - * Lets you access post and get parameters by the index - * @param string $key the key which you want to access in the URL Parameter - * placeholder, $_POST or $_GET array. - * The priority how they're returned is the following: - * 1. URL parameters - * 2. POST parameters - * 3. GET parameters - * @param mixed $default If the key is not found, this value will be returned - * @return mixed the content of the array - */ - public function params($key, $default=null){ - return $this->request->getParam($key, $default); - } - - - /** - * Returns all params that were received, be it from the request - * (as GET or POST) or throuh the URL by the route - * @return array the array with all parameters - */ - public function getParams() { - return $this->request->getParams(); - } - - - /** - * Returns the method of the request - * @return string the method of the request (POST, GET, etc) - */ - public function method() { - return $this->request->getMethod(); - } - - - /** - * Shortcut for accessing an uploaded file through the $_FILES array - * @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) { - return $this->request->getUploadedFile($key); - } - - - /** - * Shortcut for getting env variables - * @param string $key the key that will be taken from the $_ENV array - * @return array the value in the $_ENV element - */ - public function env($key) { - return $this->request->getEnv($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 - */ - public function cookie($key) { - return $this->request->getCookie($key); - } - - - /** - * Shortcut for rendering a template - * @param string $templateName the name of the template - * @param array $params the template parameters in key => value structure - * @param string $renderAs user renders a full page, blank only your template - * admin an entry in the admin settings - * @param array $headers set additional headers in name/value pairs - * @return \OCP\AppFramework\Http\TemplateResponse containing the page - */ - public function render($templateName, array $params=array(), - $renderAs='user', array $headers=array()){ - $response = new TemplateResponse($this->app->getAppName(), $templateName); - $response->setParams($params); - $response->renderAs($renderAs); - - foreach($headers as $name => $value){ - $response->addHeader($name, $value); - } - - return $response; - } - - -} diff --git a/lib/public/appframework/middleware.php b/lib/public/appframework/middleware.php index 13b4b8cab99..94f71ea8520 100644 --- a/lib/public/appframework/middleware.php +++ b/lib/public/appframework/middleware.php @@ -24,7 +24,7 @@ namespace OCP\AppFramework; -use OCP\AppFramework\Controller\Controller; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; diff --git a/tests/lib/appframework/AppTest.php b/tests/lib/appframework/AppTest.php index 8942e2f442d..9bedcb446e7 100644 --- a/tests/lib/appframework/AppTest.php +++ b/tests/lib/appframework/AppTest.php @@ -40,7 +40,7 @@ class AppTest extends \PHPUnit_Framework_TestCase { protected function setUp() { $this->container = new \OC\AppFramework\DependencyInjection\DIContainer('test'); $this->controller = $this->getMockBuilder( - 'OCP\AppFramework\Controller\Controller') + 'OCP\AppFramework\Controller') ->disableOriginalConstructor() ->getMock(); $this->dispatcher = $this->getMockBuilder( diff --git a/tests/lib/appframework/controller/ControllerTest.php b/tests/lib/appframework/controller/ControllerTest.php index 614744394ed..f17d5f24aa5 100644 --- a/tests/lib/appframework/controller/ControllerTest.php +++ b/tests/lib/appframework/controller/ControllerTest.php @@ -25,7 +25,7 @@ namespace Test\AppFramework\Controller; use OC\AppFramework\Http\Request; -use OCP\AppFramework\Controller\Controller; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; diff --git a/tests/lib/appframework/http/DispatcherTest.php b/tests/lib/appframework/http/DispatcherTest.php index fb9fd0d582a..9052fe0781a 100644 --- a/tests/lib/appframework/http/DispatcherTest.php +++ b/tests/lib/appframework/http/DispatcherTest.php @@ -62,7 +62,7 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $this->controller = $this->getMock( - '\OCP\AppFramework\Controller\Controller', + '\OCP\AppFramework\Controller', array($this->controllerMethod), array($app, $request)); $this->dispatcher = new Dispatcher( diff --git a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php index 5a43099ebb5..95d42e4eb8e 100644 --- a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php +++ b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php @@ -128,7 +128,7 @@ class MiddlewareDispatcherTest extends \PHPUnit_Framework_TestCase { private function getControllerMock(){ - return $this->getMock('OCP\AppFramework\Controller\Controller', array('method'), + return $this->getMock('OCP\AppFramework\Controller', array('method'), array($this->getAPIMock(), new Request())); } diff --git a/tests/lib/appframework/middleware/MiddlewareTest.php b/tests/lib/appframework/middleware/MiddlewareTest.php index fde67fbd395..7a93c0d4dda 100644 --- a/tests/lib/appframework/middleware/MiddlewareTest.php +++ b/tests/lib/appframework/middleware/MiddlewareTest.php @@ -47,7 +47,7 @@ class MiddlewareTest extends \PHPUnit_Framework_TestCase { $this->api = $this->getMock('OC\AppFramework\DependencyInjection\DIContainer', array(), array('test')); - $this->controller = $this->getMock('OCP\AppFramework\Controller\Controller', + $this->controller = $this->getMock('OCP\AppFramework\Controller', array(), array($this->api, new Request())); $this->exception = new \Exception(); $this->response = $this->getMock('OCP\AppFramework\Http\Response'); diff --git a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php index b647c01826b..4bfd725ffd0 100644 --- a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php +++ b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php @@ -40,7 +40,7 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { public function setUp() { $api = $this->getMock('OC\AppFramework\DependencyInjection\DIContainer', array(), array('test')); - $this->controller = $this->getMock('OCP\AppFramework\Controller\Controller', + $this->controller = $this->getMock('OCP\AppFramework\Controller', array(), array($api, new Request())); $this->request = new Request(); @@ -302,7 +302,7 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { $api->expects($this->once())->method('getServer') ->will($this->returnValue($serverMock)); - $this->controller = $this->getMock('OCP\AppFramework\Controller\Controller', + $this->controller = $this->getMock('OCP\AppFramework\Controller', array(), array($api, new Request())); $this->request = new Request( -- cgit v1.2.3