*/ namespace LaswitchTech\Core; use LaswitchTech\Core\Configurator; // Soon replaced with Config use LaswitchTech\Core\Module; use Exception; class Bootstrap { const Default = [ "LOGGER" => [ "class" => "\LaswitchTech\coreLogger\Logger", "scope" => [ "Router", "API", "CLI" ] ], ... ]; /** * Constructor. */ public function __construct($scope){ // Set the global variable global $CONFIGURATOR; // Initialize Configurator (we’ll replace this with our new Config class) $CONFIGURATOR = new Configurator(['bootstrap']); // Retrieve the straps $straps = $CONFIGURATOR->get('bootstrap'); // Loop through the straps foreach(self::Default as $strap => $config){ // Check if an alternate strap exist if(isset($straps[$strap])){ foreach($config as $key => $value){ if(isset($straps[$strap][$key])){ $config[$key] = $straps[$strap][$key]; } } } // Check if strap matches scope if(!in_array($scope, $config['scope'])) continue; // Initialize the Global Variable global ${$strap}; // Set Class $class = $config['class']; // Check if the class exists if(class_exists($class)){ // Initialize the class in the global namespace ${$strap} = new $class(); } else { // Fall back to a default module class ${$strap} = new Module(); } } } }