/**
  * Dispatch calls to method with matching name on target and echo the
  * response or an error message
  *
  * if no action is passed the action will be taken from GET or POST as
  * 'action'
  *
  * @param object $action name of action
  *
  * @return void
  */
 public function dispatch($action = null)
 {
     try {
         $sid = $this->_session->session_id();
         if (empty($sid)) {
             throw new KiTT_Exception("No session");
         }
         // Grab action from GET/POST if not passed explicitly
         if ($action === null) {
             $action = KiTT_HTTPContext::toString('action');
         }
         // Check that we have a valid action
         if ($action == null) {
             throw new KiTT_Exception("No action defined!");
         }
         if (substr($action, 0, 2) == '__') {
             throw new KiTT_Exception("Invalid action");
         }
         if (!method_exists($this->_target, $action)) {
             throw new KiTT_Exception("Invalid action");
         }
         // call implementation, this may raise an exception
         $response = $this->_target->{$action}();
         $this->outputResponse($response);
     } catch (Exception $e) {
         $this->outputError($e);
     }
 }
示例#2
0
 /**
  * Make a get_addresses call to KRED for the pno in GET/POST
  *
  * @return array containing content and content-type
  */
 public function getAddress()
 {
     $addrs = $this->_addresses->getAddresses(KiTT_HTTPContext::toString('pno'));
     return array('type' => 'application/json', 'value' => $this->_getAddressesJson($addrs));
 }