GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
GravityFormsHandler.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @license GPL-2.0-or-later
4  *
5  * Modified by gravityview on 13-January-2023 using Strauss.
6  * @see https://github.com/BrianHenryIE/strauss
7  */
8 
10 
11 use GravityKit\GravityView\Monolog\Logger as MonologLogger;
13 use GFForms;
14 use GFLogging;
15 use GFAddOn;
16 
17 /**
18  * Handler for Gravity Forms logging.
19  */
20 class GravityFormsHandler extends AbstractProcessingHandler {
21  /**
22  * @since 1.0.0
23  *
24  * @var string Logger unique ID.
25  */
26  protected $_logger_id;
27 
28  /**
29  * @since 1.0.0
30  *
31  * @var string Logger title.
32  */
33  protected $_logger_title;
34 
35  /**
36  * Class constructor.
37  *
38  * @since 1.0.0
39  *
40  * @param string $logger_id Logger unique ID ("slug" as used by GFAddOn).
41  * @param string $logger_title Logger title ("title" as used by GFAddOn).
42  * @param int|string $level The minimum logging level at which this handler will be triggered. Default: DEBUG (100).
43  * @param bool $bubble Whether the messages that are handled can bubble up the stack or not. Default: true.
44  *
45  * @return void
46  */
47  public function __construct( $logger_id, $logger_title, $level = MonologLogger::DEBUG, $bubble = true ) {
48  if ( ! class_exists( 'GFForms' ) || ! class_exists( 'GFLogging' ) ) {
49  return;
50  }
51 
52  $this->_logger_id = $logger_id;
53  $this->_logger_title = $logger_title;
54 
55  GFForms::include_addon_framework();
56 
57  GFLogging::include_logger();
58 
59  new MockGFAddon( $logger_id, $logger_title );
60 
61  parent::__construct( $level, $bubble );
62  }
63 
64  /**
65  * {@inheritdoc}
66  */
67  protected function write( array $record ) {
68  $monolog_to_klogger_log_level_map = [
69  'DEBUG' => \Klogger::DEBUG,
70  'INFO' => \Klogger::INFO,
71  'NOTICE' => \Klogger::INFO,
72  'WARNING' => \Klogger::WARN,
73  'ERROR' => \Klogger::ERROR,
74  'CRITICAL' => \Klogger::FATAL,
75  'ALERT' => \Klogger::WARN,
76  'EMERGENCY' => \Klogger::WARN,
77  ];
78 
79  \GFLogging::log_message( $this->_logger_id, $record['formatted'], $monolog_to_klogger_log_level_map[ $record['level_name'] ] );
80  }
81 }
82 
83 class MockGFAddon extends GFAddOn {
84  /**
85  * {@inheritdoc}
86  */
87  protected $_slug;
88 
89  /**
90  * {@inheritdoc}
91  */
92  protected $_title;
93 
94  /**
95  * {@inheritdoc}
96  */
97  protected $_path = '';
98 
99  /**
100  * {@inheritdoc}
101  */
102  protected $_full_path = __FILE__;
103 
104  /**
105  * {@inheritdoc}
106  */
107  public function __construct( $logger_id, $logger_title ) {
108  if ( ! class_exists( 'GFForms' ) || ! class_exists( 'GFLogging' ) ) {
109  return;
110  }
111 
112  $this->_slug = $logger_id ?: $this->_slug;
113  $this->_title = $logger_title ?: $this->_title;
114 
115  parent::__construct();
116  }
117 }
__construct( $logger_id, $logger_title, $level=MonologLogger::DEBUG, $bubble=true)
Class constructor.