actions
2 years ago
addons
2 years ago
admin
2 years ago
blocks
2 years ago
classes
2 years ago
db-queries
2 years ago
exceptions
2 years ago
form-messages
2 years ago
form-patterns
2 years ago
form-response
2 years ago
generators
2 years ago
integrations
2 years ago
migrations
2 years ago
presets
2 years ago
request
2 years ago
shortcodes
2 years ago
autoloader.php
2 years ago
file-upload.php
2 years ago
form-break.php
2 years ago
form-handler.php
2 years 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
192 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 | 'Jet_Form_Builder\\Blocks\\Manager' => 'Jet_Form_Builder\\Blocks\\Module', |
| 38 | // gateways |
| 39 | 'Jet_Form_Builder\\Gateways\\Base_Gateway' => 'JFB_Modules\\Gateways\\Base_Gateway', |
| 40 | 'Jet_Form_Builder\\Gateways\\Base_Scenario_Gateway' => 'JFB_Modules\\Gateways\\Base_Scenario_Gateway', |
| 41 | 'Jet_Form_Builder\\Gateways\\Scenarios_Abstract\\Scenario_Logic_Base' => 'JFB_Modules\\Gateways\\Scenarios_Abstract\\Scenario_Logic_Base', |
| 42 | 'Jet_Form_Builder\\Gateways\\Scenarios_Abstract\\Scenario_Logic_Repository' => 'JFB_Modules\\Gateways\\Scenarios_Abstract\\Scenario_Logic_Repository', |
| 43 | 'Jet_Form_Builder\\Gateways\\Scenarios_Abstract\\Scenario_View_Base' => 'JFB_Modules\\Gateways\\Scenarios_Abstract\\Scenario_View_Base', |
| 44 | 'Jet_Form_Builder\\Gateways\\Scenarios_Abstract\\Scenarios_Manager_Abstract' => 'JFB_Modules\\Gateways\\Scenarios_Abstract\\Scenarios_Manager_Abstract', |
| 45 | 'Jet_Form_Builder\\Gateways\\Scenarios_Abstract\\Scenarios_View_Repository' => 'JFB_Modules\\Gateways\\Scenarios_Abstract\\Scenarios_View_Repository', |
| 46 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payer_Model' => 'JFB_Modules\\Gateways\\Db_Models\\Payer_Model', |
| 47 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payer_Shipping_Model' => 'JFB_Modules\\Gateways\\Db_Models\\Payer_Shipping_Model', |
| 48 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payment_Meta_Model' => 'JFB_Modules\\Gateways\\Db_Models\\Payment_Meta_Model', |
| 49 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payment_Model' => 'JFB_Modules\\Gateways\\Db_Models\\Payment_Model', |
| 50 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payment_To_Payer_Shipping_Model' => 'JFB_Modules\\Gateways\\Db_Models\\Payment_To_Payer_Shipping_Model', |
| 51 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Payment_To_Record' => 'JFB_Modules\\Gateways\\Db_Models\\Payment_To_Record', |
| 52 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Constraints\\Payer_Shipping_Model_Constraint' => 'JFB_Modules\\Gateways\\Db_Models\\Constraints\\Payer_Shipping_Model_Constraint', |
| 53 | 'Jet_Form_Builder\\Gateways\\Db_Models\\Constraints\\Payment_Model_Constraint' => 'JFB_Modules\\Gateways\\Db_Models\\Constraints\\Payment_Model_Constraint', |
| 54 | 'Jet_Form_Builder\\Gateways\\Pages\\Single_Payment_Page' => 'JFB_Modules\\Gateways\\Pages\\Single_Payment_Page', |
| 55 | 'Jet_Form_Builder\\Gateways\\Rest_Api\\Gateway_Endpoint' => 'JFB_Modules\\Gateways\\Rest_Api\\Gateway_Endpoint', |
| 56 | 'Jet_Form_Builder\\Gateways\\Rest_Api\\Receive_Payments' => 'JFB_Modules\\Gateways\\Rest_Api\\Receive_Payments', |
| 57 | 'Jet_Form_Builder\\Gateways\\Rest_Api\\Receive_Payment' => 'JFB_Modules\\Gateways\\Rest_Api\\Receive_Payment', |
| 58 | 'Jet_Form_Builder\\Gateways\\Paypal\\Scenarios_Logic\\With_Resource_It' => 'JFB_Modules\\Gateways\\Paypal\\Scenarios_Logic\\With_Resource_It', |
| 59 | 'Jet_Form_Builder\\Gateways\\Paypal\\Scenarios_Views\\Pay_Now' => 'JFB_Modules\\Gateways\\Paypal\\Scenarios_Views\\Pay_Now', |
| 60 | 'Jet_Form_Builder\\Gateways\\Paypal\\Rest_Endpoints\\Fetch_Pay_Now_Editor' => 'JFB_Modules\\Gateways\\Paypal\\Rest_Endpoints\\Fetch_Pay_Now_Editor', |
| 61 | 'Jet_Form_Builder\\Gateways\\Paypal\\Api_Actions\\Base_Action' => 'JFB_Modules\\Gateways\\Paypal\\Api_Actions\\Base_Action', |
| 62 | 'Jet_Form_Builder\\Gateways\\Paypal\\Api_Actions\\Traits\\App_Context_Trait' => 'JFB_Modules\\Gateways\\Paypal\\Api_Actions\\Traits\\App_Context_Trait', |
| 63 | 'Jet_Form_Builder\\Gateways\\Paypal\\Controller' => 'JFB_Modules\\Gateways\\Paypal\\Controller', |
| 64 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Columns\\Row_Actions_Column' => 'JFB_Modules\\Gateways\\Table_Views\\Columns\\Row_Actions_Column', |
| 65 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Columns\\Gross_Column' => 'JFB_Modules\\Gateways\\Table_Views\\Columns\\Gross_Column', |
| 66 | 'Jet_Form_Builder\\Gateways\\Pages\\Payments_Page' => 'JFB_Modules\\Gateways\\Pages\\Payments_Page', |
| 67 | 'Jet_Form_Builder\\Gateways\\Meta_Boxes\\Payer_Box' => 'JFB_Modules\\Gateways\\Meta_Boxes\\Payer_Box', |
| 68 | 'Jet_Form_Builder\\Gateways\\Meta_Boxes\\Payer_Shipping_Box' => 'JFB_Modules\\Gateways\\Meta_Boxes\\Payer_Shipping_Box', |
| 69 | 'Jet_Form_Builder\\Gateways\\Meta_Boxes\\Columns\\Payment_Amount_Column' => 'JFB_Modules\\Gateways\\Meta_Boxes\\Columns\\Payment_Amount_Column', |
| 70 | 'Jet_Form_Builder\\Gateways\\Meta_Boxes\\Columns\\Payment_Currency_Column' => 'JFB_Modules\\Gateways\\Meta_Boxes\\Columns\\Payment_Currency_Column', |
| 71 | 'Jet_Form_Builder\\Gateways\\Meta_Boxes\\Columns\\Gateway_Type_Column' => 'JFB_Modules\\Gateways\\Meta_Boxes\\Columns\\Gateway_Type_Column', |
| 72 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Columns\\Payment_Type_Column' => 'JFB_Modules\\Gateways\\Table_Views\\Columns\\Payment_Type_Column', |
| 73 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Columns\\Payment_Status_Column' => 'JFB_Modules\\Gateways\\Table_Views\\Columns\\Payment_Status_Column', |
| 74 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Columns\\Payer_Column' => 'JFB_Modules\\Gateways\\Table_Views\\Columns\\Payer_Column', |
| 75 | 'Jet_Form_Builder\\Gateways\\Table_Views\\Payments' => 'JFB_Modules\\Gateways\\Table_Views\\Payments', |
| 76 | 'Jet_Form_Builder\\Gateways\\Query_Views\\Payment_View' => 'JFB_Modules\\Gateways\\Query_Views\\Payment_View', |
| 77 | 'Jet_Form_Builder\\Gateways\\Query_Views\\Payment_With_Record_View' => 'JFB_Modules\\Gateways\\Query_Views\\Payment_With_Record_View', |
| 78 | // jet-engine compatibility |
| 79 | 'Jet_Form_Builder\\Blocks\\Types\\Map_Field' => 'JFB_Compatibility\\Jet_Engine\\Blocks\\Map_Field', |
| 80 | // repository component |
| 81 | 'Jet_Form_Builder\\Classes\\Repository\\Repository_Pattern_Trait' => 'JFB_Components\\Repository\\Repository_Pattern_Trait', |
| 82 | 'Jet_Form_Builder\\Classes\\Repository\\Repository_Static_Item_It' => 'JFB_Components\\Repository\\Repository_Static_Item_It', |
| 83 | // form-record |
| 84 | 'Jet_Form_Builder\\Actions\\Types\\Save_Record' => 'JFB_Modules\\Form_Record\\Action_Types\\Save_Record', |
| 85 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Controller' => 'JFB_Modules\\Form_Record\\Controller', |
| 86 | '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', |
| 87 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Admin\\View_Columns\\Error_Message_Column' => 'JFB_Modules\\Form_Record\\Admin\\View_Columns\\Error_Message_Column', |
| 88 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Models\\Record_Model' => 'JFB_Modules\\Form_Record\\Models\\Record_Model', |
| 89 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Admin\\Pages\\Single_Form_Record_Page' => 'JFB_Modules\\Form_Record\\Admin\\Pages\\Single_Form_Record_Page', |
| 90 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Constraints\\Record_Model_Constraint' => 'JFB_Modules\\Form_Record\\Constraints\\Record_Model_Constraint', |
| 91 | 'Jet_Form_Builder\\Actions\\Methods\\Form_Record\\Query_Views\\Record_Fields_View' => 'JFB_Modules\\Form_Record\\Query_Views\\Record_Fields_View', |
| 92 | // dev-mode module |
| 93 | 'Jet_Form_Builder\\Dev_Mode\\Manager' => 'JFB_Modules\\Dev\\Module', |
| 94 | 'Jet_Form_Builder\\Dev_Mode\\Logger' => 'JFB_Modules\\Logger\\Module', |
| 95 | // request related |
| 96 | 'Jet_Form_Builder\\Request\\Parser_Manager' => 'JFB_Modules\\Block_Parsers\\Module', |
| 97 | 'Jet_Form_Builder\\Request\\Field_Data_Parser' => 'JFB_Modules\\Block_Parsers\\Field_Data_Parser', |
| 98 | ); |
| 99 | |
| 100 | /** |
| 101 | * Run autoloader. |
| 102 | * |
| 103 | * Register a function as `__autoload()` implementation. |
| 104 | * |
| 105 | * @since 1.6.0 |
| 106 | * @access public |
| 107 | * @static |
| 108 | */ |
| 109 | public static function run() { |
| 110 | spl_autoload_register( array( __CLASS__, 'autoload' ) ); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Load class. |
| 115 | * |
| 116 | * For a given class name, require the class file. |
| 117 | * |
| 118 | * @param string $space |
| 119 | * @param array $class_parts |
| 120 | * |
| 121 | * @since 1.6.0 |
| 122 | * @access private |
| 123 | * @static |
| 124 | */ |
| 125 | private static function load_class( string $space, array $class_parts ) { |
| 126 | |
| 127 | $file = implode( DIRECTORY_SEPARATOR, $class_parts ); |
| 128 | $file = strtolower( str_replace( '_', '-', $file ) ); |
| 129 | $filepath = JET_FORM_BUILDER_PATH . self::NAMESPACES[ $space ] . $file . '.php'; |
| 130 | |
| 131 | if ( is_readable( $filepath ) ) { |
| 132 | require_once $filepath; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Autoload. |
| 138 | * |
| 139 | * For a given class, check if it exist and load it. |
| 140 | * |
| 141 | * @param $class_name |
| 142 | * |
| 143 | * @since 1.6.0 |
| 144 | * @access private |
| 145 | * @static |
| 146 | */ |
| 147 | private static function autoload( $class_name ) { |
| 148 | |
| 149 | $parts = explode( '\\', $class_name ); |
| 150 | |
| 151 | if ( ! array_key_exists( $parts[0] . '\\', self::NAMESPACES ) ) { |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | list( $prefix, $parts, $relative ) = self::get_class_parts( $parts ); |
| 156 | |
| 157 | $has_alias = isset( self::DEPRECATED_CLASSMAP[ $prefix . $relative ] ); |
| 158 | |
| 159 | if ( $has_alias ) { |
| 160 | list( $prefix, $parts, $relative ) = self::get_class_parts( |
| 161 | self::DEPRECATED_CLASSMAP[ $prefix . $relative ] |
| 162 | ); |
| 163 | } |
| 164 | |
| 165 | if ( ! class_exists( $prefix . $relative ) ) { |
| 166 | self::load_class( $prefix, $parts ); |
| 167 | } |
| 168 | |
| 169 | if ( $has_alias ) { |
| 170 | class_alias( $prefix . $relative, $class_name ); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * @param array|string $class_name |
| 176 | * |
| 177 | * @return array |
| 178 | */ |
| 179 | private static function get_class_parts( $class_name ): array { |
| 180 | $parts = is_array( $class_name ) ? $class_name : explode( '\\', $class_name ); |
| 181 | |
| 182 | // global namespace |
| 183 | $prefix = $parts[0] . '\\'; |
| 184 | // remove first element |
| 185 | array_shift( $parts ); |
| 186 | |
| 187 | $relative = implode( '\\', $parts ); |
| 188 | |
| 189 | return array( $prefix, $parts, $relative ); |
| 190 | } |
| 191 | } |
| 192 |