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
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.
# Install

View File

@ -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;

View File

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