Development

Changeset 6522

You must first sign up to be able to contribute.

Changeset 6522

Show
Ignore:
Timestamp:
12/16/07 13:23:03 (10 months ago)
Author:
fabien
Message:

changed sfFrontWebController::dispatch() to always return a sfWebResponse instance

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/action/sfAction.class.php

    r6516 r6522  
    131131 
    132132    $this->getController()->forward($module, $action); 
    133     $this->getResponse()->send(); 
    134133 
    135134    throw new sfStopException(); 
     
    191190  { 
    192191    $this->getController()->redirect($url, 0, $statusCode); 
    193     $this->getResponse()->send(); 
    194192 
    195193    throw new sfStopException(); 
  • trunk/lib/controller/sfConsoleController.class.php

    r5139 r6522  
    3636    catch (sfException $e) 
    3737    { 
    38       $e->printStackTrace(); 
     38      echo $e->getStackTrace(); 
    3939    } 
    4040    catch (Exception $e) 
    4141    { 
    42       sfException::createFromException($e)->printStackTrace(); 
     42      echo sfException::createFromException($e)->getStackTrace(); 
    4343    } 
    4444  } 
  • trunk/lib/controller/sfFrontWebController.class.php

    r6514 r6522  
    4747      // make the first request 
    4848      $this->forward($moduleName, $actionName); 
    49  
    50       $this->context->getResponse()->send(); 
    5149    } 
    5250    catch (sfException $e) 
    5351    { 
    54       $e->printStackTrace(); 
     52      $this->context->setResponse($e->asResponse()); 
    5553    } 
    5654    catch (Exception $e) 
    5755    { 
    58       sfException::createFromException($e)->printStackTrace(); 
     56      $this->context->setResponse(sfException::createFromException($e)->asResponse()); 
    5957    } 
     58 
     59    $this->context->getResponse()->send(); 
    6060  } 
    6161} 
  • trunk/lib/exception/sfError404Exception.class.php

    r6519 r6522  
    2020{ 
    2121  /** 
    22    * Forwards to the 404 action. 
     22   * @see sfException 
    2323   */ 
    24   public function printStackTrace() 
     24  public function asResponse() 
    2525  { 
    26     // log all exceptions in php log 
    27     $exception = is_null($this->wrappedException) ? $this : $this->wrappedException; 
    28     error_log($exception->getMessage()); 
    29  
    3026    if (sfConfig::get('sf_debug')) 
    3127    { 
    32       sfContext::getInstance()->getResponse()->setStatusCode(404); 
    33  
    34       return parent::printStackTrace(); 
     28      $response = parent::asResponse(); 
     29      $response->setStatusCode(404); 
    3530    } 
    3631    else 
    3732    { 
     33      // log all exceptions in php log 
     34      if (!sfConfig::get('sf_test')) 
     35      { 
     36        error_log($this->getMessage()); 
     37      } 
     38 
    3839      $context = sfContext::getInstance(); 
     40      $context->getController()->forward(sfConfig::get('sf_error_404_module'), sfConfig::get('sf_error_404_action')); 
     41      $response = $context->getResponse(); 
     42    } 
    3943 
    40       $context->getController()->forward(sfConfig::get('sf_error_404_module'), sfConfig::get('sf_error_404_action')); 
    41       $context->getResponse()->send(); 
    42     } 
     44    return $response; 
    4345  } 
    4446} 
  • trunk/lib/exception/sfException.class.php

    r6519 r6522  
    4141  } 
    4242 
     43  /** 
     44   * Changes the wrapped exception. 
     45   * 
     46   * @param Exception An Exception instance 
     47   */ 
    4348  public function setWrappedException($e) 
    4449  { 
     
    4752 
    4853  /** 
    49    * Prints the stack trace for this exception. 
    50    */ 
    51   public function printStackTrace() 
     54   * Returns the exception as a sfWebResponse object. 
     55   * 
     56   * @param sfWebResponse A sfWebResponse instance 
     57   */ 
     58  public function asResponse() 
    5259  { 
    5360    $exception = is_null($this->wrappedException) ? $this : $this->wrappedException; 
    54  
    55     // log all exceptions in php log 
    56     error_log($exception->getMessage()); 
    5761 
    5862    if (!sfConfig::get('sf_test')) 
     
    6165      while (@ob_end_clean()); 
    6266 
    63       header('HTTP/1.0 500 Internal Server Error'); 
    64     } 
     67      // log all exceptions in php log 
     68      error_log($exception->getMessage()); 
     69    } 
     70 
     71    $response = new sfWebResponse(sfContext::getInstance()->getEventDispatcher()); 
     72    $response->setStatusCode(500); 
    6573 
    6674    try 
    6775    { 
    68       $this->outputStackTrace($exception); 
     76      $content = self::getStackTrace($exception); 
    6977    } 
    7078    catch (Exception $e) 
    7179    { 
    72     } 
    73  
    74     if (!sfConfig::get('sf_test')) 
    75     { 
    76       exit(1); 
    77     } 
     80      $content = $e->getMessage(); 
     81    } 
     82 
     83    $response->setContent($content); 
     84 
     85    return $response; 
    7886  } 
    7987 
     
    8189   * Gets the stack trace for this exception. 
    8290   */ 
    83   static protected function outputStackTrace($exception) 
     91  static protected function getStackTrace($exception) 
    8492  { 
    8593    if (class_exists('sfContext', false) && sfContext::hasInstance()) 
     
    95103      if ($event->isProcessed()) 
    96104      { 
    97         return
     105        return $event->getReturnValue()
    98106      } 
    99107    } 
     
    104112      $file = sfConfig::get('sf_web_dir').'/errors/error500.php'; 
    105113 
     114      ob_start(); 
    106115      include is_readable($file) ? $file : sfConfig::get('sf_symfony_data_dir').'/web/errors/error500.php'; 
    107116 
    108       return
     117      return ob_get_clean()
    109118    } 
    110119 
     
    126135    } 
    127136 
     137    ob_start(); 
    128138    include sfConfig::get('sf_symfony_data_dir').'/data/exception.'.($format == 'html' ? 'php' : 'txt'); 
     139 
     140    return ob_get_clean(); 
    129141  } 
    130142 
  • trunk/lib/exception/sfStopException.class.php

    r6519 r6522  
    2020{ 
    2121  /** 
    22    * Stops the current action. 
     22   * @see sfException 
    2323   */ 
    24   public function printStackTrace() 
     24  public function asResponse() 
    2525  { 
    26     // log all exceptions in php log 
    27     $exception = is_null($this->wrappedException) ? $this : $this->wrappedException; 
    28     error_log($exception->getMessage()); 
     26    return sfContext::getInstance()->getResponse(); 
    2927  } 
    3028} 
  • trunk/lib/filter/sfBasicSecurityFilter.class.php

    r6514 r6522  
    7272        // the user doesn't have access, exit stage left 
    7373        $controller->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action')); 
    74         $this->context->getResponse()->send(); 
    7574 
    7675        throw new sfStopException(); 
     
    8180      // the user is not authenticated 
    8281      $controller->forward(sfConfig::get('sf_login_module'), sfConfig::get('sf_login_action')); 
    83       $this->context->getResponse()->send(); 
    8482 
    8583      throw new sfStopException(); 
  • trunk/lib/plugins/sfPropelPlugin/test/functional/browseTest.php

    r6482 r6522  
    2121$b-> 
    2222  get('/error')-> 
    23   isStatusCode(200)-> 
     23  isStatusCode(500)-> 
    2424  isRequestParameter('module', 'error')-> 
    2525  isRequestParameter('action', 'index')-> 
  • trunk/lib/util/sfCore.class.php

    r5402 r6522  
    4242    catch (sfException $e) 
    4343    { 
    44       $e->printStackTrace(); 
     44      echo $e->getStackTrace(); 
    4545    } 
    4646    catch (Exception $e) 
    4747    { 
    48       sfException::createFromException($e)->printStackTrace(); 
     48      echo sfException::createFromException($e)->getStackTrace(); 
    4949    } 
    5050  } 
  • trunk/test/functional/genericTest.php

    r6482 r6522  
    110110$b-> 
    111111  get('/configSettingsMaxForwards/selfForward')-> 
    112   isStatusCode(200)-> 
     112  isStatusCode(500)-> 
    113113  checkResponseElement('body', '/Too many forwards have been detected for this request/i') 
    114114; 
  • trunk/test/functional/sfTestBrowserTest.php

    r6482 r6522  
    2626 
    2727  get('/exception/throwsException')-> 
    28   isStatusCode(200)-> 
     28  isStatusCode(500)-> 
    2929  isRequestParameter('module', 'exception')-> 
    3030  isRequestParameter('action', 'throwsException')-> 
     
    3535 
    3636  get('/exception/throwsSfException')-> 
    37   isStatusCode(200)-> 
     37  isStatusCode(500)-> 
    3838  isRequestParameter('module', 'exception')-> 
    3939  isRequestParameter('action', 'throwsSfException')->