attributes->get('opcode'); $online_operators = get_online_operators(); foreach ($online_operators as $item) { if ($opcode == $item['code']) { $is_online = true; break; } } $callback = $request->query->get('callback'); return $this->prepareResponse($is_online, $callback); } /** * Returns true or false of whether an operator is online or not. * * @param Request $request * @return Response Rendered page content */ public function hasOnlineOperatorsAction(Request $request) { $is_online = has_online_operators(); $callback = $request->query->get('callback'); return $this->prepareResponse($is_online, $callback); } /** * Returns prepared response: JSONP or plain text. * * @param Boolean $is_online * @param String $callback * @return Response Rendered page content */ private function prepareResponse($is_online, $callback) { $response = NULL; if ( empty($callback) ) { $response = new Response( $is_online ? 'true' : 'false' ); $response->headers->set('Access-Control-Allow-Origin', '*'); } else { $response = new JsonResponse($is_online); $response->setCallback($callback); } return $response; } }