Development

Changeset 6975

You must first sign up to be able to contribute.

Changeset 6975

Show
Ignore:
Timestamp:
01/06/08 16:51:52 (11 months ago)
Author:
fabien
Message:

changed behavior to be sure to have a 404 exception in debug mode and 404 page in production mode (not easy to write tests for this one)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/controller/sfController.class.php

    r6770 r6975  
    205205      } 
    206206 
    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)); 
    220208    } 
    221209 
  • branches/1.1/lib/exception/sfError404Exception.class.php

    r6551 r6975  
    2424  public function printStackTrace() 
    2525  { 
    26     // log all exceptions in php log 
    2726    $exception = is_null($this->wrappedException) ? $this : $this->wrappedException; 
    28     error_log($exception->getMessage()); 
    2927 
    3028    if (sfConfig::get('sf_debug')) 
    3129    { 
    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); 
    3338 
    3439      return parent::printStackTrace(); 
  • branches/1.1/lib/request/sfWebRequest.class.php

    r6769 r6975  
    899899  } 
    900900 
     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   */ 
    901908  protected function parseRequestParameters() 
    902909  { 
    903910    $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(); 
    914912 
    915913    if (!isset($parameters['module'])) 
     
    923921    } 
    924922 
    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; 
    926929  } 
    927930 
     
    937940 
    938941    // additional parameters 
    939     $this->parseRequestParameters(); 
     942    $this->requestParameters = $this->parseRequestParameters(); 
    940943    $this->parameterHolder->add($this->requestParameters); 
    941944 
  • branches/1.1/lib/util/sfContext.class.php

    r6770 r6975  
    4848    $this->factories['actionStack'] = new sfActionStack(); 
    4949 
    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    } 
    5263 
    5364    if (sfConfig::get('sf_logging_enabled')) 
    5465    { 
    55       $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Initilization'))); 
     66      $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Initialization'))); 
    5667    } 
    5768 
     
    164175   public function getController() 
    165176   { 
    166      return $this->factories['controller']
     177     return isset($this->factories['controller']) ? $this->factories['controller'] : null
    167178   } 
    168179 
     
    215226  public function getDatabaseManager() 
    216227  { 
    217     return $this->factories['databaseManager']
     228    return isset($this->factories['databaseManager']) ? $this->factories['databaseManager'] : null
    218229  } 
    219230 
     
    255266  public function getRequest() 
    256267  { 
    257     return $this->factories['request']
     268    return isset($this->factories['request']) ? $this->factories['request'] : null
    258269  } 
    259270 
     
    265276  public function getResponse() 
    266277  { 
    267     return $this->factories['response']
     278    return isset($this->factories['response']) ? $this->factories['response'] : null
    268279  } 
    269280 
     
    287298  public function getStorage() 
    288299  { 
    289     return $this->factories['storage']
     300    return isset($this->factories['storage']) ? $this->factories['storage'] : null
    290301  } 
    291302 
     
    297308  public function getViewCacheManager() 
    298309  { 
    299     return $this->factories['viewCacheManager']
     310    return isset($this->factories['viewCacheManager']) ? $this->factories['viewCacheManager'] : null
    300311  } 
    301312 
     
    322333  public function getRouting() 
    323334  { 
    324     return $this->factories['routing']
     335    return isset($this->factories['routing']) ? $this->factories['routing'] : null
    325336  } 
    326337 
     
    332343  public function getUser() 
    333344  { 
    334     return $this->factories['user']
     345    return isset($this->factories['user']) ? $this->factories['user'] : null
    335346  } 
    336347 
  • branches/1.1/test/functional/genericTest.php

    r6888 r6975  
    3131  get('/nonexistant')-> 
    3232  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.') 
    3634; 
    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*/ 
    3842// 404 with ETag enabled must returns 404, not 304 
    3943sfConfig::set('sf_cache', true); 
     
    5963  get('/default/nonexistantaction')-> 
    6064  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.') 
    6366; 
    6467 
  • branches/1.1/test/functional/prodTest.php

    r6482 r6975  
    3838  checkResponseElement('body', '/congratulations/i') 
    3939; 
     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;