/** * Mock/Force the initialization of a REST call. * Typically avoiding some HTTP request processing. * Circumvents the need to go through a REST client to invoke the API. * * @param Api_AbstractRest $rest * @param array $apiParams * * @return The initialized REST object. */ protected function initRest(Api_AbstractRest &$rest, $apiParams) { $context = Api_RequestContext::createRequestContext($apiParams); $rest->_setContext($context); $rest->validateRequest(); return $rest; }
/** * Mock/Force the initialization of a REST call. * Typically avoiding the Session creation and other HTTP request processing. * * @param Api_AbstractRest $rest * @param string $uid * @param array $apiParams * @return The initialized REST object. */ protected function initRest(Api_AbstractRest &$rest, $apiParams, $uid = null, $aid = null, $nid = null, &$session = array()) { if ($uid != null) { $session['uid'] = $uid; } if ($aid != null) { $session['app_id'] = $aid; } if ($nid != null) { $session['network_key'] = $nid; } $context = Api_RequestContext::createRequestContext($apiParams); $rest->_setContext($context); $rest->_setSession($session); $rest->validateRequest(); return $rest; }
/** * Lifecyle method to inject the context into the REST handler * * @param unknown_type $context */ public function _setContext(Api_RequestContext &$context) { $this->m_context =& $context; $this->m_apiParams =& $context->getParameters(); }
/** * Static method to create context. This method could become * a singletone, but right now acts a bit like a factory. * * @param array $request * @return Api_RequestContext */ public static function &createRequestContext($request) { $context = new Api_RequestContext(); $context->loadContext($request); return $context; }
/** * Execute the request and return the hash results, this * was separated soley for the purpose of running test cases. * * @param unknown_type $requestParams */ function executeRequest(Api_RequestContext &$context) { $response = array(); if ($context->getMethod() == null) { throw new OpenFBAPIException('Incorrect Signature, Missing METHOD.', FB_ERROR_CODE_INCORRECT_SIGNATURE); } // Call the object/method. $api_name = explode('.', $context->getMethod()); $api_pkg = $api_name[1]; $api_class = ucfirst($api_name[1]) . ucfirst($api_name[2]); $lasterrorlevel = error_reporting(E_ERROR); if (!(include_once $api_name[0] . '/rest/' . $api_class . '.php')) { // TODO: Move these to match the packaging standard // Default OpenFBServer API implementations are still here include_once 'ringside/api/facebook/' . $api_class . '.php'; } error_reporting($lasterrorlevel); if (!$api_class) { throw new Exception("Class {$api_class} could not be loaded"); } $faf = new $api_class(); // Set the server object. $faf->_setServer($this); // set the context $faf->_setContext($context); // Load the session and setup the session. $faf->loadSession(); // Execute delegation? $faf->delegateRequest(); // Validation steps $faf->validateSession(); $faf->validateApiKey(); $faf->validateSig(); $faf->validateVersion(); $faf->validateCallId(); $faf->validateRequest(); // let's invoke the API that is being requested - collect stat around the call $tuple = new M3_Event_Tuple($faf->getNetworkId(), $faf->getAppId(), $faf->getUserId()); $dispatcher = M3_Event_DispatcherFactory::createApiResponseTimeTupleDispatcher($context->getMethod(), $tuple); $dispatcher->startTimer(); $response = $faf->execute(); $dispatcher->stopTimer(); // emit event return $response; }