Horde_SyncMl_ContentHandler::process PHP Method

process() public method

Here's were all the processing takes place: gets the SyncML request data and returns a SyncML response. The only thing that needs to be in place before invoking this public function is a working backend.
public process ( string $request, string $contentType, string $respURI = null )
$request string The raw request string.
$contentType string The MIME content type of the request. Should be either application/vnd.syncml or application/vnd.syncml+wbxml.
$respURI string The url of the server endpoint. Will be returned in the RespURI element.
    public function process($request, $contentType, $respURI = null)
    {
        $isWBXML = $contentType == 'application/vnd.syncml+wbxml';
        $this->_respURI = $respURI;
        /* Catch any errors/warnings/notices that may get thrown while
         * processing. Don't want to let anything go to the client that's not
         * part of the valid response. */
        ob_start();
        $GLOBALS['backend']->logFile(Horde_SyncMl_Backend::LOGFILE_CLIENTMESSAGE, $request, $isWBXML);
        if (!$isWBXML) {
            /* XML code. */
            /* try to extract charset from XML text */
            if (preg_match('/^\\s*<\\?xml[^>]*encoding\\s*=\\s*"([^"]*)"/i', $request, $m)) {
                $charset = $m[1];
            } else {
                $charset = 'UTF-8';
            }
            $GLOBALS['backend']->setCharset($charset);
            /* Init output handler. */
            $this->_xmlWriter =& Horde_SyncMl_XmlOutput::singleton();
            /* Horde_Xml_Wbxml_ContentHandler Is a class that produces plain XML
             * output. */
            $this->_xmlWriter->init(new Horde_Xml_Wbxml_ContentHandler());
            /* Create the XML parser and set method references. */
            $parser = xml_parser_create_ns($charset);
            xml_set_object($parser, $this);
            xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
            xml_set_element_handler($parser, '_startElement', '_endElement');
            xml_set_character_data_handler($parser, '_characters');
            xml_set_processing_instruction_handler($parser, '');
            xml_set_external_entity_ref_handler($parser, '');
            /* Here we go: fire off events: */
            if (!xml_parse($parser, $request)) {
                $s = sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser));
                $GLOBALS['backend']->logMessage($s, 'ERR');
                xml_parser_free($parser);
                return new PEAR_Error($s);
            }
            xml_parser_free($parser);
        } else {
            /* The decoder works like the parser in the XML code above: It
             * parses the input and calls the callback functions of $this. */
            $this->_wbxmlparser = new Horde_Xml_Wbxml_Decoder();
            $this->_wbxmlparser->setContentHandler($this);
            /* Init output handler. */
            $this->_xmlWriter =& Horde_SyncMl_XmlOutput::singleton();
            $this->_xmlWriter->init(new Horde_Xml_Wbxml_Encoder());
            /* Here we go: fire off events: */
            /* @todo catch exceptions */
            $this->_wbxmlparser->decode($request);
        }
        $id = @session_id();
        $sessionclose = empty($id);
        $output = $this->getOutput();
        if (!$isWBXML) {
            $output = '<?xml version="1.0" encoding="' . $charset . '"?>' . $output;
        }
        $GLOBALS['backend']->logFile(Horde_SyncMl_Backend::LOGFILE_SERVERMESSAGE, $output, $isWBXML, $sessionclose);
        /* Clear the output buffer that we started above, and log anything
         * that came up for later debugging. */
        $errorLogging = ob_get_clean();
        if (!empty($errorLogging)) {
            $GLOBALS['backend']->logMessage('Caught output: ' . $errorLogging, 'WARN');
        }
        return $output;
    }

Usage Example

コード例 #1
0
ファイル: Syncml.php プロジェクト: horde/horde
 /**
  * Sends an RPC request to the server and returns the result.
  *
  * @param string $request  The raw request string.
  *
  * @return string  The XML encoded response from the server.
  */
 function getResponse($request)
 {
     $backendparms = array('debug_dir' => Horde::getTempDir() . '/sync', 'debug_files' => true, 'log_level' => 'DEBUG');
     /* Create the backend. */
     $GLOBALS['backend'] = Horde_SyncMl_Backend::factory('Horde', $backendparms);
     /* Handle request. */
     $h = new Horde_SyncMl_ContentHandler();
     $response = $h->process($request, $this->getResponseContentType(), Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/rpc.php', true, -1));
     /* Close the backend. */
     $GLOBALS['backend']->close();
     return $response;
 }
All Usage Examples Of Horde_SyncMl_ContentHandler::process