182
core/c/auto.php
Normal file
182
core/c/auto.php
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
<?php
|
||||||
|
namespace Nibiru\Auto;
|
||||||
|
/**
|
||||||
|
* Class Auto
|
||||||
|
* @project core
|
||||||
|
* @desc This is a PHP class file, please specify the use
|
||||||
|
* @author stephan - Nibiru Framework
|
||||||
|
* @date 27.02.24
|
||||||
|
* @time 13:35
|
||||||
|
* @package Nibiru\Auto
|
||||||
|
*/
|
||||||
|
use RecursiveDirectoryIterator;
|
||||||
|
use RecursiveIteratorIterator;
|
||||||
|
use RegexIterator;
|
||||||
|
use Nibiru\Config;
|
||||||
|
use Nibiru\View;
|
||||||
|
class Auto
|
||||||
|
{
|
||||||
|
const SETTINGS_SECTION = "AUTOLOADER";
|
||||||
|
const DB_MODEL_FOLDER = "dbmodel";
|
||||||
|
const SETTINGS_MODULE_SELECTOR = "module";
|
||||||
|
const SETTINGS_CLASS_POS = "class.pos";
|
||||||
|
const SETTINGS_TRAIT_POS = "trait.pos";
|
||||||
|
const FILTER_TRAIT_NAME = "traits";
|
||||||
|
const SETTINGS_IFACE_POS = "iface.pos";
|
||||||
|
const FILTER_INTERFACE_NAME = "interfaces";
|
||||||
|
const SETTINGS_CLASS_PLUGIN_POS = "class.plugin.pos";
|
||||||
|
const FILTER_CLASS_PLUGIN_NAME = "plugins";
|
||||||
|
const REGEX_PATH_NAME = "[NAME]";
|
||||||
|
private array $configSettingsSection = [];
|
||||||
|
private array $configAutoloaderSection = [];
|
||||||
|
private static ?object $_instance = null;
|
||||||
|
private string $modelFolderPath;
|
||||||
|
private string $moduleFolderPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc Singleton instance
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
$this->_set('configSettingsSection', Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS]);
|
||||||
|
$this->_set('configAutoloaderSection', Config::getInstance()->getConfig()[self::SETTINGS_SECTION]);
|
||||||
|
$this->_set('modelFolderPath', $this->_get('configSettingsSection')[self::DB_MODEL_FOLDER]);
|
||||||
|
$this->_set('moduleFolderPath', $this->_get('configSettingsSection')[self::SETTINGS_MODULE_SELECTOR]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc Singleton instance
|
||||||
|
* @return Auto
|
||||||
|
*/
|
||||||
|
public static function loader(): Auto
|
||||||
|
{
|
||||||
|
$className = get_called_class();
|
||||||
|
if( self::$_instance === null )
|
||||||
|
{
|
||||||
|
self::$_instance = new $className();
|
||||||
|
}
|
||||||
|
return self::$_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc will set a given property for this class
|
||||||
|
* @param string $name
|
||||||
|
* @param $value
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _set(string $name, $value): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$_class_properties = get_class_vars(__CLASS__);
|
||||||
|
if (array_key_exists($name, $_class_properties))
|
||||||
|
{
|
||||||
|
$this->$name = $value;
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
error_log("Exception in _set method: " . $e->getMessage());
|
||||||
|
} catch (\Error $e) {
|
||||||
|
error_log("Error in _set method: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @desc will return the value of the requested property
|
||||||
|
* @param string $name
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function _get(string $name): mixed
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$_class_properties = get_class_vars(__CLASS__);
|
||||||
|
if (array_key_exists($name, $_class_properties))
|
||||||
|
{
|
||||||
|
return $this->$name;
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
error_log("Exception in _get method: " . $e->getMessage());
|
||||||
|
} catch (\Error $e) {
|
||||||
|
error_log("Error in _get method: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc Generic method to load files based on a given path and file pattern.
|
||||||
|
* @param string $basePath The base path where the files are located.
|
||||||
|
* @param string $pattern The regex pattern to match the files.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function loadFiles(string $basePath, string $pattern = '/^.+\.php$/i')
|
||||||
|
{
|
||||||
|
$directoryIterator = new RecursiveDirectoryIterator($basePath);
|
||||||
|
$iterator = new RecursiveIteratorIterator($directoryIterator);
|
||||||
|
$phpFiles = new RegexIterator($iterator, $pattern, \RecursiveRegexIterator::GET_MATCH);
|
||||||
|
|
||||||
|
foreach ($phpFiles as $file) {
|
||||||
|
require_once $file[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc Load all PHP model files from the specified directory.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function loadModelFiles()
|
||||||
|
{
|
||||||
|
$this->loadFiles(__DIR__ . $this->_get('modelFolderPath'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $moduleName
|
||||||
|
* @param $componentType
|
||||||
|
* @param $registeredComponents
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function loadModuleComponents($moduleName, $componentType, $registeredComponents): void
|
||||||
|
{
|
||||||
|
foreach ($registeredComponents as $componentName) {
|
||||||
|
$componentBasePath = str_replace(self::REGEX_PATH_NAME, '', __DIR__ . $this->_get('moduleFolderPath')) . $moduleName;
|
||||||
|
if ($componentType === self::FILTER_TRAIT_NAME || $componentType === self::FILTER_CLASS_PLUGIN_NAME || $componentType === self::FILTER_INTERFACE_NAME)
|
||||||
|
{
|
||||||
|
$componentPath = $this->determineComponentPath($componentName, $componentBasePath, $componentType);
|
||||||
|
} else {
|
||||||
|
$componentPath = $componentBasePath . '/' . $componentType . '/' . $componentName . '.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the component if the file exists
|
||||||
|
if (file_exists($componentPath))
|
||||||
|
{
|
||||||
|
require_once $componentPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example method to determine the path for special traits and plugins
|
||||||
|
protected function determineComponentPath($componentName, $componentBasePath, $componentType)
|
||||||
|
{
|
||||||
|
// Placeholder logic to determine the correct path for traits and plugins
|
||||||
|
// You might need to implement additional logic based on your framework's structure
|
||||||
|
// For example, you might have a mapping or convention that relates component names to modules
|
||||||
|
return $componentBasePath . '/' . $componentType . '/' . $componentName . '.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load modules by utilizing the generic loadFiles method.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function loadModules(): void
|
||||||
|
{
|
||||||
|
$registeredModules = $this->_get('configAutoloaderSection')[self::SETTINGS_CLASS_POS];
|
||||||
|
$modulePath = str_replace(self::REGEX_PATH_NAME, '', __DIR__ . $this->_get('moduleFolderPath'));
|
||||||
|
|
||||||
|
foreach ($registeredModules as $moduleName) {
|
||||||
|
$moduleMainFile = $modulePath . $moduleName . '/' . $moduleName . '.php';
|
||||||
|
$this->loadModuleComponents($moduleName, self::FILTER_INTERFACE_NAME, $this->_get('configAutoloaderSection')[self::SETTINGS_IFACE_POS]);
|
||||||
|
$this->loadModuleComponents($moduleName, self::FILTER_TRAIT_NAME, $this->_get('configAutoloaderSection')[self::SETTINGS_TRAIT_POS]);
|
||||||
|
if (file_exists($moduleMainFile))
|
||||||
|
{
|
||||||
|
require_once $moduleMainFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->loadModuleComponents($moduleName, 'plugins', $this->_get('configAutoloaderSection')[self::SETTINGS_CLASS_PLUGIN_POS]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ require_once __DIR__ . '/../i/db.php';
|
|||||||
* User: kasdorf
|
* User: kasdorf
|
||||||
* Date: 10.11.17
|
* Date: 10.11.17
|
||||||
* Time: 09:44
|
* Time: 09:44
|
||||||
|
* @deprecated - this class is deprecated, use the auto autoloader instead (c/auto.php)
|
||||||
*/
|
*/
|
||||||
class Autoloader
|
class Autoloader
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Nibiru;
|
namespace Nibiru;
|
||||||
use Nibiru\Autoloader\Autoloader;
|
use Nibiru\Auto\Auto;
|
||||||
require_once __DIR__ . '/../c/autoloader.php';
|
require_once __DIR__ . '/../c/auto.php';
|
||||||
|
|
||||||
final class Dispatcher
|
final class Dispatcher
|
||||||
{
|
{
|
||||||
@@ -38,7 +38,8 @@ final class Dispatcher
|
|||||||
}
|
}
|
||||||
Router::getInstance();
|
Router::getInstance();
|
||||||
Router::getInstance()->route();
|
Router::getInstance()->route();
|
||||||
Autoloader::getInstance()->runRequireOnce();
|
Auto::loader()->loadModelFiles();
|
||||||
|
Auto::loader()->loadModules();
|
||||||
if(is_file(__DIR__ . '/../../application/controller/' . Router::getInstance()->tplName() . 'Controller.php'))
|
if(is_file(__DIR__ . '/../../application/controller/' . Router::getInstance()->tplName() . 'Controller.php'))
|
||||||
{
|
{
|
||||||
require_once __DIR__ . '/../../application/controller/' . Router::getInstance()->tplName() . 'Controller.php';
|
require_once __DIR__ . '/../../application/controller/' . Router::getInstance()->tplName() . 'Controller.php';
|
||||||
|
|||||||
@@ -1,141 +1,185 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Nibiru;
|
namespace Nibiru;
|
||||||
/**
|
/**
|
||||||
* User - stephan
|
* Class JsonNavigation
|
||||||
* Date - 24.01.17
|
* @project Nibiru
|
||||||
* Time - 15:26
|
* @desc This is a PHP class file, please specify the use
|
||||||
* @author - Stephan Kasdorf
|
* @author stephan - Nibiru Framework
|
||||||
* @category - [PLEASE SPECIFIY]
|
* @date 28.08.23
|
||||||
* @license - BSD License
|
* @time 10:30
|
||||||
|
* @package Nibiru
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class JsonNavigation extends Config
|
class JsonNavigation extends Config
|
||||||
{
|
{
|
||||||
const NAVIGATION = "navigation";
|
const NAVIGATION = "navigation";
|
||||||
|
|
||||||
private static $_navigation;
|
private static $_navigation;
|
||||||
private static $_navigation_array = array();
|
private static $_navigation_array = array();
|
||||||
private static $_instance;
|
private static $_instance;
|
||||||
private static $_file_content_string = NULL;
|
private static $_file_content_string = NULL;
|
||||||
private static $_file_content_array = array();
|
private static $_file_content_array = array();
|
||||||
private static $_name = false;
|
private static $_name = false;
|
||||||
private static $_section_name = self::NAVIGATION;
|
private static $_section_name = self::NAVIGATION;
|
||||||
|
|
||||||
public static function getInstance(): JsonNavigation
|
public static function getInstance(): JsonNavigation
|
||||||
{
|
{
|
||||||
parent::getInstance();
|
parent::getInstance();
|
||||||
self::setFileContentString();
|
self::setFileContentString();
|
||||||
self::setFileContentArray();
|
self::setFileContentArray();
|
||||||
self::setNavigation();
|
self::setNavigation();
|
||||||
$className = get_called_class();
|
$className = get_called_class();
|
||||||
if(self::$_instance==null) self::$_instance = new $className();
|
if(self::$_instance==null) self::$_instance = new $className();
|
||||||
return self::$_instance;
|
return self::$_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @desc - Will load the navigation json file to the $_navigation
|
||||||
*/
|
* @param string $filename
|
||||||
protected static function getSectionName(): string
|
* @return array
|
||||||
{
|
*/
|
||||||
return self::$_section_name;
|
public function loadNavigationRecursively(string $filename): array
|
||||||
}
|
{
|
||||||
|
$content = file_get_contents($filename);
|
||||||
|
|
||||||
/**
|
// Check if file_get_contents was successful
|
||||||
* @param string $section_name
|
if ($content === false)
|
||||||
*/
|
{
|
||||||
private static function setSectionName( string $section_name )
|
throw new \Exception("Failed to read the file: {$filename}");
|
||||||
{
|
}
|
||||||
self::$_section_name = $section_name;
|
|
||||||
}
|
$navArray = json_decode($content, true);
|
||||||
|
|
||||||
|
// Check if json_decode was successful and returned an array
|
||||||
|
if (!is_array($navArray))
|
||||||
|
{
|
||||||
|
throw new \Exception("Failed to decode JSON from the file: {$filename}");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($navArray as &$item)
|
||||||
|
{
|
||||||
|
if (isset($item['subNav']))
|
||||||
|
{
|
||||||
|
$item['children'] = $this->loadNavigationRecursively(Settings::SETTINGS_PATH . self::NAVIGATION . $item['subNav']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $navArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc - Will load the navigation json file to the $_navigation
|
||||||
|
* @param string $navigation
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function loadCompleteNavigation( string $navigation = self::NAVIGATION ): array
|
||||||
|
{
|
||||||
|
$mainNavFilename = Settings::SETTINGS_PATH . parent::getInstance()->getConfig()["SETTINGS"][$navigation];
|
||||||
|
return $this->loadNavigationRecursively($mainNavFilename);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected static function getName(): string
|
protected static function getSectionName(): string
|
||||||
{
|
{
|
||||||
return self::$_name;
|
return self::$_section_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $section_name
|
||||||
|
*/
|
||||||
|
private static function setSectionName( string $section_name )
|
||||||
|
{
|
||||||
|
self::$_section_name = $section_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function getName(): string
|
||||||
|
{
|
||||||
|
return self::$_name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
*/
|
*/
|
||||||
private static function setName( string $name )
|
private static function setName( string $name )
|
||||||
{
|
{
|
||||||
self::$_name = $name;
|
self::$_name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
protected static function getFileContentString( )
|
protected static function getFileContentString( )
|
||||||
{
|
{
|
||||||
return self::$_file_content_string;
|
return self::$_file_content_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content String
|
* Content String
|
||||||
*/
|
*/
|
||||||
private static function setFileContentString( )
|
private static function setFileContentString( )
|
||||||
{
|
{
|
||||||
self::$_file_content_string = file_get_contents( Settings::SETTINGS_PATH . parent::getInstance()->getConfig()["SETTINGS"][self::getSectionName()] );
|
self::$_file_content_string = file_get_contents( Settings::SETTINGS_PATH . parent::getInstance()->getConfig()["SETTINGS"][self::getSectionName()] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected static function getFileContentArray( ): array
|
protected static function getFileContentArray( ): array
|
||||||
{
|
{
|
||||||
return self::$_file_content_array;
|
return self::$_file_content_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* will set the file Content array
|
* will set the file Content array
|
||||||
*/
|
*/
|
||||||
private static function setFileContentArray( )
|
private static function setFileContentArray( )
|
||||||
{
|
{
|
||||||
self::$_file_content_array = file( Settings::SETTINGS_PATH . parent::getInstance()->getConfig()["SETTINGS"][self::getSectionName()] );
|
self::$_file_content_array = file( Settings::SETTINGS_PATH . parent::getInstance()->getConfig()["SETTINGS"][self::getSectionName()] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \RecursiveIteratorIterator
|
* @return \RecursiveIteratorIterator
|
||||||
*/
|
*/
|
||||||
protected static function getNavigation( ): \RecursiveIteratorIterator
|
protected static function getNavigation( ): \RecursiveIteratorIterator
|
||||||
{
|
{
|
||||||
return self::$_navigation;
|
return self::$_navigation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will load the navigation json file to the $_navigation
|
* Will load the navigation json file to the $_navigation
|
||||||
* variable
|
* variable
|
||||||
*/
|
*/
|
||||||
private static function setNavigation( )
|
private static function setNavigation( )
|
||||||
{
|
{
|
||||||
self::$_navigation = new \RecursiveIteratorIterator(
|
self::$_navigation = new \RecursiveIteratorIterator(
|
||||||
new \RecursiveArrayIterator(
|
new \RecursiveArrayIterator(
|
||||||
json_decode( self::getFileContentString() , TRUE )
|
json_decode( self::getFileContentString() , TRUE )
|
||||||
), \RecursiveIteratorIterator::SELF_FIRST
|
), \RecursiveIteratorIterator::SELF_FIRST
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the content of the file line by line on the
|
* Displays the content of the file line by line on the
|
||||||
* screen if it is in json format
|
* screen if it is in json format
|
||||||
*/
|
*/
|
||||||
public function displayRawJsonNavigation( )
|
public function displayRawJsonNavigation( )
|
||||||
{
|
{
|
||||||
foreach (self::getNavigation() as $key => $val)
|
foreach (self::getNavigation() as $key => $val)
|
||||||
{
|
{
|
||||||
if(is_array($val))
|
if(is_array($val))
|
||||||
{
|
{
|
||||||
echo "$key:<br>\n";
|
echo "$key:<br>\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo "$key => $val<br>\n";
|
echo "$key => $val<br>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the navigation from a json file into
|
* Loads the navigation from a json file into
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace Nibiru;
|
|||||||
* @category - [PLEASE SPECIFIY]
|
* @category - [PLEASE SPECIFIY]
|
||||||
* @license - BSD License
|
* @license - BSD License
|
||||||
*/
|
*/
|
||||||
use Nibiru\Autoloader\Autoloader;
|
use Nibiru\Auto\Auto;
|
||||||
|
|
||||||
final class Registry
|
final class Registry
|
||||||
{
|
{
|
||||||
@@ -47,7 +47,7 @@ final class Registry
|
|||||||
*/
|
*/
|
||||||
private function _setModulesPath( ): void
|
private function _setModulesPath( ): void
|
||||||
{
|
{
|
||||||
$this->_modules_path = __DIR__ . str_replace(Autoloader::REGEX_PATH_NAME, '', Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::CONFIG_MODULE_KEY]);
|
$this->_modules_path = __DIR__ . str_replace(Auto::REGEX_PATH_NAME, '', Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::CONFIG_MODULE_KEY]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,7 +114,7 @@ final class Registry
|
|||||||
*/
|
*/
|
||||||
private function loadModuleRegistry(): void
|
private function loadModuleRegistry(): void
|
||||||
{
|
{
|
||||||
foreach(Config::getInstance()->getConfig()[Autoloader::SETTINGS_SECTION][Autoloader::SETTINGS_CLASS_POS] as $module)
|
foreach(Config::getInstance()->getConfig()[Auto::SETTINGS_SECTION][Auto::SETTINGS_CLASS_POS] as $module)
|
||||||
{
|
{
|
||||||
$this->_setModuleName($module);
|
$this->_setModuleName($module);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ namespace Nibiru\Adapter;
|
|||||||
*/
|
*/
|
||||||
interface IVersion
|
interface IVersion
|
||||||
{
|
{
|
||||||
const NIBIRU_VERSION = "0.9.7";
|
const NIBIRU_VERSION = "1.0.0";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user