Documentation is available at backend_xmltcp.php
- <?php
- /**
- * @package midcom.services
- * @author The Midgard Project, http://www.midgard-project.org
- * @version $Id: backend_xmltcp.php,v 1.2 2005/04/16 16:46:39 torben Exp $
- * @copyright The Midgard Project, http://www.midgard-project.org
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
- */
- require_once 'XMLCommClient.php';
- /**
- * XMLComm implementation using a TCP/IP interface.
- *
- * ...
- *
- * @abstract Abstract indexer backend class
- * @package midcom.services
- * @see midcom_services_indexer
- * @see midcom_services_indexer_backend
- * @see midcom_services_indexer_XMLComm_RequestWriter
- * @see midcom_services_indexer_XMLComm_ResponseParser
- *
- * @todo Check if there is a better way to handle the exec loop, which looks rather PHP-workaroundy right now.
- */
- class midcom_services_indexer_backend_xmltcp extends midcom_services_indexer_backend
- {
- /**
- * The request to execute.
- *
- * @access private
- * @var midcom_services_indexer_XMLComm_RequestWriter
- */
- var $_request = null;
- /**
- * The response received.
- *
- * @access private
- * @var midcom_services_indexer_XMLComm_ResponseParser
- */
- var $_response = null;
- /**
- * Constructor is empty at this time.
- */
- function midcom_services_indexer_backend_xmltcp ()
- {
- parent::midcom_services_indexer_backend();
- // Nothing to do yet.
- }
- /**
- * Adds a document to the index.
- *
- * Any warning will be treated as error.
- *
- * Note, that $document may also be an array of documents without further
- * changes to this backend.
- *
- * @param Array $documents A list of midcom_services_indexer_document objects.
- * @return bool Indicating success.
- */
- function index ($documents)
- {
- $this->_request = new midcom_services_indexer_XMLComm_RequestWriter();
- $this->_request->add_index(0, $documents);
- $this->_exec();
- return (! array_key_exists(0, $this->_response->warnings));
- }
- /**
- * Removes the document with the given resource identifier from the index.
- *
- * @param string $RI The resource identifier of the document that should be deleted.
- * @return bool Indicating success.
- */
- function delete ($RI)
- {
- $this->_request = new midcom_services_indexer_XMLComm_RequestWriter();
- $this->_request->add_delete(0, $RI);
- $this->_exec();
- return (! array_key_exists(0, $this->_response->warnings));
- }
- /**
- * Clear the index completly.
- *
- * This will drop the current index.
- *
- * @return bool Indicating success.
- */
- function delete_all()
- {
- $this->_request = new midcom_services_indexer_XMLComm_RequestWriter();
- $this->_request->add_deleteall(0);
- $this->_exec();
- return (! array_key_exists(0, $this->_response->warnings));
- }
- /**
- * Query the index and, if set, restrict the query by a given filter.
- *
- * ...
- *
- * @param string $query The query, which must suite the backends query syntax.
- * @param midcom_services_indexer_filter $filter An optional filter used to restrict the query. This may be null indicating no filter.
- * @return Array An arary of documents matching the query, or false on a failure.
- */
- function query ($query, $filter)
- {
- $this->_request = new midcom_services_indexer_XMLComm_RequestWriter();
- $this->_request->add_query(0, $query, $filter);
- $this->_exec();
- if (array_key_exists(0, $this->_response->warnings))
- {
- return false;
- }
- return $this->_response->resultsets[0];
- }
- /**
- * This private helper will create a socket connection to the indexer daemon and
- * execute the query.
- *
- * Note, that both classes call generate_error on critical errors.
- */
- function _exec ()
- {
- debug_push_class($this, 'exec');
- $errstr = '';
- $errcode = 0;
- $socket = @fsockopen($GLOBALS['midcom_config']['indexer_xmltcp_host'],
- $GLOBALS['midcom_config']['indexer_xmltcp_port'],
- $errstr, $errcode);
- if (! $socket)
- {
- $GLOBALS['midcom']->generate_error(MIDCOM_ERRCRIT, "Failed to establish a connection to the indexer: {$errstr} ({$errcode})");
- // This will exit
- }
- $xml = $this->_request->get_xml(true);
- debug_print_r('Will send this request:', $xml);
- fwrite($socket, $xml);
- $response = '';
- while (! feof($socket))
- {
- $response .= fread($socket, 4096);
- }
- fclose($socket);
- debug_print_r('We got this response:', $response);
- $this->_response = new midcom_services_indexer_XMLComm_ResponseReader();
- $this->_response->parse($response);
- foreach ($this->_response->warnings as $id => $warning)
- {
- debug_add("Failed to execute Request {$id}: {$warning}", MIDCOM_LOG_WARN);
- }
- debug_pop();
- }
- }
- ?>
Documentation generated on Mon, 21 Nov 2005 18:12:26 +0100 by phpDocumentor 1.3.0RC3