actions
1 year ago
addons
11 months ago
admin
11 months ago
blocks
11 months ago
classes
11 months ago
db-queries
2 years ago
exceptions
2 years ago
form-messages
1 year ago
form-patterns
2 years ago
form-response
2 years ago
generators
2 years ago
migrations
2 years ago
presets
11 months ago
request
2 years ago
autoloader.php
1 year ago
file-upload.php
2 years ago
form-break.php
2 years ago
form-handler.php
11 months ago
form-manager.php
2 years ago
functions.php
2 years ago
live-form.php
2 years ago
plugin.php
2 years ago
autoloader.php
203 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Jet_Form_Builder; |
| 4 | |
| 5 | if ( ! defined( 'WPINC' ) ) { |
| 6 | exit; // Exit if accessed directly. |
| 7 | } |
| 8 | |
| 9 | /** |
| 10 | * Autoloader handler class is responsible for loading the different |
| 11 | * classes needed to run the plugin. |
| 12 | */ |
| 13 | class Autoloader { |
| 14 | |
| 15 | const NAMESPACES = array( |
| 16 | __NAMESPACE__ . '\\' => 'includes/', |
| 17 | 'JFB_Modules\\' => 'modules/', |
| 18 | 'JFB_Components\\' => 'components/', |
| 19 | 'JFB_Compatibility\\' => 'compatibility/', |
| 20 | ); |
| 21 | |
| 22 | /** |
| 23 | * @since 3.1.0 |
| 24 | */ |
| 25 | const DEPRECATED_CLASSMAP = array( |
| 26 | 'Jet_Form_Builder\\Classes\\Security\\Csrf_Token_Model' => 'JFB_Modules\\Security\\Csrf\\Csrf_Token_Model', |
| 27 | 'Jet_Form_Builder\\Classes\\Security\\Csrf_Token_View' => 'JFB_Modules\\Security\\Csrf\\Csrf_Token_View', |
| 28 | 'Jet_Form_Builder\\Classes\\Security\\Csrf_Tools' => 'JFB_Modules\\Security\\Csrf\\Csrf_Tools', |
| 29 | 'Jet_Form_Builder\\Integrations\\Forms_Captcha' => 'JFB_Modules\\Captcha\\Module', |
| 30 | 'Jet_Form_Builder\\Rest_Api\\Dynamic_Rest_Url_Trait' => 'JFB_Components\\Rest_Api\\Dynamic_Rest_Url_Trait', |
| 31 | 'Jet_Form_Builder\\Rest_Api\\Rest_Api_Controller_Base' => 'JFB_Components\\Rest_Api\\Rest_Api_Controller_Base', |
| 32 | 'Jet_Form_Builder\\Rest_Api\\Rest_Api_Endpoint_Base' => 'JFB_Components\\Rest_Api\\Rest_Api_Endpoint_Base', |
| 33 | 'Jet_Form_Builder\\Rest_Api\\Rest_Endpoint' => 'JFB_Components\\Rest_Api\\Rest_Endpoint', |
| 34 | 'Jet_Form_Builder\\Rest_Api\\Rest_Response' => 'JFB_Components\\Rest_Api\\Rest_Response', |
| 35 | 'Jet_Form_Builder\\Rest_Api\\Traits\\Paginated_Args' => 'JFB_Components\\Rest_Api\\Traits\\Paginated_Args', |
| 36 | 'Jet_Form_Builder\\Rest_Api\\Traits\\Rest_Fetch_Endpoint' => 'JFB_Components\\Rest_Api\\Traits\\Rest_Fetch_Endpoint', |
| 37 | // blocks |
| 38 | 'Jet_Form_Builder\\Blocks\\Manager' => 'Jet_Form_Builder\\Blocks\\Module', |
| 39 | 'Jet_Form_Builder\\Blocks\\Types\\Text_Field' => 'JFB_Modules\\Blocks_V2\\Text_Field\\Block_Type', |
| 40 | 'Jet_Form_Builder\\Blocks\\Render\\Text_Field_Render' => 'JFB_Modules\\Blocks_V2\\Text_Field\\Block_Render', |
| 41 | 'Jet_Form_Builder\\Blocks\\Types\\Repeater_Field' => 'JFB_Modules\\Blocks_V2\\Repeater_Field\\Block_Type', |
| 42 | 'Jet_Form_Builder\\Blocks\\Types\\Repeater_Row' => 'JFB_Modules\\Blocks_V2\\Repeater_Field\\Block_Type_Row', |
| 43 | // gateways |
| 44 | 'Jet_Form_Builder\\Gateways\\Base_Gateway' => 'JFB_Modules\\Gateways\\Base_Gateway', |
| 45 | 'Jet_Form_Builder\\Gateways\\Base_Scenario_Gateway' => 'JFB_Modules\\Gateways\\Base_Scenario_Gateway', |
| 46 | 'Jet_Form_Builder\\Gateways\\Scenarios_Abstract\\Scenario_Logic_Base' => 'JFB_Modules\\Gateways\\Scenarios_Abstract\\Scenario_Logic_Base', |
| 47 | 'Jet_Form_Builder\\Gateways\\Scenarios_Abstract\\Scenario_Logic_Repository' => 'JFB_Modules\\Gateways\\Scenarios_Abstract\\Scenario_Logic_Repository', |
| 48 | 'Jet_Form_Builder\\Gateways\\Scenarios_Abstract\\Scenario_View_Base' => 'JFB_Modules\\Gateways\\Scenarios_Abstract\\Scenario_View_Base', |
| 49 | 'Jet_Form_Builder\\Gateways\\Scenarios_Abstract\\Scenarios_Manager_Abstract' => 'JFB_Modules\\Gateways\\Scenarios_Abstract\\Scenarios_Manager_Abstract', |
| 50 | 'Jet_Form_Builder\\Gateways\\Scenarios_Abstract\\Scenarios_View_Repository' => 'JFB_Modules\\Gateways\\Scenarios_Abstract\\Scenarios_View_Repository', |
| 51 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payer_Model' => 'JFB_Modules\\Gateways\\Db_Models\\Payer_Model', |
| 52 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payer_Shipping_Model' => 'JFB_Modules\\Gateways\\Db_Models\\Payer_Shipping_Model', |
| 53 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payment_Meta_Model' => 'JFB_Modules\\Gateways\\Db_Models\\Payment_Meta_Model', |
| 54 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payment_Model' => 'JFB_Modules\\Gateways\\Db_Models\\Payment_Model', |
| 55 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payment_To_Payer_Shipping_Model' => 'JFB_Modules\\Gateways\\Db_Models\\Payment_To_Payer_Shipping_Model', |
| 56 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payment_To_Record' => 'JFB_Modules\\Gateways\\Db_Models\\Payment_To_Record', |
| 57 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Constraints\\Payer_Shipping_Model_Constraint' => 'JFB_Modules\\Gateways\\Db_Models\\Constraints\\Payer_Shipping_Model_Constraint', |
| 58 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Constraints\\Payment_Model_Constraint' => 'JFB_Modules\\Gateways\\Db_Models\\Constraints\\Payment_Model_Constraint', |
| 59 | 'Jet_Form_Builder\\Gateways\\Pages\\Single_Payment_Page' => 'JFB_Modules\\Gateways\\Pages\\Single_Payment_Page', |
| 60 | 'Jet_Form_Builder\\Gateways\\Rest_Api\\Gateway_Endpoint' => 'JFB_Modules\\Gateways\\Rest_Api\\Gateway_Endpoint', |
| 61 | 'Jet_Form_Builder\\Gateways\\Rest_Api\\Receive_Payments' => 'JFB_Modules\\Gateways\\Rest_Api\\Receive_Payments', |
| 62 | 'Jet_Form_Builder\\Gateways\\Rest_Api\\Receive_Payment' => 'JFB_Modules\\Gateways\\Rest_Api\\Receive_Payment', |
| 63 | 'Jet_Form_Builder\\Gateways\\Paypal\\Scenarios_Logic\\With_Resource_It' => 'JFB_Modules\\Gateways\\Paypal\\Scenarios_Logic\\With_Resource_It', |
| 64 | 'Jet_Form_Builder\\Gateways\\Paypal\\Scenarios_Views\\Pay_Now' => 'JFB_Modules\\Gateways\\Paypal\\Scenarios_Views\\Pay_Now', |
| 65 | 'Jet_Form_Builder\\Gateways\\Paypal\\Rest_Endpoints\\Fetch_Pay_Now_Editor' => 'JFB_Modules\\Gateways\\Paypal\\Rest_Endpoints\\Fetch_Pay_Now_Editor', |
| 66 | 'Jet_Form_Builder\\Gateways\\Paypal\\Api_Actions\\Base_Action' => 'JFB_Modules\\Gateways\\Paypal\\Api_Actions\\Base_Action', |
| 67 | 'Jet_Form_Builder\\Gateways\\Paypal\\Api_Actions\\Traits\\App_Context_Trait' => 'JFB_Modules\\Gateways\\Paypal\\Api_Actions\\Traits\\App_Context_Trait', |
| 68 | 'Jet_Form_Builder\\Gateways\\Paypal\\Controller' => 'JFB_Modules\\Gateways\\Paypal\\Controller', |
| 69 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Columns\\Row_Actions_Column' => 'JFB_Modules\\Gateways\\Table_Views\\Columns\\Row_Actions_Column', |
| 70 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Columns\\Gross_Column' => 'JFB_Modules\\Gateways\\Table_Views\\Columns\\Gross_Column', |
| 71 | 'Jet_Form_Builder\\Gateways\\Pages\\Payments_Page' => 'JFB_Modules\\Gateways\\Pages\\Payments_Page', |
| 72 | 'Jet_Form_Builder\\Gateways\\Meta_Boxes\\Payer_Box' => 'JFB_Modules\\Gateways\\Meta_Boxes\\Payer_Box', |
| 73 | 'Jet_Form_Builder\\Gateways\\Meta_Boxes\\Payer_Shipping_Box' => 'JFB_Modules\\Gateways\\Meta_Boxes\\Payer_Shipping_Box', |
| 74 | 'Jet_Form_Builder\\Gateways\\Meta_Boxes\\Columns\\Payment_Amount_Column' => 'JFB_Modules\\Gateways\\Meta_Boxes\\Columns\\Payment_Amount_Column', |
| 75 | 'Jet_Form_Builder\\Gateways\\Meta_Boxes\\Columns\\Payment_Currency_Column' => 'JFB_Modules\\Gateways\\Meta_Boxes\\Columns\\Payment_Currency_Column', |
| 76 | 'Jet_Form_Builder\\Gateways\\Meta_Boxes\\Columns\\Gateway_Type_Column' => 'JFB_Modules\\Gateways\\Meta_Boxes\\Columns\\Gateway_Type_Column', |
| 77 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Columns\\Payment_Type_Column' => 'JFB_Modules\\Gateways\\Table_Views\\Columns\\Payment_Type_Column', |
| 78 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Columns\\Payment_Status_Column' => 'JFB_Modules\\Gateways\\Table_Views\\Columns\\Payment_Status_Column', |
| 79 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Columns\\Payer_Column' => 'JFB_Modules\\Gateways\\Table_Views\\Columns\\Payer_Column', |
| 80 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Payments' => 'JFB_Modules\\Gateways\\Table_Views\\Payments', |
| 81 | 'Jet_Form_Builder\\Gateways\\Query_Views\\Payment_View' => 'JFB_Modules\\Gateways\\Query_Views\\Payment_View', |
| 82 | 'Jet_Form_Builder\\Gateways\\Query_Views\\Payment_With_Record_View' => 'JFB_Modules\\Gateways\\Query_Views\\Payment_With_Record_View', |
| 83 | // jet-engine compatibility |
| 84 | 'Jet_Form_Builder\\Blocks\\Types\\Map_Field' => 'JFB_Compatibility\\Jet_Engine\\Blocks\\Map_Field\\Block_Type', |
| 85 | 'JFB_Compatibility\\Jet_Engine\\Blocks\\Map_Field' => 'JFB_Compatibility\\Jet_Engine\\Blocks\\Map_Field\\Block_Type', |
| 86 | // repository component |
| 87 | 'Jet_Form_Builder\\Classes\\Repository\\Repository_Pattern_Trait' => 'JFB_Components\\Repository\\Repository_Pattern_Trait', |
| 88 | 'Jet_Form_Builder\\Classes\\Repository\\Repository_Static_Item_It' => 'JFB_Components\\Repository\\Repository_Static_Item_It', |
| 89 | // form-record |
| 90 | 'Jet_Form_Builder\\Actions\\Types\\Save_Record' => 'JFB_Modules\\Form_Record\\Action_Types\\Save_Record', |
| 91 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Controller' => 'JFB_Modules\\Form_Record\\Controller', |
| 92 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Admin\\Meta_Boxes\\Form_Record_Values_Box' => 'JFB_Modules\\Form_Record\\Admin\\Meta_Boxes\\Form_Record_Values_Box', |
| 93 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Admin\\View_Columns\\Error_Message_Column' => 'JFB_Modules\\Form_Record\\Admin\\View_Columns\\Error_Message_Column', |
| 94 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Models\\Record_Model' => 'JFB_Modules\\Form_Record\\Models\\Record_Model', |
| 95 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Admin\\Pages\\Single_Form_Record_Page' => 'JFB_Modules\\Form_Record\\Admin\\Pages\\Single_Form_Record_Page', |
| 96 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Constraints\\Record_Model_Constraint' => 'JFB_Modules\\Form_Record\\Constraints\\Record_Model_Constraint', |
| 97 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Query_Views\\Record_Fields_View' => 'JFB_Modules\\Form_Record\\Query_Views\\Record_Fields_View', |
| 98 | // dev-mode module |
| 99 | 'Jet_Form_Builder\\Dev_Mode\\Manager' => 'JFB_Modules\\Dev\\Module', |
| 100 | 'Jet_Form_Builder\\Dev_Mode\\Logger' => 'JFB_Modules\\Logger\\Module', |
| 101 | // request related |
| 102 | 'Jet_Form_Builder\\Request\\Parser_Manager' => 'JFB_Modules\\Block_Parsers\\Module', |
| 103 | 'Jet_Form_Builder\\Request\\Field_Data_Parser' => 'JFB_Modules\\Block_Parsers\\Field_Data_Parser', |
| 104 | 'Jet_Form_Builder\\Blocks\\Validation' => 'JFB_Modules\\Validation\\Module', |
| 105 | // block renderers |
| 106 | 'Jet_Form_Builder\\Blocks\\Render\\Radio_Field_Render' => 'JFB_Modules\\Option_Field\\Blocks\\Radio\\Block_Render', |
| 107 | 'Jet_Form_Builder\\Blocks\\Render\\Select_Field_Render' => 'JFB_Modules\\Option_Field\\Blocks\\Select\\Block_Render', |
| 108 | 'Jet_Form_Builder\\Blocks\\Render\\Checkbox_Field_Render' => 'JFB_Modules\\Option_Field\\Blocks\\Checkbox\\Block_Render', |
| 109 | ); |
| 110 | |
| 111 | /** |
| 112 | * Run autoloader. |
| 113 | * |
| 114 | * Register a function as `__autoload()` implementation. |
| 115 | * |
| 116 | * @since 1.6.0 |
| 117 | * @access public |
| 118 | * @static |
| 119 | */ |
| 120 | public static function run() { |
| 121 | spl_autoload_register( array( __CLASS__, 'autoload' ) ); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Load class. |
| 126 | * |
| 127 | * For a given class name, require the class file. |
| 128 | * |
| 129 | * @param string $space |
| 130 | * @param array $class_parts |
| 131 | * |
| 132 | * @since 1.6.0 |
| 133 | * @access private |
| 134 | * @static |
| 135 | */ |
| 136 | private static function load_class( string $space, array $class_parts ) { |
| 137 | |
| 138 | $file = implode( DIRECTORY_SEPARATOR, $class_parts ); |
| 139 | $file = strtolower( str_replace( '_', '-', $file ) ); |
| 140 | $filepath = JET_FORM_BUILDER_PATH . self::NAMESPACES[ $space ] . $file . '.php'; |
| 141 | |
| 142 | if ( is_readable( $filepath ) ) { |
| 143 | require_once $filepath; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Autoload. |
| 149 | * |
| 150 | * For a given class, check if it exist and load it. |
| 151 | * |
| 152 | * @param $class_name |
| 153 | * |
| 154 | * @since 1.6.0 |
| 155 | * @access private |
| 156 | * @static |
| 157 | */ |
| 158 | private static function autoload( $class_name ) { |
| 159 | |
| 160 | $parts = explode( '\\', $class_name ); |
| 161 | |
| 162 | if ( ! array_key_exists( $parts[0] . '\\', self::NAMESPACES ) ) { |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | list( $prefix, $parts, $relative ) = self::get_class_parts( $parts ); |
| 167 | |
| 168 | $has_alias = isset( self::DEPRECATED_CLASSMAP[ $prefix . $relative ] ); |
| 169 | |
| 170 | if ( $has_alias ) { |
| 171 | list( $prefix, $parts, $relative ) = self::get_class_parts( |
| 172 | self::DEPRECATED_CLASSMAP[ $prefix . $relative ] |
| 173 | ); |
| 174 | } |
| 175 | |
| 176 | if ( ! class_exists( $prefix . $relative ) ) { |
| 177 | self::load_class( $prefix, $parts ); |
| 178 | } |
| 179 | |
| 180 | if ( $has_alias ) { |
| 181 | class_alias( $prefix . $relative, $class_name ); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * @param array|string $class_name |
| 187 | * |
| 188 | * @return array |
| 189 | */ |
| 190 | private static function get_class_parts( $class_name ): array { |
| 191 | $parts = is_array( $class_name ) ? $class_name : explode( '\\', $class_name ); |
| 192 | |
| 193 | // global namespace |
| 194 | $prefix = $parts[0] . '\\'; |
| 195 | // remove first element |
| 196 | array_shift( $parts ); |
| 197 | |
| 198 | $relative = implode( '\\', $parts ); |
| 199 | |
| 200 | return array( $prefix, $parts, $relative ); |
| 201 | } |
| 202 | } |
| 203 |