correct to use unified style for the route

This commit is contained in:
everyx 2017-03-12 10:16:57 +08:00
parent 6dd2f86e99
commit ceac3f24ec
3 changed files with 14 additions and 12 deletions

View File

@ -3,7 +3,7 @@ Plugin for Mibew, get statement based on the availability of operators.
# Useage # Useage
Request `<MIBEW-BASE-URL>/opstatus?code=<OPERATOR-CODE>`, your will get `true` when operator Request `<MIBEW-BASE-URL>/opstatus/<OPERATOR-CODE>`, your will get `true` when operator
is online or `false` when operator is offline. is online or `false` when operator is offline.
# Install # Install

View File

@ -42,21 +42,23 @@ class OperatorStatusController extends AbstractController
*/ */
public function indexAction(Request $request) 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(); $online_operators = get_online_operators();
if (count($online_operators) > 0) {
if (empty($opcode)) { if ( count($online_operators) == 0 ) {
$is_online = "true"; $is_online = "false";
} else { } else if ( !empty($opcode) ) {
foreach ($online_operators as $item) { $is_online = "false";
if ($item['code'] == $opcode) { foreach ($online_operators as $item) {
$is_online = "true"; if ($item['code'] == $opcode) {
} $is_online = "true";
break;
} }
} }
} }
$response = new Response($is_online); $response = new Response($is_online);
$response->headers->set('Access-Control-Allow-Origin', '*'); $response->headers->set('Access-Control-Allow-Origin', '*');
return $response; return $response;

View File

@ -1,4 +1,4 @@
mibew_boilerplate_hello: mibew_boilerplate_hello:
path: /opstatus path: /opstatus/{opcode}
defaults: defaults:
_controller: Everyx\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::indexAction _controller: Everyx\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::indexAction