From e948091066e4893b1b823fc80db1c1ebba174b53 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 20 Nov 2018 18:55:56 +0100 Subject: [PATCH] Replaced old /api endpoint with ApiController --- config/routes.php | 3 ++ src/Controllers/ApiController.php | 30 ++++++++++++++++++++ src/Middleware/LegacyMiddleware.php | 5 ---- tests/Unit/Controllers/ApiControllerTest.php | 25 ++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 src/Controllers/ApiController.php create mode 100644 tests/Unit/Controllers/ApiControllerTest.php diff --git a/config/routes.php b/config/routes.php index 8322cb2f..b9e3646a 100644 --- a/config/routes.php +++ b/config/routes.php @@ -10,3 +10,6 @@ $route->get('/credits', 'CreditsController@index'); // Stats $route->get('/metrics', 'Metrics\\Controller@metrics'); $route->get('/stats', 'Metrics\\Controller@stats'); + +// API +$route->get('/api[/{resource:.+}]', 'ApiController@index'); diff --git a/src/Controllers/ApiController.php b/src/Controllers/ApiController.php new file mode 100644 index 00000000..a9c0be98 --- /dev/null +++ b/src/Controllers/ApiController.php @@ -0,0 +1,30 @@ +response = $response; + } + + /** + * @return Response + */ + public function index() + { + return $this->response + ->setStatusCode(501) + ->withHeader('content-type', 'application/json') + ->withContent(json_encode(['error' => 'Not implemented'])); + } +} diff --git a/src/Middleware/LegacyMiddleware.php b/src/Middleware/LegacyMiddleware.php index 2467f25c..de16e557 100644 --- a/src/Middleware/LegacyMiddleware.php +++ b/src/Middleware/LegacyMiddleware.php @@ -17,7 +17,6 @@ class LegacyMiddleware implements MiddlewareInterface protected $free_pages = [ 'admin_event_config', 'angeltypes', - 'api', 'atom', 'ical', 'login', @@ -106,10 +105,6 @@ class LegacyMiddleware implements MiddlewareInterface $title = ucfirst($page); switch ($page) { /** @noinspection PhpMissingBreakStatementInspection */ - case 'api': - error('Api disabled temporarily.'); - redirect(page_link_to()); - /** @noinspection PhpMissingBreakStatementInspection */ case 'ical': require_once realpath(__DIR__ . '/../../includes/pages/user_ical.php'); user_ical(); diff --git a/tests/Unit/Controllers/ApiControllerTest.php b/tests/Unit/Controllers/ApiControllerTest.php new file mode 100644 index 00000000..7e437e12 --- /dev/null +++ b/tests/Unit/Controllers/ApiControllerTest.php @@ -0,0 +1,25 @@ +index(); + + $this->assertEquals(501, $response->getStatusCode()); + $this->assertEquals(['application/json'], $response->getHeader('content-type')); + $this->assertJson($response->getContent()); + } +}