Home php FILP / WHOOSS: How to resolve further script execution?

FILP / WHOOSS: How to resolve further script execution?

Author

Date

Category

Greetings, dear colleagues.

Who worked with the error processing library filp / wheops (it is used, for example, in Laravel 4) Maybe knows how to perform an action in Handler, but continue rendering a page? So that the question is clearer, briefly describe the task.

You need to make the site to report errors in a comfortable form. Conditionally there are two types of errors: fatal and non-infamous. Landing is displayed on the fatal and delayed allets by mail. Nefatal errors need to be discharged into the log, and then give a page in normal mode.

If there is no problem with the first subtitle, then the second is not given – when error_reporting (e_all) , wheops shuffling the engine when e_error ignores comments and warnings.


Answer 1, Authority 100%

After the study of the source code, it became clear that it is possible to solve the question only through inheritance. Added methods that set the types of errors for “quiet” logging, perhaps the solution to someone use it:

& lt;? php
/ **
 * Class corrects the imperfections of WHOOSS:
 * Allows you to declare certain errors in non-informal,
 * What gives the script the ability to be edited after error handling.
 * /
Class MyWHoops Extends \ WHOOPS \ RUN
{
PROTECTED $ BYPASSLEVEL;
/ **
 * IN CERTIAIN SCENARIOS, LIKE IN SHUTDOWN HANDER, WE CAN NOT THROW EXCEPTIONS
 * @var bool
 * /
Private $ CANTHROWEXCEPTIONS = TRUE;
/ **
 * The method is overloaded so that the non-infamous errors do not join the engine
 *
 * /
Public Function Handleerror ($ Level, $ Message, $ File = NULL, $ Line = NULL)
{
  if ($ LEVEL & amp; error_reporting ()) {
    Foreach ($ this- & gt; SilenceDPatterns AS $ Entry) {
      $ Pathmatches = (BOOL) preg_match ($ entry ["Pattern"], $ file);
      $ LevelMatches = $ Level & Amp; $ Entry ["LEVELS"];
      If ($ Pathmatches & Amp; & amp; $ levelmatches) {
        // Ignore The Error, ABORT HANDLING
        RETURN TRUE;
      }
    }
    // XXX WE PASS $ Level for the "Code" Param Only for BC ReaSons.
    // See https://github.com/filp/whoops/issues/267
    $ Exception = New ErrorException ($ Message, / * Code * / $ Level, / * Severity * / $ LEVEL, $ File, $ Line);
    // In this method, only the following line is measured:
    If ($ this- & gt; CanthrowExceptions & amp; & amp;! $ this- & gt; IsBypasslevel ($ LEVEL)) {
      Throw $ Exception;
    } else {
      $ this- & gt; HandleException ($ Exception);
    }
    // Do Not Propagate Errors Which Were Already Handled by Whaops.
    RETURN TRUE;
  }
  // PROPAGATE ERROR TO THE NEXT HANDLER, ALLOWS ERROR_GET_LAST () TO
  // Work on Silenced Errors.
  RETURN FALSE;
}
/ **
 * The method sets the level of pass
 *
 * /
Public Function SetBypasslevel ($ BYPASSLEVEL)
{
  $ this- & gt; bypasslevel = $ bypasslevel;
}
/ **
 * The method checks the level of skip
 *
 * /
Public Function IsBypasslevel ($ LEVEL)
{
  Return ($ LEVEL & AMP; $ this- & gt; bypasslevel) & gt; 0;
}
/ **
 * Special Case to Deal With Fatal Erros and The Like.
 * Inherited for compatibility with a private property of CanthrowExceptions
 * /
Public Function HandleShutdown ()
{
  // If We Reached This Step, We Are in Shutdown Handler.
  // An Exception Thrown In A Shutdown Handler Will Not Be Propagated
  // To The Exception Handler. Pass That Information Along.
  $ this- & gt; canthrolexceptions = false;
  $ error = error_get_last ();
  If ($ error & amp; & amp; $ this- & gt; islevelfatal ($ error ['type'])) {
    // If There Was a Fatal Error,
    // IT Was Not Handled in Handleerror Yet.
    $ this- & gt; handleerror (
      $ ERROR ['Type']
      $ error ['Message'],
      $ error ['file'],
      $ ERROR ['Line']
    );
  }
}
/ **
 * Inherited for compatibility with a private property of CanthrowExceptions
 * /
Private Static Function IslevelFatal ($ LEVEL)
{
  $ errors = e_error;
  $ errors | = E_PARSE;
  $ errors | = e_core_error;
  $ errors | = e_core_warning;
  $ errors | = e_compile_error;
  $ errors | = e_compile_warning; 
Return ($ LEVEL & AMP; $ errors) & gt; 0;
}
}

You can use like this:

& lt;? php
$ WHOOPS = New MyWHoops;
$ WHOOPS- & GT; PushHandler ($ Exception, $ Inspector, $ RUN) {
if (! $ run- & gt; isbypasslevel ($ exption- & gt; getseverity ())) {
  // Perform code for fatal errors (Landing, for example)
  // Clean the output from the remnants of the naught code:
  RETURN \ WHOOPS \ Handler \ Handler :: Quit;
} else {
  // Perform "on the background" code for other errors (for example, logging)
}
}) - & gt; register () - & gt; setBypasslevel (E_NOTICE | E_USER_NOTICE | E_STRICT | E_DepRecated | E_USER_DepRecated);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions