Changeset 389

Show
Ignore:
Timestamp:
03/16/07 14:32:50 (1 year ago)
Author:
mikey
Message:

enhanced net.stubbles.util.stubExceptionHandler

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/stubbles/build.xml

    r329 r389  
    3333    <mkdir dir="${build.src.dir}/cache" /> 
    3434    <mkdir dir="${build.src.dir}/cache/xml" /> 
     35     
     36    <mkdir dir="${build.src.dir}/config/errors" /> 
     37    <copy file="${project.basedir}/../../config/errors/500.html" tofile="${build.src.dir}/config/errors/500-dist.html" /> 
    3538     
    3639    <mkdir dir="${build.src.dir}/config/php" /> 
  • trunk/src/main/php/net/stubbles/util/stubExceptionHandler.php

    r360 r389  
    1616 * @package     stubbles 
    1717 * @subpackage  util 
     18 * @Inject(stubRequest:stubResponse) 
    1819 */ 
    1920class stubExceptionHandler extends stubBaseObject implements stubPreInterceptor 
    2021{ 
     22    /** 
     23     * access to request instance 
     24     * 
     25     * @var  stubRequest 
     26     */ 
     27    protected static $request; 
     28    /** 
     29     * access to response instance 
     30     * 
     31     * @var  stubResponse 
     32     */ 
     33    protected static $response; 
     34     
    2135    /** 
    2236     * registers the exception handler 
     
    3448    public static function handle(Exception $exception) 
    3549    { 
     50        if (null != self::$request) { 
     51            self::$request->cancel(); 
     52        } 
     53         
     54        if (null == self::$response) { 
     55            self::$response = new stubBaseResponse(); 
     56        } 
     57         
    3658        if (stubRegistry::hasConfig('net.stubbles.mode') == true && stubRegistry::getConfig('net.stubbles.mode') == 'test') { 
    37             $response = new stubBaseResponse(); 
    3859            if ($exception instanceof stubException) { 
    39                 $response->write($exception); 
     60                self::$response->replaceData((string) $exception); 
    4061            } else { 
    41                 $response->write($exception->getMessage()); 
     62                self::$response->replaceData($exception->getMessage()); 
    4263            } 
    43             $response->send(); 
    4464        } else { 
    4565            header('HTTP/1.0 500 Internal Server Error'); 
     66            self::$response->replaceData(file_get_contents(stubConfig::getConfigPath() . '/errors/500.html')); 
    4667        } 
     68         
     69        // send the response because the request will end right after this  
     70        // method has been finished 
     71        self::$response->send(); 
     72    } 
     73     
     74    /** 
     75     * sets the request instance 
     76     * 
     77     * @param  stubRequest  $request 
     78     */ 
     79    public function setRequest(stubRequest $request) 
     80    { 
     81        self::$request = $request; 
     82    } 
     83     
     84    /** 
     85     * sets the response instance 
     86     * 
     87     * @param  stubResponse  $response 
     88     */ 
     89    public function setResponse(stubResponse $response) 
     90    { 
     91        self::$response = $response; 
    4792    } 
    4893