| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Module API Backups Admin class. |
| 4 |
* |
| 5 |
* @package MainWP\Dashboard |
| 6 |
* @version 5.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace MainWP\Dashboard\Module\ApiBackups; |
| 10 |
|
| 11 |
// Exit if accessed directly. |
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Class Api_Backups_Manager |
| 18 |
*/ |
| 19 |
class Api_Backups_Manager { |
| 20 |
|
| 21 |
|
| 22 |
/** |
| 23 |
* Static variable to hold the single instance of the class. |
| 24 |
* |
| 25 |
* @static |
| 26 |
* |
| 27 |
* @var mixed Default null |
| 28 |
*/ |
| 29 |
public static $instance = null; |
| 30 |
|
| 31 |
/** |
| 32 |
* Get Instance |
| 33 |
* |
| 34 |
* Creates public static instance. |
| 35 |
* |
| 36 |
* @static |
| 37 |
* |
| 38 |
* @return Api_Backups_Manager |
| 39 |
*/ |
| 40 |
public static function get_instance() { |
| 41 |
if ( null === static::$instance ) { |
| 42 |
static::$instance = new self(); |
| 43 |
} |
| 44 |
return static::$instance; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Constructor |
| 49 |
* |
| 50 |
* Runs each time the class is called. |
| 51 |
*/ |
| 52 |
public function __construct() { |
| 53 |
spl_autoload_register( array( $this, 'autoload' ) ); |
| 54 |
Api_Backups_Admin::get_instance(); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Autoloader for classes. |
| 59 |
* |
| 60 |
* @param string $class_name class name. |
| 61 |
*/ |
| 62 |
public function autoload( $class_name ) { |
| 63 |
|
| 64 |
if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class_name, $matches ) ) { |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
static $reflection; |
| 69 |
|
| 70 |
if ( empty( $reflection ) ) { |
| 71 |
$reflection = new \ReflectionObject( $this ); |
| 72 |
} |
| 73 |
|
| 74 |
if ( $reflection->getNamespaceName() !== $matches['namespace'] ) { |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
$autoload_name = $matches['autoload']; |
| 79 |
$autoload_dir = static::get_location_path(); |
| 80 |
|
| 81 |
$load_dirs = array( |
| 82 |
'classes' => 'class', |
| 83 |
); |
| 84 |
foreach ( $load_dirs as $dir => $prefix ) { |
| 85 |
$dir = $dir . DIRECTORY_SEPARATOR; |
| 86 |
$autoload_path = sprintf( '%s%s%s-%s.php', $autoload_dir, $dir, $prefix, strtolower( str_replace( '_', '-', $autoload_name ) ) ); |
| 87 |
if ( is_readable( $autoload_path ) ) { |
| 88 |
require_once $autoload_path; // NOSONAR - WP compatible. |
| 89 |
return; |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Method get_location(). |
| 96 |
* |
| 97 |
* @param string $path what to get path/url. |
| 98 |
* |
| 99 |
* @return string value. |
| 100 |
*/ |
| 101 |
public static function get_location_path( $path = 'dir' ) { |
| 102 |
$location = array( |
| 103 |
'dir' => MAINWP_MODULES_DIR . 'api-backups' . DIRECTORY_SEPARATOR, |
| 104 |
'url' => MAINWP_MODULES_URL . 'api-backups/', |
| 105 |
); |
| 106 |
return isset( $location[ $path ] ) ? $location[ $path ] : ''; |
| 107 |
} |
| 108 |
} |
| 109 |
|