Example #1
0
 /**
  * Set exception AND error AND assertion handler.
  * @param callable|null $handler that takes ($message, $script, $line, $trace, $type, $other) and returns bool accordingly if it handled or not
  */
 function debug_handler($handler = null)
 {
     /* forward  */
     $exception_to_common = null;
     $error_to_common = null;
     $assertion_to_common = null;
     if (null !== $handler) {
         $exception_to_common = function ($e) use($handler) {
             /** @var Exception $e */
             return $handler($e->getMessage(), $e->getFile(), $e->getLine(), $e->getTrace(), 'exception', array('exception' => $e));
         };
         $error_to_common = function ($number, $message, $script, $line) use($handler) {
             return $handler($message, $script, $line, array(), 'php_error', array('php_error' => $number));
         };
         $assertion_to_common = function ($script, $line, $message) use($handler) {
             return $handler($message, $script, $line, array(), 'assertion', array());
         };
     }
     debug_handler_exception($exception_to_common);
     debug_handler_error($error_to_common);
     debug_handler_assertion($assertion_to_common);
 }
Example #2
0
 /**
  * @param string $path
  * @throws ErrorException
  */
 function ensure_dir_exists($path)
 {
     $handler = debug_handler_error();
     debug_handler_error(function ($errno, $errstr, $errfile, $errline, $errcontext) use($handler, $path) {
         if ($errno === 2 && is_dir($path)) {
             $ret = true;
         } else {
             $ret = $handler($errno, $errstr, $errfile, $errline, $errcontext);
         }
         return $ret;
     });
     mkdir($path);
     debug_handler_error($handler);
 }