-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.php
62 lines (51 loc) · 1.48 KB
/
core.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Exit if accessed directly
*/
if (!defined('ABSPATH')) {
exit;
}
final class WooZarinpalPlugin {
private static $instance = null;
public static function Instance(){
if(!self::$instance){
self::$instance = new self();
}
return self::$instance;
}
private function __construct()
{
add_action('woocommerce_blocks_loaded', [$this, 'include_files']);
}
/**
* Include init files
*
* @return void
*/
public function include_files()
{
$this->register_autoload();
require_once ZPGATE_INC_PATH . 'functions.php';
\ZarinpalGate\App\Hooks::init();
}
public function register_autoload()
{
if (function_exists('__autoload')) {
spl_autoload_register('__autoload');
}
spl_autoload_register([$this, 'autoloader']);
}
public function autoloader($class)
{
if(strpos($class, 'ZarinpalGate') !== false){
$class = str_replace(['ZarinpalGate\\', 'ZarinpalGate', '\\'], ['', '', '/'], $class);
$class_arr = explode('/', $class);
$file_name = $class_arr[array_key_last($class_arr)] . '.php';
unset($class_arr[array_key_last($class_arr)]);
$file_path = ZPGATE_PATH . strtolower(implode('/', $class_arr)) . '/' . $file_name;
if(file_exists($file_path) && is_readable($file_path)){
include_once($file_path);
}
}
}
}