From ceac3f24ec208f895642ee60683c6ad2ab0b7779 Mon Sep 17 00:00:00 2001 From: everyx Date: Sun, 12 Mar 2017 10:16:57 +0800 Subject: [PATCH] correct to use unified style for the route --- README.md | 2 +- src/Controller/OperatorStatusController.php | 22 +++++++++++---------- src/routing.yml | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d78f63c..63cd6bb 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Plugin for Mibew, get statement based on the availability of operators. # Useage -Request `/opstatus?code=`, your will get `true` when operator +Request `/opstatus/`, your will get `true` when operator is online or `false` when operator is offline. # Install diff --git a/src/Controller/OperatorStatusController.php b/src/Controller/OperatorStatusController.php index 314ddf6..96aefbb 100644 --- a/src/Controller/OperatorStatusController.php +++ b/src/Controller/OperatorStatusController.php @@ -42,21 +42,23 @@ class OperatorStatusController extends AbstractController */ public function indexAction(Request $request) { - $is_online = "false"; + $is_online = "true"; - $opcode = $request->query->get('code', false); + $opcode = $request->attributes->get('opcode'); $online_operators = get_online_operators(); - if (count($online_operators) > 0) { - if (empty($opcode)) { - $is_online = "true"; - } else { - foreach ($online_operators as $item) { - if ($item['code'] == $opcode) { - $is_online = "true"; - } + + if ( count($online_operators) == 0 ) { + $is_online = "false"; + } else if ( !empty($opcode) ) { + $is_online = "false"; + foreach ($online_operators as $item) { + if ($item['code'] == $opcode) { + $is_online = "true"; + break; } } } + $response = new Response($is_online); $response->headers->set('Access-Control-Allow-Origin', '*'); return $response; diff --git a/src/routing.yml b/src/routing.yml index a04a781..11cea93 100644 --- a/src/routing.yml +++ b/src/routing.yml @@ -1,4 +1,4 @@ mibew_boilerplate_hello: - path: /opstatus + path: /opstatus/{opcode} defaults: _controller: Everyx\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::indexAction