]> source.dussan.org Git - nextcloud-server.git/commitdiff
OCP\AppFramework\Controller\Controller => OCP\AppFramework\Controller
authorThomas Tanghus <thomas@tanghus.net>
Fri, 11 Oct 2013 08:07:57 +0000 (10:07 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Fri, 11 Oct 2013 08:07:57 +0000 (10:07 +0200)
lib/private/appframework/http/dispatcher.php
lib/private/appframework/middleware/middlewaredispatcher.php
lib/public/appframework/controller.php [new file with mode: 0644]
lib/public/appframework/controller/controller.php [deleted file]
lib/public/appframework/middleware.php
tests/lib/appframework/AppTest.php
tests/lib/appframework/controller/ControllerTest.php
tests/lib/appframework/http/DispatcherTest.php
tests/lib/appframework/middleware/MiddlewareDispatcherTest.php
tests/lib/appframework/middleware/MiddlewareTest.php
tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php

index 2a9ed1214886d09a03fd89f371b88864b7da029d..51283fd64e7cb73f2f91a522a85d5995e608df8f 100644 (file)
@@ -25,7 +25,7 @@
 namespace OC\AppFramework\Http;
 
 use \OC\AppFramework\Middleware\MiddlewareDispatcher;
-use OCP\AppFramework\Controller\Controller;
+use OCP\AppFramework\Controller;
 
 
 /**
index c46ddc7cb02d65cb87e8e366115ffa51f1bd712c..681140c2242e2d5d402e8f34b3917334dee51527 100644 (file)
@@ -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 (file)
index 0000000..1642b50
--- /dev/null
@@ -0,0 +1,145 @@
+<?php
+
+/**
+ * ownCloud - App Framework
+ *
+ * @author Bernhard Posselt
+ * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+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 (file)
index b3de8c9..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-
-/**
- * ownCloud - App Framework
- *
- * @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-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;
-       }
-
-
-}
index 13b4b8cab99b38a96b14dd6411db8c701c907453..94f71ea8520ddbec62ac7ed4b5e0e1b762263337 100644 (file)
@@ -24,7 +24,7 @@
 
 namespace OCP\AppFramework;
 
-use OCP\AppFramework\Controller\Controller;
+use OCP\AppFramework\Controller;
 use OCP\AppFramework\Http\Response;
 
 
index 8942e2f442d0fcb990d4075ac367953793a3bdd8..9bedcb446e73604d5cf2e2bed4b4ed48092e31bd 100644 (file)
@@ -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(
index 614744394ed364c545cd4d65f3321b8f059d4abe..f17d5f24aa523c0e4ee0a5309d9541f66e0d562d 100644 (file)
@@ -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;
 
 
index fb9fd0d582a58dfa042c8f7684a1219f246b6b9b..9052fe0781ac8929e27d2b7604ccd9a5afbafe99 100644 (file)
@@ -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(
index 5a43099ebb56c48a652e20a0b1d7ecc5fb151472..95d42e4eb8ec81315e44fe1b486e4a80fec08016 100644 (file)
@@ -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()));
        }
 
index fde67fbd395e30257f57f4fe073eae83d5a92b3e..7a93c0d4ddac9b309ff43858f60743a91824b560 100644 (file)
@@ -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');
index b647c01826ba5af6511e65b8a4be3b809dbc7be6..4bfd725ffd02d797647e2aa606d242101de86dbe 100644 (file)
@@ -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(