/** * 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; } } }
/** * 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; } } }
################################################################################ # # # WOOPS - Web Object Oriented Programming System # # # # COPYRIGHT NOTICE # # # # Copyright (C) 2009 Jean-David Gadina - www.xs-labs.com # # All rights reserved # ################################################################################ # $Id$ // Includes the initialization script require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'init.inc.php'; // Plain text content header('Content-Type: text/plain'); // Creates some cookies $FOO = new Woops_Http_Cookie('foo', 'WOOPS-test-cookie-1'); $BAR = new Woops_Http_Cookie('bar', 'WOOPS-test-cookie-2'); // Sets the cookies $FOO->set(); $BAR->set(); // Prints the POST data print 'POST data ($_POST): '; print_r($_POST); // Separator print chr(10) . '-----' . chr(10) . chr(10); // Prints the uploaded files print 'Uploaded files ($_FILES): '; print_r($_FILES); // Aborts the script exit;