public function serve(Request $request) { $p = []; $response = []; try { // See: http://www.w3schools.com/php/php_exception.asp if ($request->isMethod('post')) { $p = $request->all(); App\Cb\Api::setPost($p)->authenticate(); // Make sure required data is passed to the api $api_map = ['check' => 'App\\Cb\\Api::check', 'user_authenticate' => 'App\\Cb\\Api::userAuthenticate', 'logout' => 'App\\Cb\\Api::logout', 'add_user' => 'App\\Cb\\Api\\Users::addUser', 'update_user' => 'App\\Cb\\Api\\Users::updateUser', 'test_pusher' => 'App\\Cb\\Api::testPusher']; if (!isset($api_map[$p['api_name']])) { throw new App\Cb\Api\Exceptyon('API "' . $p['api_name'] . '" is unknown'); } $response = App\Cb\Api::run($api_map[$p['api_name']]); return response()->json($response); } else { throw new App\Cb\Api\Exceptyon('Please use POST method in accessing the api'); } } catch (App\Cb\Api\Exceptyon $err) { $response['error'] = $err->getMessage(); $response['passed'] = App\Json::encode($p); $response['res'] = App\Json::encode($request->all()); $response['post'] = App\Json::encode($_POST); $response['request'] = App\Json::encode($_REQUEST); //xplog('RAW: '.file_get_contents("php://input")); if (isset($p['api_name'])) { $response['api_name'] = $p['api_name']; } return response()->json($response); } }
protected function write($_msg, $_class_info = false) { $nl = chr(10); $msg = ''; $data = array(); $data['msg'] = '[' . trim($_msg) . ']'; $data['request_uri'] = $_SERVER['REQUEST_URI']; $data['ip'] = $_SERVER['REMOTE_ADDR']; if (!!$_class_info) { if (is_object($_class_info)) { $data['classname'] = get_class($_class_info); } else { $data['code'] = $_class_info; } } $msg = str_replace('\\n', ' ', App\Json::encode($data)); //$msg = $nl.'INFO - '.date('Y-m-d h:i:s A').' --> '.str_replace('\\', '', $msg); $msg = $nl . 'INFO - ' . $this->pinoyTime(date('Y-m-d h:i:s A'), 'Y-m-d h:i:s A') . ' --> ' . str_replace('\\', '', $msg); App\Files::append($this->log_file, $msg, true); }
protected function testPusher($_post) { $p = $_post; $this->req($p, ['data']); // See: http://www.smashingmagazine.com/2012/05/building-real-time-commenting-system/ // See: https://github.com/pusher/pusher-http-php $app_id = '149666'; $app_key = '768422d844cb5acf6d6e'; $app_secret = '2f685782367009dec1bf'; $pusher = new Pusher($app_key, $app_secret, $app_id); // See: https://github.com/pusher/pusher-http-php#debugging--logging $pusher->set_logger(new App\Cb\RealTime\Logger()); $pusher->trigger('currentBID_channel', 'currentBID_event', App\Json::decode($p['data'])); xplog('API PUSHER TRIGGER: ' . App\Json::encode($p)); xplog('DATA: ' . $p['data']); xplog('API PUSHER CHANNELS: ' . App\Json::encode($pusher->get_channels())); return ['api_name' => $_post['api_name'], 'payload' => 1]; }