action-exception.php
2 years ago
condition-exception.php
2 years ago
condition-silence-exception.php
2 years ago
gateway-exception.php
2 years ago
handler-exception.php
2 years ago
integration-exception.php
2 years ago
invalid-macro-exception.php
2 years ago
not-router-request.php
2 years ago
parse-exception.php
2 years ago
plain-default-exception.php
2 years ago
preset-exception.php
2 years ago
query-builder-exception.php
2 years ago
repository-exception.php
2 years ago
request-exception.php
2 years ago
silence-exception.php
2 years ago
handler-exception.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Exceptions; |
| 5 | |
| 6 | use Jet_Form_Builder\Form_Messages\Manager; |
| 7 | use JFB_Modules\Dev; |
| 8 | use JFB_Modules\Logger; |
| 9 | |
| 10 | // If this file is called directly, abort. |
| 11 | if ( ! defined( 'WPINC' ) ) { |
| 12 | die; |
| 13 | } |
| 14 | |
| 15 | abstract class Handler_Exception extends \Exception { |
| 16 | |
| 17 | protected $default_type_message = 'failed'; |
| 18 | |
| 19 | protected $additional_data; |
| 20 | |
| 21 | public function __construct( $message = '', ...$additional_data ) { |
| 22 | parent::__construct( $message, 0, null ); |
| 23 | |
| 24 | $this->additional_data = $additional_data; |
| 25 | |
| 26 | $this->log(); |
| 27 | } |
| 28 | |
| 29 | public function set_code( $code ) { |
| 30 | $this->code = $code; |
| 31 | |
| 32 | return $this; |
| 33 | } |
| 34 | |
| 35 | public function dynamic_success(): Handler_Exception { |
| 36 | $this->message = Manager::dynamic_success( $this->message ); |
| 37 | |
| 38 | return $this; |
| 39 | } |
| 40 | |
| 41 | public function dynamic_error(): Handler_Exception { |
| 42 | $this->message = Manager::dynamic_error( $this->message ); |
| 43 | |
| 44 | return $this; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | public function get_form_status() { |
| 49 | return $this->message ?: $this->default_type_message; |
| 50 | } |
| 51 | |
| 52 | public function get_additional() { |
| 53 | return $this->additional_data; |
| 54 | } |
| 55 | |
| 56 | public function unset_log() { |
| 57 | Logger\Module::instance()->unset_last( static::class ); |
| 58 | } |
| 59 | |
| 60 | public function log() { |
| 61 | if ( ! jet_form_builder()->has_module( 'dev' ) ) { |
| 62 | return; |
| 63 | } |
| 64 | Logger\Module::instance()->push_log( |
| 65 | static::class, |
| 66 | array( |
| 67 | 'message' => $this->getMessage(), |
| 68 | 'file' => $this->make_pretty_filename( $this->getFile() ), |
| 69 | 'line' => $this->getLine(), |
| 70 | 'data' => $this->get_additional(), |
| 71 | 'version' => jet_form_builder()->get_version(), |
| 72 | 'action_id' => jet_fb_action_handler()->get_position(), |
| 73 | ) |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | private function make_pretty_filename( string $file ) { |
| 78 | $path = explode( 'wp-content\\', $file ); |
| 79 | |
| 80 | return $path[1] ?? ( explode( 'wp-content/', $file )[1] ?? $file ); |
| 81 | } |
| 82 | |
| 83 | } |
| 84 |