| 1 |
<?php |
| 2 |
/** |
| 3 |
* Blocks Bootstrap Class |
| 4 |
* |
| 5 |
* @package PRAD |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace PRAD\Includes\Blocks; |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Bootstrap class to initialize the blocks system |
| 15 |
*/ |
| 16 |
class Blocks_Bootstrap { |
| 17 |
|
| 18 |
/** |
| 19 |
* Instance of this class |
| 20 |
* |
| 21 |
* @var self |
| 22 |
*/ |
| 23 |
private static $instance = null; |
| 24 |
|
| 25 |
/** |
| 26 |
* Block system initialized flag |
| 27 |
* |
| 28 |
* @var bool |
| 29 |
*/ |
| 30 |
private bool $initialized = false; |
| 31 |
|
| 32 |
/** |
| 33 |
* Get singleton instance |
| 34 |
* |
| 35 |
* @return self |
| 36 |
*/ |
| 37 |
public static function get_instance(): self { |
| 38 |
if ( null === self::$instance ) { |
| 39 |
self::$instance = new self(); |
| 40 |
} |
| 41 |
|
| 42 |
return self::$instance; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Private constructor to prevent direct instantiation |
| 47 |
*/ |
| 48 |
private function __construct() { |
| 49 |
$this->init(); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Initialize the blocks system |
| 54 |
*/ |
| 55 |
public function init(): void { |
| 56 |
if ( $this->initialized ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
// Initialize main render blocks class. |
| 61 |
$this->init_render_blocks(); |
| 62 |
|
| 63 |
$this->initialized = true; |
| 64 |
|
| 65 |
do_action( 'prad_blocks_bootstrap_initialized' ); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
/** |
| 70 |
* Initialize main render blocks controller |
| 71 |
*/ |
| 72 |
private function init_render_blocks(): void { |
| 73 |
if ( class_exists( 'PRAD\Includes\Blocks\Render_Product_Fields' ) ) { |
| 74 |
new Render_Product_Fields(); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
/** |
| 80 |
* Get initialization status |
| 81 |
* |
| 82 |
* @return bool |
| 83 |
*/ |
| 84 |
public function is_initialized(): bool { |
| 85 |
return $this->initialized; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
/** |
| 90 |
* Force re-initialization (useful for testing) |
| 91 |
*/ |
| 92 |
public function force_reinit(): void { |
| 93 |
$this->initialized = false; |
| 94 |
$this->init(); |
| 95 |
} |
| 96 |
} |
| 97 |
|