* @author Tobias Hauser
*/
class UDDI extends PEAR
{
// {{{ properties
/**
* version of package
* @var string $_version
*/
var $_version = '0.2.0alpha4';
/**
* list of known registries
* @var array $regarray
*/
var $_regarray =
array('IBM' =>
array('Inquiry' =>
array('url' => 'www-3.ibm.com/services/uddi/testregistry/inquiryapi',
'port' => 80),
'Publish' =>
array('url' => 'https://www-3.ibm.com/services/uddi/testregistry/protect/publishapi',
'port' => 443)),
'Microsoft' =>
array('Inquiry' =>
array('url' => 'test.uddi.microsoft.com/inquire',
'port' => 80),
'Publish' =>
array('url' => 'https://test.uddi.microsoft.com/publish',
'port' => 443)));
/**
* which API to use (Inquiry/Publish)
* @var string $_api
*/
var $_api = 'Inquiry';
/**
* used XML namespace
* @var string $_xmlns
*/
var $_xmlns = 'urn:uddi-org:api';
/**
* used UDDI version
* @var string $_uddiversion
*/
var $_uddiversion = 1;
/**
* used XML generic version
* @var string $_generic
*/
var $_generic;
/**
* debug mode
* @var boolean $_debug
*/
var $_debug = false;
/**
* Turns on _posting of UDDI message to UBR
* @var boolean $_transmit
*/
var $_transmit = true;
/**
* Host to use
* @var string $_host
*/
var $_host;
/**
* URL to use
* @var string $_url
*/
var $_url;
// }}}
// {{{ constructor
/**
* constructor
*
* @access public
* @param string $registry name of registry to use
* @param integer $version UDDI version to use
*/
function UDDI($registry = 'IBM', $version = 1)
{
$this->splitUrl($registry, $version);
}
// }}}
// {{{ splitUrl()
/**
* retrieves information from URL and sets params
*
* @access public
* @param string $registry name of registry to use
* @param integer $version UDDI version to use
*/
function splitUrl($registry, $version)
{
$this->_registry = $registry;
$reg = $this->_regarray[$this->_registry][$this->_api]['url'];
$reg = str_replace('http://', '', $reg);
$pos = strpos($reg, '/')
or PEAR::raiseError("Invalid registry (POS = $pos, URL = '$reg')\n");
$this->_host = substr($reg, 0, $pos);
$this->_url = substr($reg, $pos, strlen($reg) - 1);
if ($version > 1) {
$this->_xmlns .= "_v$version";
}
$this->_generic = "$version.0";
}
// }}}
// {{{ post()
/**
* assembles HTTP headers and posts these and the UDDI message to the UBR
*
* @access public
* @param string $message the UDDI message to send
* @return string $data data returned from the UBR
*/
function post($message)
{
$msg_length = strlen($message);
$php_version = phpversion();
$date = str_replace('+0000', 'GMT', gmdate('r', time()));
$header = '';
$header .= "POST $this->_url HTTP/1.0\r\n";
$header .= "Date: $date\r\n";
$header .= "Content-Type: text/xml; charset=UTF-8\r\n";
$header .= "User-agent: PEAR::UDDI/$this->_version php/$php_version\r\n";
$header .= "Host: $this->_host\r\n";
$header .= "SOAPAction: \"\"\r\n";
$header .= "Content-Length: $msg_length\r\n\r\n";
// echoes HTTP header and UDDI message to page if true
if ($this->_debug) {
echo '' . htmlspecialchars(str_replace('><', ">\n<", $header . $message)) . '';
}
// sends header and message to UBR if true
if ($this->_transmit) {
$port = $this->_regarray[$this->_registry][$this->_api]['port'];
$fp = fsockopen($this->_host, $port, $errno, $errstr, 5)
or PEAR::raiseError("Couldn't connect to server at $this->_host:$port. Error #$errno: $errstr.");
fputs($fp, $header)
or PEAR::raiseError('Couldn\'t send HTTP headers.');
fputs($fp, "$message\n\n")
or PEAR::raiseError('Couldn\'t send UDDI message.');
$response = '';
while (!feof($fp)) {
$response .= fgets($fp, 1024)
or PEAR::raiseError('No response from server.');
}
fclose($fp)
or PEAR::raiseError('Warning: Couldn\'t close HTTP connection.');
$response = str_replace('><', ">\n<", $response);
return $response;
}
}
// }}}
// {{{ query()
/**
* sends and UDDI query to the registry server
*
* @access public
* @param string $method the UDDI message to send
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function query($method, $params)
{
$message = $this->assemble($method, $params);
return $this->post($message);
}
// }}}
// {{{ assemble()
/**
* generate XML creating the UDDI query
*
* @access public
* @param string $method the UDDI message to send
* @param array $params parameters for the query
* @return string $data the desired XML query code
*/
function assemble($method, $params)
{
$head = '';
$head .= '';
$head .= '';
$end = "$method>";
$attrib = '';
$element = '';
if (isset($params['discoveryURLs']) && ($params['discoveryURLs'] != '')) {
$element .= '' . $params['discoveryURLs'] . '';
}
if (isset($params['bindingKey']) && ($params['bindingKey'] != '')) {
$element .= '' . $params['bindingKey'] . '';
}
if (isset($params['businessKey']) && ($params['businessKey'] != '')) {
$element .= '' . $params['businessKey'] . '';
}
if (isset($params['serviceKey']) && ($params['serviceKey'] != '')) {
if ($method == 'find_binding') {
$attrib .= ' serviceKey="' . $params['serviceKey'] . '"';
}
if ($method == 'get_serviceDetail') {
$element .= '' . $params['serviceKey'] . '';
}
}
if (isset($params['tModelKey']) && ($params['tModelKey'] != '')) {
$element .= 'uuid:' . $params['tModelKey'] . '';
}
if (isset($params['findQualifiers']) && ($params['findQualifiers'] != '')) {
$element .= '';
$findQualifiers = explode(',', $params['findQualifiers']);
for ($i = 0; $i < count($findQualifiers); $i++) {
$element .= '' . $findQualifiers[$i] . '';
}
$element .= '';
}
if (isset($params['tModelBag']) && ($params['tModelBag'] != '')) {
$tModelKey = explode(',', $params['tModelBag']);
$element .= '';
for ($i = 0; $i < count($tModelKey); $i++) {
$element .= 'uuid:' . $tModelKey[$i] . '';
$element .= '';
}
}
if (isset($params['name']) && ($params['name'] != '')) {
$lang = '';
if (isset($params['lang']) && ($params['lang'] != '')) {
$lang = "xml:lang=\"$lang\"";
}
$element .= '' . $params['name'] . '';
}
if (isset($params['identifierBag']) && ($params['identifierBag'] != '')) {
$element .= '';
$keyedReference = explode(',', $params['identifierBag']);
for ($i = 0; $i < count($keyedReference); $i++) {
$element .= '' . $keyedReference[$i] . '';
}
$element .= '';
}
if (isset($params['categoryBag']) && ($params['categoryBag'] != '')) {
$element .= '';
$keyedReference = explode(',', $params['identifierBag']);
for ($i = 0; $i';
}
$element .= '';
}
if (isset($params['maxRows']) && ($params['maxRows'] != '')) {
$attrib .= ' maxRows="' . $params['maxRows'] . '"';
}
$head .= "<$method $attrib xmlns=\"$this->_xmlns\" generic=\"$this->_generic\">";
$message = $head;
$message .= $element;
$message .= $end;
return $message;
}
// }}}
// {{{ find_binding()
/**
* Sends find_binding inquiry to UBR (searchs for bindings within a businessService element)
*
* @access public
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function find_binding($params)
{
$data = $this->query('find_binding', $params);
return $data;
}
// }}}
// {{{ find_business()
/**
* Sends find_business inquiry to UBR (searchs businessEntity elements)
*
* @access public
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function find_business($params)
{
$data = $this->query('find_business', $params);
return $data;
}
// }}}
// {{{ find_relatedBusinesses()
/**
* Sends find_relatedBusinesses inquiry to UBR (searchs for related businessEntity elements for a given businessKey)
*
* @access public
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function find_relatedBusinesses($params)
{
$data = $this->query('find_relatedBusinesses', $params);
return $data;
}
// }}}
// {{{ find_service()
/**
* Sends find_service inquiry to UBR (searchs for businessService elements)
*
* @access public
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function find_service($params)
{
$data = $this->query('find_service', $params);
return $data;
}
// }}}
// {{{ find_tModel()
/**
* Sends find_tModel inquiry to UBR (searchs for tModel elements)
*
* @access public
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function find_tModel($params)
{
$data = $this->query('find_tModel', $params);
return $data;
}
// }}}
// {{{ get_bindingDetail()
/**
* Sends get_bindingDetail inquiry to UBR (returns bindingDetail elements for one or more bindingKey elements)
*
* @access public
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function get_bindingDetail($params)
{
$data = $this->query('get_bindingDetail', $params);
return $data;
}
// }}}
// {{{ get_businessDetail()
/**
* Sends get_businessDetail inquiry to UBR (returns information about one or more businessEntity elements)
*
* @access public
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function get_businessDetail($params)
{
$data = $this->query('get_businessDetail', $params);
return $data;
}
// }}}
// {{{ get_businessDetailExt()
/**
* Sends get_businessDetailExt inquiry to UBR (returns extended information about one or more businessEntity elements)
*
* @access public
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function get_businessDetailExt($params)
{
$data = $this->query('get_businessDetailExt', $params);
return $data;
}
// }}}
// {{{ get_serviceDetail()
/**
* Sends get_serviceDetail inquiry to UBR (returns information about one or more businessService elements)
*
* @access public
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function get_serviceDetail($params)
{
$data = $this->query('get_serviceDetail', $params);
return $data;
}
// }}}
// {{{ get_tModelDetail()
/**
* Sends get_tModelDetail inquiry to UBR (returns information about one or more tModel elements)
*
* @access public
* @param array $params parameters for the query
* @return string $data response from the registry server
*/
function get_tModelDetail($params)
{
$data = $this->query('get_tModelDetail', $params);
return $data;
}
// }}}
}
// }}}
?>
|