Changeset 11254
- Timestamp:
- 08/30/08 14:20:19 (5 years ago)
- Files:
-
- branches/1.2/UPGRADE_TO_1_2 (modified) (3 diffs)
- branches/1.2/lib/action/sfAction.class.php (modified) (1 diff)
- branches/1.2/lib/plugins/sfCompat10Plugin/lib/filter/sfValidationExecutionFilter.class.php (modified) (1 diff)
- branches/1.2/lib/request/sfRequest.class.php (modified) (3 diffs)
- branches/1.2/lib/request/sfWebRequest.class.php (modified) (7 diffs)
- branches/1.2/test/unit/request/sfWebRequestTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/UPGRADE_TO_1_2
r11171 r11254 27 27 The remaining sections explain the main changes made in symfony 1.2. 28 28 29 Configuration 30 ------------- 31 32 ### Request 29 Request 30 ------- 33 31 34 32 The `path_info_array`, `path_info_key`, and `relative_url_root` settings have … … 42 40 instead of being passed as an attribute. 43 41 44 ### Response 42 The request method constants from `sfRequest` values have changed from integers 43 to strings and the `sfRequest::NONE` method has been removed: 44 45 **Constant** | **Old value** | **New value** 46 ------------ | ------------- | ------------- 47 GET | 2 | GET 48 POST | 4 | POST 49 PUT | 5 | PUT 50 DELETE | 6 | DELETE 51 HEAD | 7 | HEAD 52 NONE | 1 | - 53 54 The `getMethod()` and `getMethodName()` methods now returns the same value, 55 so `getMethodName()` is deprecated. 56 57 The `sfAction::getMethodNames()` and the corresponding code in 58 `sfValidationExecutionFilter` from `sfCompat10Plugin` have been removed. 59 This method was deprecated in 1.1 and was not really useable in 1.0. 60 61 You can now simulate `PUT` and `DELETE` requests from a browser by using the 62 `POST` method and adding a special `sf_method` parameter: 63 64 [php] 65 <form action="#" method="POST"> 66 <input type="hidden" name="sf_method" value="PUT" /> 67 68 <!-- // ... --> 69 </form> 70 71 Response 72 -------- 45 73 46 74 There is a new setting for the `response` factory: `send_http_headers`. … … 107 135 positions. In symfony 1.1, they take the position as a second argument. 108 136 109 ### Prototype and Scriptaculous 137 Prototype and Scriptaculous 138 --------------------------- 110 139 111 140 symfony continues to decouple its bundled software. In 1.2 the bundled Prototype and branches/1.2/lib/action/sfAction.class.php
r10834 r11254 360 360 361 361 /** 362 * Retrieves the request methods on which this action will process validation and execution.363 *364 * @return int One of the following values:365 *366 * - sfRequest::GET367 * - sfRequest::POST368 * - sfRequest::PUT369 * - sfRequest::DELETE370 * - sfRequest::HEAD371 * - sfRequest::NONE372 *373 * @see sfRequest374 */375 public function getRequestMethods()376 {377 if (!sfConfig::get('sf_compat_10'))378 {379 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');380 }381 382 return sfRequest::GET383 | sfRequest::POST384 | sfRequest::PUT385 | sfRequest::DELETE386 | sfRequest::HEAD387 | sfRequest::NONE;388 }389 390 /**391 362 * Executes any post-validation error application logic. 392 363 * branches/1.2/lib/plugins/sfCompat10Plugin/lib/filter/sfValidationExecutionFilter.class.php
r9947 r11254 83 83 } 84 84 85 // get the request method86 $method = $this->context->getRequest()->getMethod();87 if (($actionInstance->getRequestMethods() & $method) != $method)88 {89 // this action will skip validation/execution for this method90 // get the default view91 return $actionInstance->getDefaultView();92 }93 94 85 return $this->validateAction($filterChain, $actionInstance) ? $this->executeAction($actionInstance) : $this->handleErrorAction($actionInstance); 95 86 } branches/1.2/lib/request/sfRequest.class.php
r10627 r11254 23 23 abstract class sfRequest 24 24 { 25 /** 26 * Process validation and execution for only GET requests. 27 * 28 */ 29 const GET = 2; 30 31 /** 32 * Skip validation and execution for any request method. 33 * 34 */ 35 const NONE = 1; 36 37 /** 38 * Process validation and execution for only POST requests. 39 * 40 */ 41 const POST = 4; 42 43 /** 44 * Process validation and execution for only PUT requests. 45 * 46 */ 47 const PUT = 5; 48 49 /** 50 * Process validation and execution for only DELETE requests. 51 * 52 */ 53 const DELETE = 6; 54 55 /** 56 * Process validation and execution for only HEAD requests. 57 * 58 */ 59 const HEAD = 7; 25 const GET = 'GET'; 26 const POST = 'POST'; 27 const PUT = 'PUT'; 28 const DELETE = 'DELETE'; 29 const HEAD = 'HEAD'; 60 30 61 31 protected … … 132 102 133 103 /** 134 * Retrieves this request's method. 135 * 136 * @return int One of the following constants: 137 * - sfRequest::GET 138 * - sfRequest::POST 104 * Gets the request method. 105 * 106 * @return string The request method 139 107 */ 140 108 public function getMethod() … … 146 114 * Sets the request method. 147 115 * 148 * @param int $methodCode One of the following constants: 149 * 150 * - sfRequest::GET 151 * - sfRequest::POST 152 * - sfRequest::PUT 153 * - sfRequest::DELETE 154 * - sfRequest::HEAD 116 * @param string $method The request method 155 117 * 156 118 * @throws <b>sfException</b> - If the specified request method is invalid 157 119 */ 158 public function setMethod($methodCode) 159 { 160 $available_methods = array(self::GET, self::POST, self::PUT, self::DELETE, self::HEAD, self::NONE); 161 if (in_array($methodCode, $available_methods)) 162 { 163 $this->method = $methodCode; 164 165 return; 166 } 167 168 // invalid method type 169 throw new sfException(sprintf('Invalid request method: %s.', $methodCode)); 120 public function setMethod($method) 121 { 122 if (!in_array(strtoupper($method), array(self::GET, self::POST, self::PUT, self::DELETE, self::HEAD))) 123 { 124 throw new sfException(sprintf('Invalid request method: %s.', $method)); 125 } 126 127 $this->method = strtoupper($method); 170 128 } 171 129 branches/1.2/lib/request/sfWebRequest.class.php
r11217 r11254 50 50 parent::initialize($dispatcher, $parameters, $attributes, $options); 51 51 52 // GET parameters 53 $this->getParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_GET) : $_GET; 54 $this->parameterHolder->add($this->getParameters); 55 56 // POST parameters 57 $this->postParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_POST) : $_POST; 58 $this->parameterHolder->add($this->postParameters); 59 60 $this->fixParameters(); 61 52 62 if (isset($_SERVER['REQUEST_METHOD'])) 53 63 { … … 59 69 60 70 case 'POST': 61 $this->setMethod(s elf::POST);71 $this->setMethod(strtoupper($this->getParameter('sf_method', 'POST'))); 62 72 break; 63 73 … … 102 112 } 103 113 104 // load parameters from GET/PATH_INFO/POST 105 $this->loadParameters(); 114 // additional parameters 115 $this->requestParameters = $this->parseRequestParameters(); 116 $this->parameterHolder->add($this->requestParameters); 117 118 if ($this->options['logging']) 119 { 120 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))))); 121 } 106 122 } 107 123 … … 279 295 public function isMethod($method) 280 296 { 281 $pathArray = $this->getPathInfoArray(); 282 283 return strtolower($method) == strtolower($this->getMethodName()); 297 return strtoupper($method) == $this->getMethod(); 284 298 } 285 299 … … 291 305 public function getMethodName() 292 306 { 293 $pathArray = $this->getPathInfoArray(); 294 295 return isset($pathArray['REQUEST_METHOD']) ? $pathArray['REQUEST_METHOD'] : 'GET'; 307 if ($this->options['logging']) 308 { 309 $this->dispatcher->notify(new sfEvent($this, 'application.log', array('The "sfWebRequest::getMethodName()" method is deprecated, please use "getMethod()" instead.'))); 310 } 311 312 return $this->getMethod(); 296 313 } 297 314 … … 772 789 } 773 790 774 /** 775 * Loads GET, PATH_INFO and POST data into the parameter list. 776 * 777 */ 778 protected function loadParameters() 779 { 780 // GET parameters 781 $this->getParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_GET) : $_GET; 782 $this->parameterHolder->add($this->getParameters); 783 784 // POST parameters 785 $this->postParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_POST) : $_POST; 786 $this->parameterHolder->add($this->postParameters); 787 788 // additional parameters 789 $this->requestParameters = $this->parseRequestParameters(); 790 $this->parameterHolder->add($this->requestParameters); 791 791 protected function fixParameters() 792 { 792 793 // move symfony parameters to attributes (parameters prefixed with _sf_) 793 794 foreach ($this->parameterHolder->getAll() as $key => $value) … … 799 800 } 800 801 } 801 802 if ($this->options['logging'])803 {804 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true))))));805 }806 802 } 807 803 } branches/1.2/test/unit/request/sfWebRequestTest.php
r10060 r11254 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(3 4, new lime_output_color());13 $t = new lime_test(37, new lime_output_color()); 14 14 15 15 class myRequest extends sfWebRequest … … 143 143 $_SERVER['HTTP_X_FORWARDED_FOR'] = '10.0.0.1'; 144 144 $t->is($request->getForwardedRemoteAddress(), '10.0.0.1', '->getForwardedRemoteAddress() returns the value from HTTP_X_FORWARDED_FOR'); 145 146 // methods 147 $t->diag('methods'); 148 $_SERVER['REQUEST_METHOD'] = 'POST'; 149 $_POST['sf_method'] = 'PUT'; 150 $request = new myRequest($dispatcher); 151 $t->is($request->getMethod(), 'PUT', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST'); 152 153 $_SERVER['REQUEST_METHOD'] = 'GET'; 154 $_POST['sf_method'] = 'PUT'; 155 $request = new myRequest($dispatcher); 156 $t->is($request->getMethod(), 'GET', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST'); 157 158 $_SERVER['REQUEST_METHOD'] = 'POST'; 159 unset($_POST['sf_method']); 160 $request = new myRequest($dispatcher); 161 $t->is($request->getMethod(), 'POST', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST');