<?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'common.php'; // create and configure the node connecton object $node = new Services_HyperEstraier_Node(); $node->setUrl($uri); $node->setAuth($user, $pass); // create a document object $doc = new Services_HyperEstraier_Document(); // add attributes to the document object $doc->addAttribute('@uri', 'http://estraier.example.com/example.txt'); $doc->addAttribute('@title', 'Bridge Over The Troubled Water'); // add the body text to the document object $doc->addText('Like a bridge over the troubled water,'); $doc->addText('I will ease your mind.'); // register the document object to the node if (!$node->putDocument($doc)) { fprintf(STDERR, "error: %d\n", $node->status); if (Services_HyperEstraier_Error::hasErrors()) { fputs(STDERR, print_r(Services_HyperEstraier_Error::getErrors(), true)); } } else { fputs(STDOUT, "success.\n"); }
/** * Get a node object. * * @param string $url The url of a node server. * Also includes the username and the password. * @return object Services_HyperEstraier_Node * @throws InvalidArgumentException * @access private * @static * @ignore */ private static function _getNode($url) { static $node = null; static $checksum = ''; // parse the url if (!is_string($url)) { throw new InvalidArgumentException(sprintf('Argument#2 should be a kind of integer or string, %s given.', gettype($id))); } if (!($purl = @parse_url($url)) || !isset($purl['scheme']) || strcasecmp($purl['scheme'], 'http') != 0 || !isset($purl['host']) || !isset($purl['path']) || (isset($purl['user']) xor isset($purl['pass']))) { throw new InvalidArgumentException('Invalid URL given.'); } // check if the node object is cached $newchecksum = md5($url); if ($checksum != $newchecksum) { $node = new Services_HyperEstraier_Node(); $nurl = 'http://' . $purl['host']; if (isset($purl['port'])) { $nurl .= ':' . $purl['port']; } $nurl .= $purl['path']; $node->setUrl($nurl); if (isset($purl['user']) && isset($purl['pass'])) { $node->setAuth($purl['user'], $purl['pass']); } $checksum = $newchecksum; } return $node; }