Changeset 7714
- Timestamp:
- 03/02/08 14:51:08 (1 year ago)
- Files:
-
- branches/1.1/lib/debug/sfDebug.class.php (modified) (2 diffs)
- branches/1.1/lib/response/sfResponse.class.php (modified) (8 diffs)
- branches/1.1/lib/response/sfWebResponse.class.php (modified) (12 diffs)
- branches/1.1/test/unit/response/sfResponseTest.php (modified) (3 diffs)
- branches/1.1/test/unit/response/sfWebResponseTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/debug/sfDebug.class.php
r5342 r7714 95 95 public static function requestAsArray($request) 96 96 { 97 if ( $request)97 if (!$request) 98 98 { 99 $values = array( 100 'parameterHolder' => self::flattenParameterHolder($request->getParameterHolder()), 101 'attributeHolder' => self::flattenParameterHolder($request->getAttributeHolder()), 102 ); 103 } 104 else 105 { 106 $values = array('parameterHolder' => array(), 'attributeHolder' => array()); 99 return array(); 107 100 } 108 101 109 return $values; 102 return array( 103 'parameterHolder' => self::flattenParameterHolder($request->getParameterHolder()), 104 'attributeHolder' => self::flattenParameterHolder($request->getAttributeHolder()), 105 ); 110 106 } 111 107 … … 119 115 public static function responseAsArray($response) 120 116 { 121 if ( $response)117 if (!$response) 122 118 { 123 $values = array( 124 'cookies' => array(), 125 'httpHeaders' => array(), 126 'parameterHolder' => self::flattenParameterHolder($response->getParameterHolder()), 127 ); 128 if (method_exists($response, 'getHttpHeaders')) 129 { 130 foreach ($response->getHttpHeaders() as $key => $value) 131 { 132 $values['httpHeaders'][$key] = $value; 133 } 134 } 135 136 if (method_exists($response, 'getCookies')) 137 { 138 $cookies = array(); 139 foreach ($response->getCookies() as $key => $value) 140 { 141 $values['cookies'][$key] = $value; 142 } 143 } 144 } 145 else 146 { 147 $values = array('cookies' => array(), 'httpHeaders' => array(), 'parameterHolder' => array()); 119 return array(); 148 120 } 149 121 150 return $values; 122 return array( 123 'options' => $response->getOptions(), 124 'cookies' => method_exists($response, 'getCookies') ? $response->getCookies() : array(), 125 'httpHeaders' => method_exists($response, 'getHttpHeaders') ? $response->getHttpHeaders() : array(), 126 'javascripts' => method_exists($response, 'getJavascripts') ? $response->getJavascripts('ALL') : array(), 127 'stylesheets' => method_exists($response, 'getStylesheets') ? $response->getStylesheets('ALL') : array(), 128 'metas' => method_exists($response, 'getMetas') ? $response->getMetas() : array(), 129 'httpMetas' => method_exists($response, 'getHttpMetas') ? $response->getHttpMetas() : array(), 130 ); 151 131 } 152 132 branches/1.1/lib/response/sfResponse.class.php
r7215 r7714 21 21 { 22 22 protected 23 $ parameterHolder = null,24 $dispatcher = null,25 $content = '';23 $options = array(), 24 $dispatcher = null, 25 $content = ''; 26 26 27 27 /** … … 30 30 * @see initialize() 31 31 */ 32 public function __construct(sfEventDispatcher $dispatcher, $ parameters = array())32 public function __construct(sfEventDispatcher $dispatcher, $options = array()) 33 33 { 34 $this->initialize($dispatcher, $ parameters);34 $this->initialize($dispatcher, $options); 35 35 } 36 36 … … 39 39 * 40 40 * @param sfEventDispatcher A sfEventDispatcher instance 41 * @param array An array of parameters41 * @param array An array of options 42 42 * 43 43 * @return Boolean true, if initialization completes successfully, otherwise false … … 45 45 * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfResponse 46 46 */ 47 public function initialize(sfEventDispatcher $dispatcher, $ parameters = array())47 public function initialize(sfEventDispatcher $dispatcher, $options = array()) 48 48 { 49 49 $this->dispatcher = $dispatcher; 50 $this->options = $options; 50 51 51 $this->parameterHolder = new sfParameterHolder(); 52 $this->parameterHolder->add($parameters); 52 if (!isset($this->options['logging'])) 53 { 54 $this->options['logging'] = false; 55 } 53 56 } 54 57 … … 81 84 $content = $event->getReturnValue(); 82 85 83 if ($this-> getParameter('logging'))86 if ($this->options['logging']) 84 87 { 85 88 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send content (%s o)', strlen($content))))); … … 97 100 } 98 101 99 /** 100 * Retrieves the parameters from the current response. 101 * 102 * @return sfParameterHolder List of parameters 103 */ 104 public function getParameterHolder() 102 public function getOptions() 105 103 { 106 return $this->parameterHolder; 107 } 108 109 /** 110 * Retrieves a parameter from the current response. 111 * 112 * @param string A parameter name 113 * @param string A default paramter value 114 * 115 * @return mixed A parameter value 116 */ 117 public function getParameter($name, $default = null) 118 { 119 return $this->parameterHolder->get($name, $default); 120 } 121 122 /** 123 * Indicates whether or not a parameter exist for the current response. 124 * 125 * @param string A parameter name 126 * 127 * @return boolean true, if the parameter exists otherwise false 128 */ 129 public function hasParameter($name) 130 { 131 return $this->parameterHolder->has($name); 132 } 133 134 /** 135 * Sets a parameter for the current response. 136 * 137 * @param string A parameter name 138 * @param string The parameter value to be set 139 */ 140 public function setParameter($name, $value) 141 { 142 $this->parameterHolder->set($name, $value); 104 return $this->options; 143 105 } 144 106 … … 171 133 public function serialize() 172 134 { 173 return serialize( array($this->content, $this->parameterHolder));135 return serialize($this->content); 174 136 } 175 137 … … 183 145 $this->initialize(sfContext::hasInstance() ? sfContext::getInstance()->getEventDispatcher() : new sfEventDispatcher()); 184 146 185 list($this->content, $this->parameterHolder)= $data;147 $this->content = $data; 186 148 } 187 149 } branches/1.1/lib/response/sfWebResponse.class.php
r7713 r7714 39 39 * 40 40 * @param sfEventDispatcher A sfEventDispatcher instance 41 * @param array An array of parameters41 * @param array An array of options 42 42 * 43 43 * @return Boolean true, if initialization completes successfully, otherwise false … … 45 45 * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfResponse 46 46 */ 47 public function initialize(sfEventDispatcher $dispatcher, $ parameters = array())48 { 49 parent::initialize($dispatcher, $ parameters);47 public function initialize(sfEventDispatcher $dispatcher, $options = array()) 48 { 49 parent::initialize($dispatcher, $options); 50 50 51 51 $this->javascripts = array_combine($this->positions, array_fill(0, count($this->positions), array())); 52 52 $this->stylesheets = array_combine($this->positions, array_fill(0, count($this->positions), array())); 53 54 if (!isset($this->options['charset'])) 55 { 56 $this->options['charset'] = 'utf-8'; 57 } 53 58 54 59 $this->statusTexts = array( … … 253 258 if (false === stripos($value, 'charset') && (0 === stripos($value, 'text/') || strlen($value) - 3 === strripos($value, 'xml'))) 254 259 { 255 $value .= '; charset='.$this-> getParameter('charset');260 $value .= '; charset='.$this->options['charset']; 256 261 } 257 262 … … 266 271 public function getContentType() 267 272 { 268 return $this->getHttpHeader('Content-Type', 'text/html; charset='.$this-> getParameter('charset'));273 return $this->getHttpHeader('Content-Type', 'text/html; charset='.$this->options['charset']); 269 274 } 270 275 … … 284 289 header($status); 285 290 286 if ($this-> getParameter('logging'))291 if ($this->options['logging']) 287 292 { 288 293 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send status "%s"', $status)))); … … 294 299 header($name.': '.$value); 295 300 296 if ($value != '' && $this-> getParameter('logging'))301 if ($value != '' && $this->options['logging']) 297 302 { 298 303 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send header "%s": "%s"', $name, $value)))); … … 312 317 } 313 318 314 if ($this-> getParameter('logging'))319 if ($this->options['logging']) 315 320 { 316 321 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send cookie "%s": "%s"', $cookie['name'], $cookie['value'])))); … … 378 383 else 379 384 { 380 throw new sfParameterException('The second getDate() method parameter must be one of: rfc1123, rfc1036 or asctime.');385 throw new InvalidArgumentException('The second getDate() method parameter must be one of: rfc1123, rfc1036 or asctime.'); 381 386 } 382 387 } … … 510 515 if ($escape) 511 516 { 512 $value = htmlentities($value, ENT_QUOTES, $this-> getParameter('charset'));517 $value = htmlentities($value, ENT_QUOTES, $this->options['charset']); 513 518 } 514 519 … … 679 684 public function mergeProperties(sfWebResponse $response) 680 685 { 681 $this-> parameterHolder = clone $response->getParameterHolder();682 $this->headers = $response->getHttpHeaders();683 $this->metas = $response->getMetas();684 $this->httpMetas = $response->getHttpMetas();685 $this->stylesheets = $response->getStylesheets('ALL');686 $this->javascripts = $response->getJavascripts('ALL');687 $this->slots = $response->getSlots();686 $this->options = $response->getOptions(); 687 $this->headers = $response->getHttpHeaders(); 688 $this->metas = $response->getMetas(); 689 $this->httpMetas = $response->getHttpMetas(); 690 $this->stylesheets = $response->getStylesheets('ALL'); 691 $this->javascripts = $response->getJavascripts('ALL'); 692 $this->slots = $response->getSlots(); 688 693 } 689 694 … … 695 700 public function serialize() 696 701 { 697 return serialize(array($this->content, $this->statusCode, $this->statusText, $this-> parameterHolder, $this->cookies, $this->headerOnly, $this->headers, $this->metas, $this->httpMetas, $this->stylesheets, $this->javascripts, $this->slots));702 return serialize(array($this->content, $this->statusCode, $this->statusText, $this->options, $this->cookies, $this->headerOnly, $this->headers, $this->metas, $this->httpMetas, $this->stylesheets, $this->javascripts, $this->slots)); 698 703 } 699 704 … … 707 712 $this->initialize(sfContext::hasInstance() ? sfContext::getInstance()->getEventDispatcher() : new sfEventDispatcher()); 708 713 709 list($this->content, $this->statusCode, $this->statusText, $this-> parameterHolder, $this->cookies, $this->headerOnly, $this->headers, $this->metas, $this->httpMetas, $this->stylesheets, $this->javascripts, $this->slots) = $data;714 list($this->content, $this->statusCode, $this->statusText, $this->options, $this->cookies, $this->headerOnly, $this->headers, $this->metas, $this->httpMetas, $this->stylesheets, $this->javascripts, $this->slots) = $data; 710 715 } 711 716 branches/1.1/test/unit/response/sfResponseTest.php
r5016 r7714 21 21 } 22 22 23 $t = new lime_test( 17, new lime_output_color());23 $t = new lime_test(7, new lime_output_color()); 24 24 25 25 $dispatcher = new sfEventDispatcher(); … … 28 28 $t->diag('->initialize()'); 29 29 $response = new myResponse($dispatcher, array('foo' => 'bar')); 30 $t->is($response->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument'); 30 $options = $response->getOptions(); 31 $t->is($options['foo'], 'bar', '->initialize() takes an array of options as its second argument'); 31 32 32 33 // ->getContent() ->setContent() … … 47 48 $t->ok(new myResponse($dispatcher) instanceof Serializable, 'sfResponse implements the Serializable interface'); 48 49 49 // parameter holder proxy50 require_once($_test_dir.'/unit/sfParameterHolderTest.class.php');51 $response = new myResponse($dispatcher);52 $pht = new sfParameterHolderProxyTest($t);53 $pht->launchTests($response, 'parameter');54 55 50 // new methods via sfEventDispatcher 56 51 require_once($_test_dir.'/unit/sfEventDispatcherTest.class.php'); branches/1.1/test/unit/response/sfWebResponseTest.php
r7713 r7714 98 98 $t->diag('->getContentType() ->setContentType()'); 99 99 100 $response->setParameter('charset', 'UTF-8'); 101 102 $t->is($response->getContentType(), 'text/html; charset=UTF-8', '->getContentType() returns a sensible default value'); 100 $t->is($response->getContentType(), 'text/html; charset=utf-8', '->getContentType() returns a sensible default value'); 103 101 104 102 $response->setContentType('text/xml'); 105 $t->is($response->getContentType(), 'text/xml; charset= UTF-8', '->setContentType() adds a charset if none is given');103 $t->is($response->getContentType(), 'text/xml; charset=utf-8', '->setContentType() adds a charset if none is given'); 106 104 107 105 $response->setContentType('application/vnd.mozilla.xul+xml'); 108 $t->is($response->getContentType(), 'application/vnd.mozilla.xul+xml; charset= UTF-8', '->setContentType() adds a charset if none is given');106 $t->is($response->getContentType(), 'application/vnd.mozilla.xul+xml; charset=utf-8', '->setContentType() adds a charset if none is given'); 109 107 110 108 $response->setContentType('image/jpg');

