handleRequest() публичный Метод

The heart of the server. Dispatch a request to the appropriate request handler.
public handleRequest ( string $cmd, string $devId ) : string | boolean
$cmd string The command we are requesting.
$devId string The device id making the request. @deprecated
Результат string | boolean false if failed, true if succeeded and response content is wbxml, otherwise the content-type string to send in the response.
Пример #1
0
 /**
  * Sends an RPC request to the server and returns the result.
  *
  * @param string $request  PHP input stream (ignored).
  */
 public function getResponse($request)
 {
     ob_start(null, 1048576);
     $serverVars = $this->_request->getServerVars();
     switch ($serverVars['REQUEST_METHOD']) {
         case 'OPTIONS':
         case 'GET':
             if ($serverVars['REQUEST_METHOD'] == 'GET' && $this->_get['Cmd'] != 'OPTIONS' && stripos($serverVars['REQUEST_URI'], 'autodiscover/autodiscover.xml') === false) {
                 $this->_logger->debug('Accessing ActiveSync endpoing from browser or missing required data.');
                 throw new Horde_Rpc_Exception(Horde_Rpc_Translation::t('Trying to access the ActiveSync endpoint from a browser. Not Supported.'));
             }
             if (stripos($serverVars['REQUEST_URI'], 'autodiscover/autodiscover.xml') !== false) {
                 try {
                     if (!$this->_server->handleRequest('Autodiscover', null)) {
                         $this->_logger->err('Unknown error during Autodiscover.');
                         throw new Horde_Exception('Unknown Error');
                     }
                 } catch (Horde_Exception_AuthenticationFailure $e) {
                     $this->_sendAuthenticationFailedHeaders();
                     exit;
                 } catch (Horde_Exception $e) {
                     $this->_handleError($e);
                 }
                 break;
             }
             $this->_logger->debug('Horde_Rpc_ActiveSync::getResponse() starting for OPTIONS');
             try {
                 if (!$this->_server->handleRequest('Options', null)) {
                     throw new Horde_Exception('Unknown Error');
                 }
             } catch (Horde_Exception_AuthenticationFailure $e) {
                 $this->_sendAuthenticationFailedHeaders();
                 exit;
             } catch (Horde_Exception $e) {
                 $this->_handleError($e);
             }
             break;
         case 'POST':
             // Autodiscover Request
             if (stripos($serverVars['REQUEST_URI'], 'autodiscover/autodiscover.xml') !== false) {
                 $this->_get['Cmd'] = 'Autodiscover';
                 $this->_get['DeviceId'] = null;
             }
             $this->_logger->debug('Horde_Rpc_ActiveSync::getResponse() starting for ' . $this->_get['Cmd']);
             try {
                 $ret = $this->_server->handleRequest($this->_get['Cmd'], $this->_get['DeviceId']);
                 if ($ret === false) {
                     throw new Horde_Rpc_Exception(sprintf('Received FALSE while handling %s command.', $this->_get['Cmd']));
                 } elseif ($ret !== true) {
                     $this->_contentType = $ret;
                 }
             } catch (Horde_ActiveSync_Exception_InvalidRequest $e) {
                 $this->_logger->err(sprintf('Returning HTTP 400 while handling %s command', $this->_get['Cmd']));
                 $this->_handleError($e);
                 header('HTTP/1.1 400 Invalid Request ' . $e->getMessage());
                 exit;
             } catch (Horde_Exception_AuthenticationFailure $e) {
                 $this->_sendAuthenticationFailedHeaders();
                 exit;
             } catch (Horde_Exception $e) {
                 $this->_logger->err(sprintf('Returning HTTP 500 while handling %s command.', $this->_get['Cmd']));
                 $this->_handleError($e);
                 header('HTTP/1.1 500 ' . $e->getMessage());
                 exit;
             }
             break;
     }
 }