Exemplo n.º 1
0
 /**
  * Return a subset of a domain-matching cookies that also match a specified path
  *
  * @param array $dom_array
  * @param string $path
  * @return array
  */
 protected function _matchPath($domains, $path)
 {
     $ret = array();
     foreach ($domains as $dom => $paths_array) {
         foreach (array_keys($paths_array) as $cpath) {
             if (IfwPsn_Vendor_Zend_Http_Cookie::matchCookiePath($cpath, $path)) {
                 if (!isset($ret[$dom])) {
                     $ret[$dom] = array();
                 }
                 $ret[$dom][$cpath] = $paths_array[$cpath];
             }
         }
     }
     return $ret;
 }
Exemplo n.º 2
0
 /**
  * Add a cookie to the request. If the client has no Cookie Jar, the cookies
  * will be added directly to the headers array as "Cookie" headers.
  *
  * @param IfwPsn_Vendor_Zend_Http_Cookie|string $cookie
  * @param string|null $value If "cookie" is a string, this is the cookie value.
  * @return IfwPsn_Vendor_Zend_Http_Client
  * @throws IfwPsn_Vendor_Zend_Http_Client_Exception
  */
 public function setCookie($cookie, $value = null)
 {
     IfwPsn_Zend_Loader::loadClass('IfwPsn_Vendor_Zend_Http_Cookie');
     if (is_array($cookie)) {
         foreach ($cookie as $c => $v) {
             if (is_string($c)) {
                 $this->setCookie($c, $v);
             } else {
                 $this->setCookie($v);
             }
         }
         return $this;
     }
     if ($value !== null && $this->config['encodecookies']) {
         $value = urlencode($value);
     }
     if (isset($this->cookiejar)) {
         if ($cookie instanceof IfwPsn_Vendor_Zend_Http_Cookie) {
             $this->cookiejar->addCookie($cookie);
         } elseif (is_string($cookie) && $value !== null) {
             $cookie = IfwPsn_Vendor_Zend_Http_Cookie::fromString("{$cookie}={$value}", $this->uri, $this->config['encodecookies']);
             $this->cookiejar->addCookie($cookie);
         }
     } else {
         if ($cookie instanceof IfwPsn_Vendor_Zend_Http_Cookie) {
             $name = $cookie->getName();
             $value = $cookie->getValue();
             $cookie = $name;
         }
         if (preg_match("/[=,; \t\r\n\v\f]/", $cookie)) {
             /** @see IfwPsn_Vendor_Zend_Http_Client_Exception */
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Http/Client/Exception.php';
             throw new IfwPsn_Vendor_Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\v\f ({$cookie})");
         }
         $value = addslashes($value);
         if (!isset($this->headers['cookie'])) {
             $this->headers['cookie'] = array('Cookie', '');
         }
         $this->headers['cookie'][1] .= $cookie . '=' . $value . '; ';
     }
     return $this;
 }