From c85621a8971a99a6f811c470f50d9b0e89f957da Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sat, 5 Oct 2013 16:59:06 +0200 Subject: [PATCH] Make abstract Middleware class public It doesn't make sense for subclasses to have to implement all methods. --- .../appframework/middleware/middlewaredispatcher.php | 4 ++-- .../middleware/security/securitymiddleware.php | 2 +- .../middleware => public/appframework}/middleware.php | 4 ++-- .../appframework/middleware/MiddlewareDispatcherTest.php | 8 ++++---- tests/lib/appframework/middleware/MiddlewareTest.php | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) rename lib/{private/appframework/middleware => public/appframework}/middleware.php (97%) diff --git a/lib/private/appframework/middleware/middlewaredispatcher.php b/lib/private/appframework/middleware/middlewaredispatcher.php index 70ab108e6b..5cce97b216 100644 --- a/lib/private/appframework/middleware/middlewaredispatcher.php +++ b/lib/private/appframework/middleware/middlewaredispatcher.php @@ -26,7 +26,7 @@ namespace OC\AppFramework\Middleware; use OC\AppFramework\Controller\Controller; use OCP\AppFramework\Http\Response; - +use OCP\AppFramework\IMiddleWare; /** * This class is used to store and run all the middleware in correct order @@ -58,7 +58,7 @@ class MiddlewareDispatcher { * Adds a new middleware * @param Middleware $middleware the middleware which will be added */ - public function registerMiddleware(Middleware $middleWare){ + public function registerMiddleware(IMiddleware $middleWare){ array_push($this->middlewares, $middleWare); } diff --git a/lib/private/appframework/middleware/security/securitymiddleware.php b/lib/private/appframework/middleware/security/securitymiddleware.php index 4f1447e1af..d6daf737bb 100644 --- a/lib/private/appframework/middleware/security/securitymiddleware.php +++ b/lib/private/appframework/middleware/security/securitymiddleware.php @@ -29,8 +29,8 @@ use OC\AppFramework\Http\Http; use OC\AppFramework\Http\Request; use OC\AppFramework\Http\RedirectResponse; use OC\AppFramework\Utility\MethodAnnotationReader; -use OC\AppFramework\Middleware\Middleware; use OC\AppFramework\Core\API; +use OCP\AppFramework\Middleware; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\JSONResponse; diff --git a/lib/private/appframework/middleware/middleware.php b/lib/public/appframework/middleware.php similarity index 97% rename from lib/private/appframework/middleware/middleware.php rename to lib/public/appframework/middleware.php index b12c03c3eb..0f08eaef36 100644 --- a/lib/private/appframework/middleware/middleware.php +++ b/lib/public/appframework/middleware.php @@ -22,7 +22,7 @@ */ -namespace OC\AppFramework\Middleware; +namespace OCP\AppFramework; use OCP\AppFramework\Http\Response; @@ -33,7 +33,7 @@ use OCP\AppFramework\Http\Response; * They're modeled after Django's middleware system: * https://docs.djangoproject.com/en/dev/topics/http/middleware/ */ -abstract class Middleware { +abstract class Middleware implements IMiddleWare { /** diff --git a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php index 43727846dc..dd85a9ad52 100644 --- a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php +++ b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php @@ -25,8 +25,8 @@ namespace OC\AppFramework; use OC\AppFramework\Http\Request; -use OC\AppFramework\Middleware\Middleware; use OC\AppFramework\Middleware\MiddlewareDispatcher; +use OCP\AppFramework\Middleware; use OCP\AppFramework\Http\Response; @@ -142,12 +142,12 @@ class MiddlewareDispatcherTest extends \PHPUnit_Framework_TestCase { public function testAfterExceptionShouldReturnResponseOfMiddleware(){ $response = new Response(); - $m1 = $this->getMock('\OC\AppFramework\Middleware\Middleware', + $m1 = $this->getMock('\OCP\AppFramework\Middleware', array('afterException', 'beforeController')); $m1->expects($this->never()) ->method('afterException'); - $m2 = $this->getMock('OC\AppFramework\Middleware\Middleware', + $m2 = $this->getMock('OCP\AppFramework\Middleware', array('afterException', 'beforeController')); $m2->expects($this->once()) ->method('afterException') @@ -267,7 +267,7 @@ class MiddlewareDispatcherTest extends \PHPUnit_Framework_TestCase { public function testExceptionShouldRunAfterExceptionOfOnlyPreviouslyExecutedMiddlewares(){ $m1 = $this->getMiddleware(); $m2 = $this->getMiddleware(true); - $m3 = $this->getMock('\OC\AppFramework\Middleware\Middleware'); + $m3 = $this->getMock('\OCP\AppFramework\Middleware'); $m3->expects($this->never()) ->method('afterException'); $m3->expects($this->never()) diff --git a/tests/lib/appframework/middleware/MiddlewareTest.php b/tests/lib/appframework/middleware/MiddlewareTest.php index 5e2930ac6a..d0be7f7ca7 100644 --- a/tests/lib/appframework/middleware/MiddlewareTest.php +++ b/tests/lib/appframework/middleware/MiddlewareTest.php @@ -25,7 +25,7 @@ namespace OC\AppFramework; use OC\AppFramework\Http\Request; -use OC\AppFramework\Middleware\Middleware; +use OCP\AppFramework\Middleware; class ChildMiddleware extends Middleware {};