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

Documentation generated on Tue, 13 Dec 2011 20:26:02 +0000 by phpDocumentor 1.4.3