Alpha Framework alpha--util
[ class tree: alpha--util ] [ index: alpha--util ] [ all elements ]

Source for file AlphaErrorHandlers.inc

Documentation is available at AlphaErrorHandlers.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/util/Logger.inc';
  4. require_once $config->get('sysRoot').'alpha/exceptions/PHPException.inc';
  5.  
  6. /**
  7.  *
  8.  * A pair of static methods for capturing normal PHP errors and unhandled Alpha exceptions
  9.  * 
  10.  * @package alpha::util
  11.  * @since 1.0
  12.  * @author John Collins <dev@alphaframework.org>
  13.  * @version $Id: AlphaErrorHandlers.inc 1341 2011-03-17 15:02:02Z johnc $
  14.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  15.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  16.  *  All rights reserved.
  17.  * 
  18.  *  <pre>
  19.  *  Redistribution and use in source and binary forms, with or
  20.  *  without modification, are permitted provided that the
  21.  *  following conditions are met:
  22.  * 
  23.  *  * Redistributions of source code must retain the above
  24.  *    copyright notice, this list of conditions and the
  25.  *    following disclaimer.
  26.  *  * Redistributions in binary form must reproduce the above
  27.  *    copyright notice, this list of conditions and the
  28.  *    following disclaimer in the documentation and/or other
  29.  *    materials provided with the distribution.
  30.  *  * Neither the name of the Alpha Framework nor the names
  31.  *    of its contributors may be used to endorse or promote
  32.  *    products derived from this software without specific
  33.  *    prior written permission.
  34.  *   
  35.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  36.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  37.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  38.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  40.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  42.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  43.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  45.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  46.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  47.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48.  *  </pre>
  49.  *  
  50.  */
  51. abstract class AlphaErrorHandlers {
  52.     public static function catchException($e{
  53.         $logger new Logger(get_class($e));        
  54.         $logger->error($e->getMessage()."\n [stacktrace]: \n".$e->getTraceAsString());
  55.         header('HTTP/1.1 404 Not Found');
  56.         echo AlphaView::renderErrorPage(404'The file that you have requested cannot be found!');
  57.     }
  58.     
  59.     public static function catchError($error_no$msg$file$line{    
  60.         $e new PHPException();
  61.         $e->setMessage('[PHP error '.$error_no.'] on line ['.$line.']: '.$msg);
  62.         $e->setFile($file);
  63.          
  64.         throw $e;
  65.     }
  66. }
  67.  
  68. set_exception_handler('AlphaErrorHandlers::catchException');
  69. set_error_handler('AlphaErrorHandlers::catchError'$config->get('sysPHPErrorLogLevel'));
  70.  
  71.  
  72. ?>

Documentation generated on Thu, 17 Mar 2011 16:43:29 +0000 by phpDocumentor 1.4.3