PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.5.0
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.5.0
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / framework / Exception / ExceptionHandler.php

ExceptionHandler.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 3.5.0, at framework/Exception/ExceptionHandler.php

97 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\Framework\Exception;
4
5 class ExceptionHandler
6 {
7 const APPEND_TO_LOG_FILE = 3;
8
9 /**
10 * framework\App\Application
11 * @var Object
12 */
13 protected $app = null;
14
15 public function __construct($app)
16 {
17 $this->app = $app;
18 // $this->registerHandlers();
19 }
20
21 public function registerHandlers()
22 {
23 error_reporting(-1);
24 set_error_handler([$this, 'handleError']);
25 set_exception_handler([$this, 'handleException']);
26 register_shutdown_function([$this, 'handleShutdown']);
27 }
28
29 public function handleError($severity, $message, $file = '', $line = 0)
30 {
31 try {
32 if (error_reporting() & $severity) {
33 throw new \ErrorException($message, 0, $severity, $file, $line);
34 }
35 } catch(\Exception $e) {
36 $this->handleException($e);
37 }
38 }
39
40 public function handleException($e)
41 {
42 try {
43 if ($this->app->getEnv() != 'production') {
44 $this->report($e);
45 $this->render($e);
46 }
47 } catch (\Exception $e) {
48 wp_die(
49 '<pre>'
50 . $e->getMessage().' : '.$e->getFile().' ('.$e->getLine().')' .
51 '</pre>'
52 );
53 }
54 }
55
56 public function handleShutdown()
57 {
58 if (!is_null($error = error_get_last()) && $this->isFatal($error['type'])) {
59 $this->handleException(new \ErrorException(
60 $error['message'], 0, $error['type'], $error['file'], $error['line']
61 ));
62 }
63 }
64
65 public function report($e)
66 {
67 $logDir = $this->app->storagePath('logs');
68
69 if (!is_readable($logDir)) {
70 mkdir($logDir, 0777);
71 }
72
73 //Log in: wp-content/debug.log
74 if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) {
75 error_log((string) $e);
76 }
77
78 //Log in: plugin-root-dir/storage/logs/error.log
79 error_log(
80 '['.current_time('mysql').'] ' . (string) $e,
81 self::APPEND_TO_LOG_FILE,
82 $logDir.'/error.log'
83 );
84 }
85
86 public function render($e)
87 {
88 echo get_class($e) .' : '. $e->getMessage() . ' in ' . $e->getFile() . ' (' . $e->getLine() . ')';
89 echo '<br><pre>' . str_replace("\n", '<br>', $e->getTraceAsString()) . '</pre>';
90 }
91
92 protected function isFatal($type)
93 {
94 return in_array($type, [E_COMPILE_ERROR, E_CORE_ERROR, E_ERROR, E_PARSE]);
95 }
96 }
97