Пример #1
0
 /**
  * Class constructor
  * 
  * The constructor cannot be called from outside this class. Please use the
  * createResponseObject() static method to get an instance.
  * 
  * @param   int                             The HTTP response code
  * @param   array                           The HTTP response headers, as key/value pairs
  * @param   string                          The HTTP raw response body
  * @param   string                          The HTTP response body
  * @param   number                          The HTTP protocol version
  * @return  void
  * @throws  Woops_Http_Response_Exception   If the HTTP response code is invalid
  */
 protected function __construct($code, array $headers, $rawBody, $body, $httpVersion)
 {
     // Checks if the static variables are set
     if (!self::$_hasStatic) {
         // Sets the static variables
         self::_setStaticVars();
     }
     // Code and version should be numbers
     $code = (int) $code;
     $httpVersion = (double) $httpVersion;
     // Ensures the response code is valid
     if (!isset(self::$_codes[$code])) {
         // Invalid HTTP response code
         throw new Woops_Http_Response_Exception('Invalid HTTP code (' . $code . ')', Woops_Http_Response_Exception::EXCEPTION_INVALID_CODE);
     }
     // Stores the response informations
     $this->_code = $code;
     $this->_headers = $headers;
     $this->_httpVersion = $httpVersion;
     $this->_rawBody = $rawBody;
     $this->_body = $body;
     // Checks for the 'Set-Cookie' header
     if (isset($headers['Set-Cookie'])) {
         // Process each cookie
         foreach ($headers['Set-Cookie'] as $cookie) {
             // Creates a cookie object
             $cookie = Woops_Http_Cookie::createCookieObject(trim($cookie));
             // Stores the cookie object
             $this->_cookies[$cookie->getName()] = $cookie;
         }
     }
 }
Пример #2
0
 /**
  * Adds a cookie
  * 
  * @param   mixed                       Either a string, or a Woops_Http_Cookie object
  * @return  void
  * @throws  Woops_Http_Client_Exception If the connection has already been established
  */
 public function addCookie($cookie)
 {
     // Checks the connect flag
     if ($this->_connected) {
         // Connection has been established
         throw new Woops_Http_Client_Exception('The connection has already been established', Woops_Http_Client_Exception::EXCEPTION_CONNECTED);
     }
     // Checks if the passed argument is a cookie object
     if (is_object($cookie) && $cookie instanceof Woops_Http_Cookie) {
         // Stores the cookie object
         $this->_cookies[$cookie->getName()] = $cookie;
     } else {
         // Gets the cookies
         $cookies = explode(';', $cookie);
         // Process each cookie
         foreach ($cookies as $cookie) {
             // Creates a new cookie object
             $cookie = Woops_Http_Cookie::createCookieObject($cookie);
             // Stores the cookie object
             $this->_cookies[$cookie->getName()] = $cookie;
         }
     }
 }