Exemplo n.º 1
0
 /**
  * Enables the debug tools.
  *
  * This method registers an error handler and an exception handler.
  *
  * If the Symfony ClassLoader component is available, a special
  * class loader is also registered.
  *
  * @param int  $errorReportingLevel The level of error reporting you want
  * @param bool $displayErrors       Whether to display errors (for development) or just log them (for production)
  */
 public static function enable($errorReportingLevel = E_ALL, $displayErrors = true)
 {
     if (static::$enabled) {
         return;
     }
     static::$enabled = true;
     if (null !== $errorReportingLevel) {
         error_reporting($errorReportingLevel);
     } else {
         error_reporting(E_ALL);
     }
     if ('cli' !== PHP_SAPI) {
         ini_set('display_errors', 0);
         ExceptionHandler::register();
     } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
         // CLI - display errors only if they're not already logged to STDERR
         ini_set('display_errors', 1);
     }
     if ($displayErrors) {
         ErrorHandler::register(new ErrorHandler(new BufferingLogger()));
     } else {
         ErrorHandler::register()->throwAt(0, true);
     }
     DebugClassLoader::enable();
 }
Exemplo n.º 2
0
 /**
  * activate custom debugging
  * registers error handler and exception handler
  * 
  * @param integer $reportingLevel
  * @param boolean $displayErrors
  */
 public static function enable($reportingLevel = NULL, $displayErrors = NULL)
 {
     if (!static::$enabled) {
         static::$enabled = true;
         error_reporting(E_ALL);
         ErrorHandler::register($reportingLevel, $displayErrors);
         if (PHP_SAPI !== 'cli') {
             ExceptionHandler::register($reportingLevel, $displayErrors);
         } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
             ini_set('display_errors', 1);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Enables the debug tools.
  *
  * This method registers an error handler and an exception handler.
  *
  * If the Symfony ClassLoader component is available, a special
  * class loader is also registered.
  *
  * @param int     $errorReportingLevel The level of error reporting you want
  * @param bool    $displayErrors       Whether to display errors (for development) or just log them (for production)
  */
 public static function enable($errorReportingLevel = null, $displayErrors = true)
 {
     if (static::$enabled) {
         return;
     }
     static::$enabled = true;
     error_reporting(-1);
     ErrorHandler::register($errorReportingLevel, $displayErrors);
     if ('cli' !== php_sapi_name()) {
         ExceptionHandler::register();
         // CLI - display errors only if they're not already logged to STDERR
     } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
         ini_set('display_errors', 1);
     }
     DebugClassLoader::enable();
 }
Exemplo n.º 4
0
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @license    MIT
 *
 * @author     Andy Young <*****@*****.**>
 * @author     Dave Ingram <*****@*****.**> (GroupSpaces)
 * @author     Gabor Vizi <*****@*****.**> (GroupSpaces)
 */
ErrorHandler::register();
/**
 * Handles custom error and exception handling
 *
 */
class ErrorHandler
{
    // stack of error reporting level integer constants
    protected static $_errorReportingLevelStack = array();
    // stack of extra data to log if an error occurs
    protected static $extraData = array();
    // store pointers to previous error/exception handlers, where present
    protected static $prevErrorHandler = array();
    protected static $prevExceptionHandler = array();
    protected static $customHandlerCount = 0;
    // sensitive data what we will change to *s
Exemplo n.º 5
0
 /**
  * Initialize the application.
  */
 private function init()
 {
     $errorHandler = new ErrorHandler();
     $errorHandler->register();
     static::$DI = $DI = DI::instance();
     $DI['Request'] = $request = new Http\Request();
     $DI['Config'] = $config = new Config($this->sitePath, dirname($_SERVER['SCRIPT_FILENAME']), $request->getBaseUrl());
     $DI['Alias'] = new Alias(['@app' => $config->get('app.path'), '@asset' => $this->sitePath . '/assets', '@media' => $config->get('media.path'), '@page' => $config->get('pages.path'), '@plugin' => $config->get('plugins.path'), '@post' => $config->get('posts.path'), '@site' => $this->sitePath, '@vendor' => $this->vendorDir, '@web' => $config->get('web.path')]);
     $DI['Assets'] = function ($DI) {
         return new Assets($DI['Alias'], $DI['Config']->get('web.url'));
     };
     $DI['Cache\\PageCache'] = function ($DI) {
         return Cache\CacheFactory::create('page', $DI['Config']);
     };
     $DI['Cache\\DataCache'] = function ($DI) {
         return Cache\CacheFactory::create('data', $DI['Config']);
     };
     $DI['DataArray'] = function ($DI) {
         $loader = new Loader\DataLoader($DI['Config']->get('data.extensions'));
         return $loader->load($DI['Config']->get('data.path'));
     };
     $DI['Loader\\PageLoader'] = function ($DI) {
         $loader = new Loader\PageLoader($DI['Alias']);
         return $loader;
     };
     $DI['Menu\\Page\\Builder'] = function ($DI) {
         $paths = [];
         $paths['@page'] = realpath($DI['Config']->get('pages.path'));
         foreach ($DI['Config']->get('pages.extra_paths', []) as $alias) {
             $paths[$alias] = $DI['Alias']->get($alias);
         }
         $extensions = $DI['Config']->get('pages.extensions', []);
         $builder = new Menu\Page\Builder($paths, $extensions);
         return $builder;
     };
     $DI['PluginManager'] = function ($DI) {
         $enabled = $DI['Config']->get('plugins.enable', []);
         $path = $DI['Config']->get('plugins.path');
         $enabledSysPlugins = $DI['Config']->get('sysplugins.enable');
         return new PluginManager($enabled, $path, $enabledSysPlugins);
     };
     $DI['Url\\UrlGenerator'] = function ($DI) {
         return new Url\UrlGenerator($DI['Request'], $DI['Config']->get('nice_urls', false));
     };
     setlocale(LC_ALL, $DI['Config']->get('locale'));
     // Add custom PSR-4 plugin path to Composer autoloader
     $autoload = (require $this->vendorDir . '/autoload.php');
     $autoload->addPsr4('herbie\\sysplugin\\', __DIR__ . '/../plugins/');
     $autoload->addPsr4('herbie\\plugin\\', $DI['Config']->get('plugins.path'));
     // Init PluginManager at first
     if (true === $DI['PluginManager']->init($DI['Config'])) {
         Hook::trigger(Hook::ACTION, 'pluginsInitialized', $DI['PluginManager']);
         Hook::trigger(Hook::ACTION, 'shortcodeInitialized', $DI['Shortcode']);
         $DI['Menu\\Page\\Collection'] = function ($DI) {
             $DI['Menu\\Page\\Builder']->setCache($DI['Cache\\DataCache']);
             return $DI['Menu\\Page\\Builder']->buildCollection();
         };
         $DI['Menu\\Page\\Node'] = function ($DI) {
             return Menu\Page\Node::buildTree($DI['Menu\\Page\\Collection']);
         };
         $DI['Menu\\Page\\RootPath'] = function ($DI) {
             $rootPath = new Menu\Page\RootPath($DI['Menu\\Page\\Collection'], $DI['Request']->getRoute());
             return $rootPath;
         };
         $DI['Menu\\Post\\Collection'] = function ($DI) {
             $builder = new Menu\Post\Builder($DI['Cache\\DataCache'], $DI['Config']);
             return $builder->build();
         };
         $DI['Page'] = function ($DI) {
             try {
                 $route = $DI['Request']->getRoute();
                 $page = false;
                 if (false === $page) {
                     $menuItem = $DI['Url\\UrlMatcher']->match($route);
                     $path = $menuItem->getPath();
                     $page = new Page();
                     $page->setLoader($DI['Loader\\PageLoader']);
                     $page->load($path);
                     Hook::trigger(Hook::ACTION, 'pageLoaded', $page);
                 }
             } catch (\Exception $e) {
                 $page = new Page();
                 $page->layout = 'error.html';
                 $page->setError($e);
             }
             return $page;
         };
         $DI['Translator'] = function ($DI) {
             $translator = new Translator($DI['Config']->get('language'), ['app' => $DI['Alias']->get('@app/../messages')]);
             foreach ($DI['PluginManager']->getLoadedPlugins() as $key => $dir) {
                 $translator->addPath($key, $dir . '/messages');
             }
             $translator->init();
             return $translator;
         };
         $DI['Url\\UrlMatcher'] = function ($DI) {
             return new Url\UrlMatcher($DI['Menu\\Page\\Collection'], $DI['Menu\\Post\\Collection']);
         };
     }
 }
Exemplo n.º 6
0
<?php

require_once __DIR__ . '/handler.php';
$handler = new ErrorHandler();
$handler->register();
function foo()
{
    fatal();
}
function bar()
{
    foo();
}
// warning
strpos();
// fatal
bar();
__halt_compiler();
Expected output:
E_WARNING: strpos() expects at least 2 parameters, 0 given in /home/buglloc/work/projects/php-fatal-handler/demo/test.php:16
#1 /home/buglloc/work/projects/php-fatal-handler/demo/test.php(16): strpos()
#2 {main}
E_ERROR: Call to undefined function fatal() in /home/buglloc/work/projects/php-fatal-handler/demo/test.php:9
#1 /home/buglloc/work/projects/php-fatal-handler/demo/test.php(13): foo()
#2 /home/buglloc/work/projects/php-fatal-handler/demo/test.php(19): bar()
#3 {main}
Ooops