Changeset 6975
- Timestamp:
- 01/06/08 16:51:52 (1 year ago)
- Files:
-
- branches/1.1/lib/controller/sfController.class.php (modified) (1 diff)
- branches/1.1/lib/exception/sfError404Exception.class.php (modified) (1 diff)
- branches/1.1/lib/request/sfWebRequest.class.php (modified) (3 diffs)
- branches/1.1/lib/util/sfContext.class.php (modified) (9 diffs)
- branches/1.1/test/functional/genericTest.php (modified) (2 diffs)
- branches/1.1/test/functional/prodTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/controller/sfController.class.php
r6770 r6975 205 205 } 206 206 207 // track the requested module so we have access to the data in the error 404 page 208 $this->context->getRequest()->setAttribute('requested_action', $actionName); 209 $this->context->getRequest()->setAttribute('requested_module', $moduleName); 210 211 // switch to error 404 action 212 $moduleName = sfConfig::get('sf_error_404_module'); 213 $actionName = sfConfig::get('sf_error_404_action'); 214 215 if (!$this->actionExists($moduleName, $actionName)) 216 { 217 // cannot find unavailable module/action 218 throw new sfConfigurationException(sprintf('Invalid configuration settings: [sf_error_404_module] "%s", [sf_error_404_action] "%s".', $moduleName, $actionName)); 219 } 207 throw new sfError404Exception(sprintf('Action "%s/%s" does not exist.', $moduleName, $actionName)); 220 208 } 221 209 branches/1.1/lib/exception/sfError404Exception.class.php
r6551 r6975 24 24 public function printStackTrace() 25 25 { 26 // log all exceptions in php log27 26 $exception = is_null($this->wrappedException) ? $this : $this->wrappedException; 28 error_log($exception->getMessage());29 27 30 28 if (sfConfig::get('sf_debug')) 31 29 { 32 sfContext::getInstance()->getResponse()->setStatusCode(404); 30 $response = sfContext::getInstance()->getResponse(); 31 if (is_null($response)) 32 { 33 $response = new sfWebResponse(sfContext::getInstance()->getEventDispatcher()); 34 sfContext::getInstance()->setResponse($response); 35 } 36 37 $response->setStatusCode(404); 33 38 34 39 return parent::printStackTrace(); branches/1.1/lib/request/sfWebRequest.class.php
r6769 r6975 899 899 } 900 900 901 /** 902 * Parses the request parameters. 903 * 904 * This method notifies the request.filter_parameters event. 905 * 906 * @return array An array of request parameters. 907 */ 901 908 protected function parseRequestParameters() 902 909 { 903 910 $parameters = array(); 904 905 try 906 { 907 $parameters = $this->dispatcher->filter(new sfEvent($this, 'request.filter_parameters', array('path_info' => $this->getPathInfo())), $parameters)->getReturnValue(); 908 } 909 catch (sfError404Exception $e) 910 { 911 $parameters['module'] = sfConfig::get('sf_error_404_module', 'default'); 912 $parameters['action'] = sfConfig::get('sf_error_404_action', 'error404'); 913 } 911 $parameters = $this->dispatcher->filter(new sfEvent($this, 'request.filter_parameters', array('path_info' => $this->getPathInfo())), $parameters)->getReturnValue(); 914 912 915 913 if (!isset($parameters['module'])) … … 923 921 } 924 922 925 $this->requestParameters = $parameters; 923 if (empty($parameters['module']) || empty($parameters['action'])) 924 { 925 throw new sfError404Exception(sprintf('Empty module and/or action after parsing the URL "%s" (%s/%s).', $this->getPathInfo(), $parameters['module'], $parameters['action'])); 926 } 927 928 return $parameters; 926 929 } 927 930 … … 937 940 938 941 // additional parameters 939 $this-> parseRequestParameters();942 $this->requestParameters = $this->parseRequestParameters(); 940 943 $this->parameterHolder->add($this->requestParameters); 941 944 branches/1.1/lib/util/sfContext.class.php
r6770 r6975 48 48 $this->factories['actionStack'] = new sfActionStack(); 49 49 50 // include the factories configuration 51 require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name').'/factories.yml')); 50 try 51 { 52 // include the factories configuration 53 require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name').'/factories.yml')); 54 } 55 catch (sfException $e) 56 { 57 $e->printStackTrace(); 58 } 59 catch (Exception $e) 60 { 61 sfException::createFromException($e)->printStackTrace(); 62 } 52 63 53 64 if (sfConfig::get('sf_logging_enabled')) 54 65 { 55 $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Initi lization')));66 $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Initialization'))); 56 67 } 57 68 … … 164 175 public function getController() 165 176 { 166 return $this->factories['controller'];177 return isset($this->factories['controller']) ? $this->factories['controller'] : null; 167 178 } 168 179 … … 215 226 public function getDatabaseManager() 216 227 { 217 return $this->factories['databaseManager'];228 return isset($this->factories['databaseManager']) ? $this->factories['databaseManager'] : null; 218 229 } 219 230 … … 255 266 public function getRequest() 256 267 { 257 return $this->factories['request'];268 return isset($this->factories['request']) ? $this->factories['request'] : null; 258 269 } 259 270 … … 265 276 public function getResponse() 266 277 { 267 return $this->factories['response'];278 return isset($this->factories['response']) ? $this->factories['response'] : null; 268 279 } 269 280 … … 287 298 public function getStorage() 288 299 { 289 return $this->factories['storage'];300 return isset($this->factories['storage']) ? $this->factories['storage'] : null; 290 301 } 291 302 … … 297 308 public function getViewCacheManager() 298 309 { 299 return $this->factories['viewCacheManager'];310 return isset($this->factories['viewCacheManager']) ? $this->factories['viewCacheManager'] : null; 300 311 } 301 312 … … 322 333 public function getRouting() 323 334 { 324 return $this->factories['routing'];335 return isset($this->factories['routing']) ? $this->factories['routing'] : null; 325 336 } 326 337 … … 332 343 public function getUser() 333 344 { 334 return $this->factories['user'];345 return isset($this->factories['user']) ? $this->factories['user'] : null; 335 346 } 336 347 branches/1.1/test/functional/genericTest.php
r6888 r6975 31 31 get('/nonexistant')-> 32 32 isStatusCode(404)-> 33 isForwardedTo('default', 'error404')-> 34 checkResponseElement('body', '!/congratulations/i')-> 35 checkResponseElement('link[href="/sf/sf_default/css/screen.css"]') 33 throwsException('sfError404Exception', 'Action "nonexistant/index" does not exist.') 36 34 ; 37 35 /* 36 $b-> 37 get('/nonexistant/')-> 38 isStatusCode(404)-> 39 throwsException('sfError404Exception', 'Empty module and/or action after parsing the URL "/nonexistant/" (nonexistant/).') 40 ; 41 */ 38 42 // 404 with ETag enabled must returns 404, not 304 39 43 sfConfig::set('sf_cache', true); … … 59 63 get('/default/nonexistantaction')-> 60 64 isStatusCode(404)-> 61 isForwardedTo('default', 'error404')-> 62 checkResponseElement('link[href="/sf/sf_default/css/screen.css"]') 65 throwsException('sfError404Exception', 'Action "default/nonexistantaction" does not exist.') 63 66 ; 64 67 branches/1.1/test/functional/prodTest.php
r6482 r6975 38 38 checkResponseElement('body', '/congratulations/i') 39 39 ; 40 41 // 404 42 $b-> 43 get('/nonexistant')-> 44 isStatusCode(404)-> 45 isForwardedTo('default', 'error404')-> 46 checkResponseElement('body', '!/congratulations/i')-> 47 checkResponseElement('link[href="/sf/sf_default/css/screen.css"]') 48 ; 49 50 $b-> 51 get('/nonexistant/')-> 52 isStatusCode(404)-> 53 isForwardedTo('default', 'error404')-> 54 checkResponseElement('body', '!/congratulations/i')-> 55 checkResponseElement('link[href="/sf/sf_default/css/screen.css"]') 56 ; 57 58 // unexistant action 59 $b-> 60 get('/default/nonexistantaction')-> 61 isStatusCode(404)-> 62 isForwardedTo('default', 'error404')-> 63 checkResponseElement('body', '!/congratulations/i')-> 64 checkResponseElement('link[href="/sf/sf_default/css/screen.css"]') 65 ;

