| 1 |
<?php |
| 2 |
/** |
| 3 |
* CartFlows Admin. |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace CartflowsAdmin; |
| 9 |
|
| 10 |
use CartflowsAdmin\AdminCore\Api\ApiInit; |
| 11 |
use CartflowsAdmin\AdminCore\Ajax\AjaxInit; |
| 12 |
use CartflowsAdmin\AdminCore\Inc\AdminMenu; |
| 13 |
use CartflowsAdmin\AdminCore\Inc\OnboardingCore; |
| 14 |
use CartflowsAdmin\AdminCore\Inc\StoreCheckout; |
| 15 |
|
| 16 |
// Exit if accessed directly. |
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
exit; |
| 19 |
} |
| 20 |
/** |
| 21 |
* Class Admin_Loader. |
| 22 |
*/ |
| 23 |
class Admin_Loader { |
| 24 |
|
| 25 |
/** |
| 26 |
* Instance |
| 27 |
* |
| 28 |
* @access private |
| 29 |
* @var object Class object. |
| 30 |
* @since 1.0.0 |
| 31 |
*/ |
| 32 |
private static $instance; |
| 33 |
|
| 34 |
/** |
| 35 |
* Initiator |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
* @return object initialized object of class. |
| 39 |
*/ |
| 40 |
public static function get_instance() { |
| 41 |
if ( ! isset( self::$instance ) ) { |
| 42 |
self::$instance = new self(); |
| 43 |
} |
| 44 |
return self::$instance; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Autoload classes. |
| 49 |
* |
| 50 |
* @param string $class class name. |
| 51 |
*/ |
| 52 |
public function autoload( $class ) { |
| 53 |
|
| 54 |
if ( 0 !== strpos( $class, __NAMESPACE__ ) ) { |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
$class_to_load = $class; |
| 59 |
|
| 60 |
if ( ! class_exists( $class_to_load ) ) { |
| 61 |
$filename = strtolower( |
| 62 |
preg_replace( |
| 63 |
array( '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ), |
| 64 |
array( '', '$1-$2', '-', DIRECTORY_SEPARATOR ), |
| 65 |
$class_to_load |
| 66 |
) |
| 67 |
); |
| 68 |
|
| 69 |
$file = CARTFLOWS_DIR . $filename . '.php'; |
| 70 |
|
| 71 |
// if the file redable, include it. |
| 72 |
if ( is_readable( $file ) ) { |
| 73 |
include $file; |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Constructor |
| 80 |
* |
| 81 |
* @since 1.0.0 |
| 82 |
*/ |
| 83 |
public function __construct() { |
| 84 |
|
| 85 |
spl_autoload_register( array( $this, 'autoload' ) ); |
| 86 |
|
| 87 |
$this->define_constants(); |
| 88 |
$this->setup_classes(); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Include required classes. |
| 93 |
*/ |
| 94 |
public function define_constants() { |
| 95 |
define( 'CARTFLOWS_ADMIN_CORE_DIR', CARTFLOWS_DIR . 'admin-core/' ); |
| 96 |
define( 'CARTFLOWS_ADMIN_CORE_URL', CARTFLOWS_URL . 'admin-core/' ); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Include required classes. |
| 101 |
*/ |
| 102 |
public function setup_classes() { |
| 103 |
|
| 104 |
/* Init API */ |
| 105 |
ApiInit::get_instance(); |
| 106 |
|
| 107 |
if ( is_admin() ) { |
| 108 |
StoreCheckout::get_instance(); |
| 109 |
/* Setup Menu */ |
| 110 |
AdminMenu::get_instance(); |
| 111 |
|
| 112 |
/* Ajax init */ |
| 113 |
AjaxInit::get_instance(); |
| 114 |
|
| 115 |
OnboardingCore::get_instance(); |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
Admin_Loader::get_instance(); |
| 121 |
|