public function runApi($name = 'api') {

		$router = Router::getInstance();

		// check if API has been called
		if (!trim($name) or $name != $router->module or !file_exists(MODULE_PATH . 'controller.php')) {
			return;
		}
		
		// set as raw request
		Router::setRaw();
		
		$logger = Logger::getInstance();
		$logger->disable();

		// require controller file
		require (MODULE_PATH . 'controller.php');
		
		// get SID by both GET and POST
		$sid = Input::get('sid');
		
		// get token as well
		$tokenValue = Router::get('token');

		$ctlName = $name . 'Controller';
		$apiCtl = new $ctlName();

		// set the action function
		$action = $router->action ? $router->action . 'Action' : 'defaultAction';
		
		// check token as first
		if ($tokenValue) {
			
			$token = Token::getByValue($tokenValue);
			
			// set token and start controller
			if ($token) {
				$token->updateLastUse();
				$apiCtl->setToken($token);
				$apiCtl->$action();
			} else {
				$apiCtl->sendError('Token is not valid');
			}
			
		// login and logout
		} else if ('login' == $router->action or 'logout' == $router->action) {
			
			// start the PHP session
			session_start();
			
			// start controller
			$apiCtl->$action();

		// all the other requests with sid
		} else if ($sid) {

			// get passed session
			$session = new Session($sid);

			// check if sid is valid
			if (!$session->isLoaded()) {
				$apiCtl->sendError('Session is not valid');
			}

			// if session exists, extend session timeout
			$session->extendTimeout();

			// create User object for API
			$userClass = PAIR_USER_CLASS;
			$user = new $userClass($session->idUser);
			$this->setCurrentUser($user);

			// set session and start controller
			$apiCtl->setSession($session);
			$apiCtl->$action();

		// unauthorized request
		} else {

			$apiCtl->sendError('Request is not valid');

		}

		exit();

	}
public function runApi($name = 'api') {

		$router = Router::getInstance();

		// check if API has been called
		if (!trim($name) or $name != $router->module or !file_exists(MODULE_PATH . 'controller.php')) {
			return;
		}
		
		// set as raw request
		Router::setRaw();
		
		$logger = Logger::getInstance();
		$logger->disable();

		// require controller file
		require (MODULE_PATH . 'controller.php');
		
		// get SID by both GET and POST
		$sid = Input::get('sid');
		
		// get token as well
		$tokenValue = Router::get('token');

		$ctlName = $name . 'Controller';
		$apiCtl = new $ctlName();

		// set the action function
		$action = $router->action ? $router->action . 'Action' : 'defaultAction';
		
		// check token as first
		if ($tokenValue) {
			
			$token = Token::getByValue($tokenValue);
			
			// set token and start controller
			if ($token) {
				$token->updateLastUse();
				$apiCtl->setToken($token);
				$apiCtl->$action();
			} else {
				$apiCtl->sendError('Token is not valid');
			}
			
		// login and logout
		} else if ('login' == $router->action or 'logout' == $router->action) {
			
			// start the PHP session
			session_start();
			
			// start controller
			$apiCtl->$action();

		// all the other requests with sid
		} else if ($sid) {

			// get passed session
			$session = new Session($sid);

			// check if sid is valid
			if (!$session->isLoaded()) {
				$apiCtl->sendError('Session is not valid');
			}

			// if session exists, extend session timeout
			$session->extendTimeout();

			// create User object for API
			$userClass = PAIR_USER_CLASS;
			$user = new $userClass($session->idUser);
			$this->setCurrentUser($user);

			// set session and start controller
			$apiCtl->setSession($session);
			$apiCtl->$action();

		// unauthorized request
		} else {

			$apiCtl->sendError('Request is not valid');

		}

		exit();

	}
public function runApi ( $ name = 'api' ) { $ router = Router :: getInstance ( ) ; // check if API has been called if ( ! trim ( $ name ) or $ name != $ router -> module or ! file_exists ( MODULE_PATH . 'controller.php' ) ) { return ; } // set as raw request Router :: setRaw ( ) ; $ logger = Logger :: getInstance ( ) ; $ logger -> disable ( ) ; // require controller file require ( MODULE_PATH . 'controller.php' ) ; // get SID by both GET and POST $ sid = Input :: get ( 'sid' ) ; // get token as well $ tokenValue = Router :: get ( 'token' ) ; $ ctlName = $ name . 'Controller' ; $ apiCtl = new $ ctlName ( ) ; // set the action function $ action = $ router -> action ? $ router -> action . 'Action' : 'defaultAction' ; // check token as first if ( $ tokenValue ) { $ token = Token :: getByValue ( $ tokenValue ) ; // set token and start controller if ( $ token ) { $ token -> updateLastUse ( ) ; $ apiCtl -> setToken ( $ token ) ; $ apiCtl -> $ action ( ) ; } else { $ apiCtl -> sendError ( 'Token is not valid' ) ; } // login and logout } else if ( 'login' == $ router -> action or 'logout' == $ router -> action ) { // start the PHP session session_start ( ) ; // start controller $ apiCtl -> $ action ( ) ; // all the other requests with sid } else if ( $ sid ) { // get passed session $ session = new Session ( $ sid ) ; // check if sid is valid if ( ! $ session -> isLoaded ( ) ) { $ apiCtl -> sendError ( 'Session is not valid' ) ; } // if session exists, extend session timeout $ session -> extendTimeout ( ) ; // create User object for API $ userClass = PAIR_USER_CLASS ; $ user = new $ userClass ( $ session -> idUser ) ; $ this -> setCurrentUser ( $ user ) ; // set session and start controller $ apiCtl -> setSession ( $ session ) ; $ apiCtl -> $ action ( ) ; // unauthorized request } else { $ apiCtl -> sendError ( 'Request is not valid' ) ; } exit ( ) ; }
Manage API login, logout and custom requests.

@param	string	Name of module that executes API requests. Default is “api”.
Manage API login logout and custom requests .