Пример #1
0
 /**
  * Return a singleton instance of this class.
  *
  * @return  Services_Yadis_Xri
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Пример #2
0
 /**
  * Performs Service Discovery, i.e. the requesting and parsing of a valid
  * Yadis (XRD) document into a list of Services and Service Data. The
  * return value will be an instance of Services_Yadis_Xrds which will
  * implement SeekableIterator. Returns FALSE on failure.
  *
  * @return Services_Yadis_Xrds|boolean
  * @throws Services_Yadis_Exception
  */
 public function discover()
 {
     $currentUri = $this->getYadisUrl();
     $xrdsDocument = null;
     $request = null;
     $xrdStatus = false;
     // Check XRI first
     if (in_array($this->yadisId[0], $this->xriIdentifiers)) {
         $xri = Services_Yadis_Xri::getInstance();
         $xrds = $xri->toCanonicalID($xri->getXri());
         $this->httpResponse = $xri->getHTTPResponse();
         return new Services_Yadis_Xrds_Service($xrds, $this->namespace);
     }
     while ($xrdsDocument === null) {
         $this->httpResponse = $this->get($currentUri);
         $responseType = $this->getResponseType($this->httpResponse);
         /**
          * If prior response type was a location header, or a http-equiv
          * content value, then it should have contained a valid URI to
          * an XRD document. Each of these when detected would set the
          * xrdStatus flag to true.
          */
         if (!$responseType == self::XRDS_CONTENT_TYPE && $xrdStatus == true) {
             throw new Services_Yadis_Exception('Yadis protocol could not locate a valid XRD document');
         }
         /**
          * The Yadis Spec 1.0 specifies that we must use a valid response
          * header in preference to other responses. So even if we receive
          * an XRDS Content-Type, if it also includes an X-XRDS-Location
          * header we must request the Location URI and ignore the response
          * body.
          */
         switch ($responseType) {
             case self::XRDS_LOCATION_HEADER:
                 $xrdStatus = true;
                 $currentUri = $this->xrdsLocationHeaderUrl;
                 break;
             case self::XRDS_META_HTTP_EQUIV:
                 $xrdStatus = true;
                 $currentUri = $this->metaHttpEquivUrl;
                 break;
             case self::XRDS_CONTENT_TYPE:
                 $xrdsDocument = $this->httpResponse->getBody();
                 break;
             default:
                 throw new Services_Yadis_Exception('Yadis protocol could not locate a valid XRD document');
         }
     }
     try {
         $serviceList = $this->parseXrds($xrdsDocument);
     } catch (PEAR_Exception $e) {
         throw new Services_Yadis_Exception('XRD Document could not be parsed with the following message: ' . $e->getMessage(), $e->getCode());
     }
     return $serviceList;
 }