From: Thomas Tanghus Date: Fri, 11 Oct 2013 08:07:57 +0000 (+0200) Subject: OCP\AppFramework\Controller\Controller => OCP\AppFramework\Controller X-Git-Tag: v6.0.0beta2~103^2~2^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d75d80ba133c40ec519422db85f1493cbdc9edeb;p=nextcloud-server.git OCP\AppFramework\Controller\Controller => OCP\AppFramework\Controller --- 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(