示例#1
0
 /**
  * Set the URI for the next request
  *
  * @param  EUriHttp|string $uri
  * @return EHttpClient
  * @throws EHttpClientException
  */
 public function setUri($uri)
 {
     if ($uri instanceof EUriHttp) {
         $uri = clone $uri;
     } elseif (is_string($uri)) {
         $uri = EUri::factory($uri);
     }
     if (!$uri instanceof EUriHttp) {
         throw new EHttpClientException(Yii::t('EHttpClient', 'Passed parameter is not a valid HTTP URI.'));
     }
     if ($uri->getUsername() && $uri->getPassword()) {
         $this->setAuth($uri->getUsername(), $uri->getPassword());
     }
     // We have no ports, set the defaults
     if (!$uri->getPort()) {
         $uri->setPort($uri->getScheme() == 'https' ? 443 : 80);
     }
     $this->uri = $uri;
     return $this;
 }
示例#2
0
 /**
  * Get a specific cookie according to a URI and name
  *
  * @param EUriHttp|string $uri The uri (domain and path) to match
  * @param string $cookie_name The cookie's name
  * @param int $ret_as Whether to return cookies as objects of EHttpCookieJar or as strings
  * @return EHttpCookieJar|string
  */
 public function getCookie($uri, $cookie_name, $ret_as = self::COOKIE_OBJECT)
 {
     if (is_string($uri)) {
         $uri = EUri::factory($uri);
     }
     if (!$uri instanceof EUriHttp) {
         throw new CException('Invalid URI specified');
     }
     // Get correct cookie path
     $path = $uri->getPath();
     $path = substr($path, 0, strrpos($path, '/'));
     if (!$path) {
         $path = '/';
     }
     if (isset($this->cookies[$uri->getHost()][$path][$cookie_name])) {
         $cookie = $this->cookies[$uri->getHost()][$path][$cookie_name];
         switch ($ret_as) {
             case self::COOKIE_OBJECT:
                 return $cookie;
                 break;
             case self::COOKIE_STRING_ARRAY:
             case self::COOKIE_STRING_CONCAT:
                 return $cookie->__toString();
                 break;
             default:
                 throw new CException("Invalid value passed for \$ret_as: {$ret_as}");
                 break;
         }
     } else {
         return false;
     }
 }