classes
4 months ago
dist
4 months ago
changelog.txt
4 months ago
nps-survey-plugin-loader.php
4 months ago
nps-survey.php
4 months ago
version.json
4 months ago
nps-survey-plugin-loader.php
102 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Loader. |
| 4 | * |
| 5 | * @package {{package}} |
| 6 | * @since {{since}} |
| 7 | */ |
| 8 | |
| 9 | namespace NPS_Survey; |
| 10 | |
| 11 | if ( ! class_exists( 'NPS_Survey_Plugin_Loader' ) ) { |
| 12 | |
| 13 | /** |
| 14 | * Plugin_Loader |
| 15 | * |
| 16 | * @since 1.0.0 |
| 17 | */ |
| 18 | class NPS_Survey_Plugin_Loader { |
| 19 | /** |
| 20 | * Instance |
| 21 | * |
| 22 | * @access private |
| 23 | * @var object Class Instance. |
| 24 | * @since 1.0.0 |
| 25 | */ |
| 26 | private static $instance; |
| 27 | |
| 28 | /** |
| 29 | * Constructor |
| 30 | * |
| 31 | * @since 1.0.0 |
| 32 | */ |
| 33 | public function __construct() { |
| 34 | |
| 35 | spl_autoload_register( [ $this, 'autoload' ] ); |
| 36 | add_action( 'wp_loaded', [ $this, 'load_files' ] ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Initiator |
| 41 | * |
| 42 | * @since 1.0.0 |
| 43 | * @return object initialized object of class. |
| 44 | */ |
| 45 | public static function get_instance() { |
| 46 | if ( null === self::$instance ) { |
| 47 | self::$instance = new self(); |
| 48 | } |
| 49 | return self::$instance; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Autoload classes. |
| 54 | * |
| 55 | * @param string $class class name. |
| 56 | * @return void |
| 57 | */ |
| 58 | public function autoload( $class ): void { |
| 59 | if ( 0 !== strpos( $class, __NAMESPACE__ ) ) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | $class_to_load = $class; |
| 64 | |
| 65 | $filename = strtolower( |
| 66 | strval( |
| 67 | preg_replace( |
| 68 | [ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ], |
| 69 | [ '', '$1-$2', '-', DIRECTORY_SEPARATOR ], |
| 70 | $class_to_load |
| 71 | ) |
| 72 | ) |
| 73 | ); |
| 74 | |
| 75 | $file = NPS_SURVEY_DIR . $filename . '.php'; |
| 76 | |
| 77 | // if the file redable, include it. |
| 78 | if ( is_readable( $file ) ) { |
| 79 | // nosemgrep audit.php.lang.security.file.inclusion-arg - To allow the theme or plugin on WooCommerce Marketplace. |
| 80 | require_once $file; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Load Files |
| 86 | * |
| 87 | * @since 1.0.0 |
| 88 | * |
| 89 | * @return void |
| 90 | */ |
| 91 | public function load_files(): void { |
| 92 | require_once NPS_SURVEY_DIR . 'classes/nps-survey-script.php'; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Kicking this off by calling 'get_instance()' method |
| 98 | */ |
| 99 | NPS_Survey_Plugin_Loader::get_instance(); |
| 100 | |
| 101 | } |
| 102 |