Changeset 1094
- Timestamp:
- 11/30/07 00:12:08 (9 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/lang/stubMode.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/lang/stubMode.php
r1089 r1094 15 15 * or not. Currently, there are four different modes available: 16 16 * stubMode::$PROD 17 * - uses exception handler net::stubbles:: util::errorhandler::stubProdModeExceptionHandler18 * - uses default error handler net.stubbles. util.errorhandler.stubDefaultErrorHandler17 * - uses exception handler net::stubbles::lang::errorhandler::stubProdModeExceptionHandler 18 * - uses default error handler net.stubbles.lang.errorhandler.stubDefaultErrorHandler 19 19 * - caching enabled 20 20 * stubMode::$TEST 21 * - uses exception handler net::stubbles:: util::errorhandler::stubDisplayExceptionHandler21 * - uses exception handler net::stubbles::lang::errorhandler::stubDisplayExceptionHandler 22 22 * - no error handler 23 23 * - caching enabled 24 24 * stubMode::$STAGE 25 * - uses exception handler net::stubbles:: util::errorhandler::stubDisplayExceptionHandler25 * - uses exception handler net::stubbles::lang::errorhandler::stubDisplayExceptionHandler 26 26 * - no error handler 27 27 * - caching disabled 28 28 * stubMode::$DEV 29 * - uses exception handler net::stubbles:: util::errorhandler::stubDisplayExceptionHandler29 * - uses exception handler net::stubbles::lang::errorhandler::stubDisplayExceptionHandler 30 30 * - no error handler 31 31 * - caching disabled … … 47 47 { 48 48 /** 49 * handler method must be called statically 50 */ 51 const HANDLER_STATIC = 'static'; 52 /** 53 * handler has to be an instance 54 */ 55 const HANDLER_INSTANCE = 'instance'; 56 /** 49 57 * mode: production 50 58 * … … 94 102 public static function __static() 95 103 { 104 // production mode 96 105 self::$PROD = new self('PROD', 0); 97 self::$PROD->exceptionHandler = array('class' => 'net.stubbles.util.errorhandler.stubProdModeExceptionHandler', 98 'method' => 'handle' 99 ); 100 self::$PROD->errorHandler = array('class' => 'net.stubbles.util.errorhandler.stubDefaultErrorHandler', 101 'method' => 'handle' 102 ); 106 self::$PROD->exceptionHandler = array('class' => 'net.stubbles.lang.errorhandler.stubProdModeExceptionHandler', 107 'method' => 'handle', 108 'type' => self::HANDLER_INSTANCE 109 ); 110 self::$PROD->errorHandler = array('class' => 'net.stubbles.lang.errorhandler.stubDefaultErrorHandler', 111 'method' => 'handle', 112 'type' => self::HANDLER_INSTANCE 113 ); 114 115 // test mode 103 116 self::$TEST = new self('TEST', 1); 104 self::$TEST->exceptionHandler = array('class' => 'net.stubbles.util.errorhandler.stubDisplayExceptionHandler', 105 'method' => 'handle' 106 ); 117 self::$TEST->exceptionHandler = array('class' => 'net.stubbles.lang.errorhandler.stubDisplayExceptionHandler', 118 'method' => 'handle', 119 'type' => self::HANDLER_INSTANCE 120 ); 121 122 // stage mode 107 123 self::$STAGE = new self('STAGE', 2); 108 self::$STAGE->exceptionHandler = array('class' => 'net.stubbles.util.errorhandler.stubDisplayExceptionHandler', 109 'method' => 'handle' 124 self::$STAGE->exceptionHandler = array('class' => 'net.stubbles.lang.errorhandler.stubDisplayExceptionHandler', 125 'method' => 'handle', 126 'type' => self::HANDLER_INSTANCE 110 127 ); 111 128 self::$STAGE->enableCache = false; 129 130 // development mode 112 131 self::$DEV = new self('STAGE', 3); 113 self::$DEV->exceptionHandler = array('class' => 'net.stubbles.util.errorhandler.stubDisplayExceptionHandler', 114 'method' => 'handle' 132 self::$DEV->exceptionHandler = array('class' => 'net.stubbles.lang.errorhandler.stubDisplayExceptionHandler', 133 'method' => 'handle', 134 'type' => self::HANDLER_INSTANCE 115 135 ); 116 136 self::$DEV->enableCache = false; … … 122 142 * To register the new exception handler call registerExceptionHandler(). 123 143 * 124 * @param string $fqClassName 125 * @param string $methodName 126 */ 127 public function setExceptionHandler($fqClassName, $methodName) 128 { 129 $this->exceptionHandler = array('class' => $fqClassName, 130 'method' => $methodName 144 * @param string|object $class name or instance of exception handler class 145 * @param string $methodName name of exception handler method 146 * @param string $type optional whether method has to be called statically or via an instance 147 */ 148 public function setExceptionHandler($class, $methodName, $type = self::HANDLER_INSTANCE) 149 { 150 $this->exceptionHandler = array('class' => $class, 151 'method' => $methodName, 152 'type' => $type 131 153 ); 132 154 } … … 143 165 } 144 166 145 if (class_exists($this->exceptionHandler['class'], false) === false) { 146 stubClassLoader::load($this->exceptionHandler['class']); 147 } 148 149 set_exception_handler(array(stubClassLoader::getNonQualifiedClassName($this->exceptionHandler['class']), $this->exceptionHandler['method'])); 167 set_exception_handler($this->getCallback($this->exceptionHandler)); 150 168 return true; 151 169 } … … 156 174 * To register the new error handler call registerErrorHandler(). 157 175 * 158 * @param string $fqClassName 159 * @param string $methodName 160 */ 161 public function setErrorHandler($fqClassName, $methodName) 162 { 163 $this->errorHandler = array('class' => $fqClassName, 164 'method' => $methodName 176 * @param string|object $class name or instance of error handler class 177 * @param string $methodName name of error handler method 178 * @param string $type optional whether method has to be called statically or via an instance 179 */ 180 public function setErrorHandler($class, $methodName, $type = self::HANDLER_INSTANCE) 181 { 182 $this->errorHandler = array('class' => $class, 183 'method' => $methodName, 184 'type' => $type 165 185 ); 166 186 } … … 176 196 return false; 177 197 } 178 179 if (class_exists($this->errorHandler['class'], false) === false) { 180 stubClassLoader::load($this->errorHandler['class']); 181 } 182 183 set_error_handler(array(stubClassLoader::getNonQualifiedClassName($this->errorHandler['class']), $this->errorHandler['method'])); 198 199 set_error_handler($this->getCallback($this->errorHandler)); 184 200 return true; 185 201 } … … 193 209 { 194 210 return $this->cacheEnabled; 211 } 212 213 /** 214 * helper method to create the callback from the handler data 215 * 216 * @param array $handler handler data 217 * @return callback 218 */ 219 protected function getCallback(array &$handler) 220 { 221 if (is_string($handler['class']) === true && class_exists($handler['class'], false) === false) { 222 stubClassLoader::load($handler['class']); 223 } 224 225 if (self::HANDLER_INSTANCE === $handler['type']) { 226 if (is_string($handler['class']) === true) { 227 $instance = stubClassLoader::getNonQualifiedClassName($handler['class']); 228 } else { 229 $instance = $handler['class']; 230 } 231 232 return array($instance, $handler['method']); 233 } 234 235 return array(stubClassLoader::getNonQualifiedClassName($handler['class']), $handler['method']); 195 236 } 196 237 }
