REFACTORING: updated the autoloader, currently a duplicate section has to be refactored. Added a Registry for the settings section of every module.
This commit is contained in:
@@ -10,6 +10,7 @@ class controllerController extends Controller
|
|||||||
View::assign([
|
View::assign([
|
||||||
'name' => 'rapid prototyping framework',
|
'name' => 'rapid prototyping framework',
|
||||||
'title' => 'Nibiru Controller Example',
|
'title' => 'Nibiru Controller Example',
|
||||||
|
'ndbraw_output' => print_r(Registry::getInstance()->loadModuleConfigByName('users'), true),
|
||||||
'css' => Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS]["smarty.css"],
|
'css' => Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS]["smarty.css"],
|
||||||
'js' => Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS]["smarty.js"]
|
'js' => Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS]["smarty.js"]
|
||||||
]);
|
]);
|
||||||
|
|||||||
3
application/module/users/settings/users.ini
Normal file
3
application/module/users/settings/users.ini
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[USERS]
|
||||||
|
name = "users"
|
||||||
|
path = "/application/module/users"
|
||||||
@@ -7,9 +7,12 @@ debug_template = "/../../application/view/templates/shared/debug.tpl"
|
|||||||
debugbar = true
|
debugbar = true
|
||||||
|
|
||||||
[AUTOLOADER]
|
[AUTOLOADER]
|
||||||
class.pos[] = "users"
|
iface.pos[] = "register"
|
||||||
trait.pos[] = "users"
|
|
||||||
iface.pos[] = "users"
|
iface.pos[] = "users"
|
||||||
|
trait.pos[] = "register"
|
||||||
|
trait.pos[] = "users"
|
||||||
|
class.pos[] = "register"
|
||||||
|
class.pos[] = "users"
|
||||||
|
|
||||||
[EMAIL]
|
[EMAIL]
|
||||||
register.smtp = 1
|
register.smtp = 1
|
||||||
|
|||||||
@@ -121,7 +121,9 @@
|
|||||||
<p>
|
<p>
|
||||||
<!-- Smarty $raw output -->
|
<!-- Smarty $raw output -->
|
||||||
{if isset($ndbraw_output)}
|
{if isset($ndbraw_output)}
|
||||||
|
<pre>
|
||||||
{$ndbraw_output}
|
{$ndbraw_output}
|
||||||
|
</pre>
|
||||||
{else}
|
{else}
|
||||||
{$message}
|
{$message}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -13,12 +13,11 @@ require_once __DIR__ . '/../i/db.php';
|
|||||||
class Autoloader
|
class Autoloader
|
||||||
{
|
{
|
||||||
const MY_FILE_NAME = "autoloader.php";
|
const MY_FILE_NAME = "autoloader.php";
|
||||||
|
const PHP_FILE_EXTENSION = ".php";
|
||||||
const DB_MODEL_FOLDER = "dbmodel";
|
const DB_MODEL_FOLDER = "dbmodel";
|
||||||
const MODULES = [
|
const MODULE_FOLDER = "module";
|
||||||
'module',
|
const INTERFACE_FOLDER = "interfaces";
|
||||||
'interfaces',
|
const TRAIT_FOLDER = "traits";
|
||||||
'traits'
|
|
||||||
];
|
|
||||||
const SETTINGS_SECTION = "AUTOLOADER";
|
const SETTINGS_SECTION = "AUTOLOADER";
|
||||||
const SETTINGS_CLASS_POS = "class.pos";
|
const SETTINGS_CLASS_POS = "class.pos";
|
||||||
const SETTINGS_TRAIT_POS = "trait.pos";
|
const SETTINGS_TRAIT_POS = "trait.pos";
|
||||||
@@ -32,7 +31,7 @@ class Autoloader
|
|||||||
|
|
||||||
protected function __construct()
|
protected function __construct()
|
||||||
{
|
{
|
||||||
self::_setFilesInFoler();
|
self::_setFilesInFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
@@ -67,11 +66,10 @@ class Autoloader
|
|||||||
* @param mixed $section
|
* @param mixed $section
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private static function sortOrderModules( array $modules, $section ): array
|
private static function sortOrderModules( array $modules, $section ): ?array
|
||||||
{
|
{
|
||||||
(bool) $skip = false;
|
(bool) $skip = false;
|
||||||
(array) $normal = array();
|
(array) $normal = array();
|
||||||
|
|
||||||
if($section == self::SETTINGS_CLASS_POS)
|
if($section == self::SETTINGS_CLASS_POS)
|
||||||
{
|
{
|
||||||
$moduleSortOrder = Config::getInstance()->getConfig()[self::SETTINGS_SECTION][self::SETTINGS_CLASS_POS];
|
$moduleSortOrder = Config::getInstance()->getConfig()[self::SETTINGS_SECTION][self::SETTINGS_CLASS_POS];
|
||||||
@@ -163,14 +161,14 @@ class Autoloader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $folderPath
|
* @param string $folderPath
|
||||||
|
* @param string $moduleName
|
||||||
* @return \RecursiveIteratorIterator
|
* @return \RecursiveIteratorIterator
|
||||||
*/
|
*/
|
||||||
private static function folderContent( string $folderPath ): \RecursiveIteratorIterator
|
private static function folderContent( string $folderPath, string $moduleName = '' ): \RecursiveIteratorIterator
|
||||||
{
|
{
|
||||||
$folderSettings = Config::getInstance()->getConfig()[self::SETTINGS_SECTION][self::SETTINGS_CLASS_POS];
|
if(strstr($folderPath, self::REGEX_PATH_NAME) && $moduleName!="")
|
||||||
foreach($folderSettings as $moduleFolderName)
|
|
||||||
{
|
{
|
||||||
$folderPath = str_replace(self::REGEX_PATH_NAME, $moduleFolderName, $folderPath);
|
$folderPath = str_replace(self::REGEX_PATH_NAME, $moduleName, $folderPath);
|
||||||
}
|
}
|
||||||
return new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator( $folderPath ));
|
return new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator( $folderPath ));
|
||||||
}
|
}
|
||||||
@@ -178,13 +176,14 @@ class Autoloader
|
|||||||
/**
|
/**
|
||||||
* @param array $filesInFoler
|
* @param array $filesInFoler
|
||||||
*/
|
*/
|
||||||
private static function _setFilesInFoler( )
|
private static function _setFilesInFolder( )
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @desc arrays for sorting the module order, so they will load
|
* @desc arrays for sorting the module order, so they will load
|
||||||
* alphabetically
|
* alphabetically
|
||||||
*/
|
*/
|
||||||
$modules = array();
|
$modules = array();
|
||||||
|
self::$_filesInFoler = array();
|
||||||
|
|
||||||
if( is_array( Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::DB_MODEL_FOLDER] ) )
|
if( is_array( Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::DB_MODEL_FOLDER] ) )
|
||||||
{
|
{
|
||||||
@@ -193,7 +192,7 @@ class Autoloader
|
|||||||
$iterator = self::folderContent( __DIR__ . $modelfolder );
|
$iterator = self::folderContent( __DIR__ . $modelfolder );
|
||||||
foreach ( $iterator as $item )
|
foreach ( $iterator as $item )
|
||||||
{
|
{
|
||||||
if($item->getFileName()!= self::MY_FILE_NAME && $item->getFileName()!="." && $item->getFileName()!="..")
|
if($item->getFileName()!= self::MY_FILE_NAME && $item->getFileName()!="." && $item->getFileName()!=".." && strstr($item->getFileName(), self::PHP_FILE_EXTENSION))
|
||||||
{
|
{
|
||||||
self::$_filesInFoler[] = $item->getPathName();
|
self::$_filesInFoler[] = $item->getPathName();
|
||||||
}
|
}
|
||||||
@@ -205,33 +204,85 @@ class Autoloader
|
|||||||
$iterator = self::folderContent(__DIR__ . Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::DB_MODEL_FOLDER] );
|
$iterator = self::folderContent(__DIR__ . Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::DB_MODEL_FOLDER] );
|
||||||
foreach ( $iterator as $item )
|
foreach ( $iterator as $item )
|
||||||
{
|
{
|
||||||
if($item->getFileName()!= self::MY_FILE_NAME && $item->getFileName()!="." && $item->getFileName()!="..")
|
if($item->getFileName()!= self::MY_FILE_NAME && $item->getFileName()!="." && $item->getFileName()!=".." && strstr($item->getFileName(), self::PHP_FILE_EXTENSION))
|
||||||
{
|
{
|
||||||
self::$_filesInFoler[] = $item->getPathName();
|
self::$_filesInFoler[] = $item->getPathName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @desc run check on modules that should provide an interface as well as a trait
|
* TODO: refactor this section
|
||||||
*/
|
*/
|
||||||
foreach(self::MODULES as $module)
|
$moduleInterfaceNames = Config::getInstance()->getConfig()[self::SETTINGS_SECTION][self::SETTINGS_IFACE_POS];
|
||||||
|
foreach($moduleInterfaceNames as $interfaceName)
|
||||||
{
|
{
|
||||||
$iterator = self::folderContent(__DIR__ . Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][$module] );
|
$iterator = self::folderContent(__DIR__ . Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::INTERFACE_FOLDER], $interfaceName);
|
||||||
|
foreach ($iterator as $item)
|
||||||
|
{
|
||||||
|
if($item->getFileName() != self::MY_FILE_NAME && $item->getFileName() != "." && $item->getFileName() != ".." && strstr($item->getFileName(), self::PHP_FILE_EXTENSION))
|
||||||
|
{
|
||||||
|
$interfaces[] = array(
|
||||||
|
'nfilename' => str_replace('.php', '', $item->getFileName()),
|
||||||
|
'filepathname' => $item->getPath() . '/' . $item->getFileName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
asort($interfaces);
|
||||||
|
$Sinterfaces = self::sortOrderModules($interfaces, self::SETTINGS_IFACE_POS);
|
||||||
|
foreach ($Sinterfaces as $interface)
|
||||||
|
{
|
||||||
|
if(!in_array($interface['filepathname'], self::$_filesInFoler))
|
||||||
|
{
|
||||||
|
self::$_filesInFoler[] = $interface['filepathname'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$modulesTraitsNames = Config::getInstance()->getConfig()[self::SETTINGS_SECTION][self::SETTINGS_TRAIT_POS];
|
||||||
|
foreach($modulesTraitsNames as $traitsName)
|
||||||
|
{
|
||||||
|
$iterator = self::folderContent(__DIR__ . Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::TRAIT_FOLDER], $traitsName );
|
||||||
foreach ( $iterator as $item )
|
foreach ( $iterator as $item )
|
||||||
{
|
{
|
||||||
if($item->getFileName()!= self::MY_FILE_NAME && $item->getFileName()!="." && $item->getFileName()!="..")
|
if($item->getFileName()!= self::MY_FILE_NAME && $item->getFileName()!="." && $item->getFileName()!=".." && strstr($item->getFileName(), self::PHP_FILE_EXTENSION))
|
||||||
{
|
{
|
||||||
$moduleFolder[] = array(
|
$traits[] = array(
|
||||||
'nfilename' => str_replace('.php', '', $item->getFileName()),
|
'nfilename' => str_replace('.php', '', $item->getFileName()),
|
||||||
'filepathname' => $item->getPath() . '/' . $item->getFileName()
|
'filepathname' => $item->getPath() . '/' . $item->getFileName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
asort($moduleFolder);
|
asort($traits);
|
||||||
$itms = self::sortOrderModules($moduleFolder, self::SETTINGS_IFACE_POS);
|
$Straits = self::sortOrderModules($traits, self::SETTINGS_TRAIT_POS);
|
||||||
foreach ($itms as $itm)
|
foreach($Straits as $trait)
|
||||||
{
|
{
|
||||||
self::$_filesInFoler[] = $itm['filepathname'];
|
if(!in_array($trait['filepathname'], self::$_filesInFoler))
|
||||||
|
{
|
||||||
|
self::$_filesInFoler[] = $trait['filepathname'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$modulesClassNames = Config::getInstance()->getConfig()[self::SETTINGS_SECTION][self::SETTINGS_CLASS_POS];
|
||||||
|
foreach($modulesClassNames as $className)
|
||||||
|
{
|
||||||
|
$iterator = self::folderContent(__DIR__ . Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::MODULE_FOLDER], $className );
|
||||||
|
foreach ( $iterator as $item )
|
||||||
|
{
|
||||||
|
if($item->getFileName()!= self::MY_FILE_NAME && $item->getFileName()!="." && $item->getFileName()!=".." && strstr($item->getFileName(), self::PHP_FILE_EXTENSION))
|
||||||
|
{
|
||||||
|
$modules[] = array(
|
||||||
|
'nfilename' => str_replace('.php', '', $item->getFileName()),
|
||||||
|
'filepathname' => $item->getPath() . '/' . $item->getFileName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
asort($modules);
|
||||||
|
$Smodules = self::sortOrderModules($modules, self::SETTINGS_CLASS_POS);
|
||||||
|
foreach($Smodules as $smodule)
|
||||||
|
{
|
||||||
|
if(!in_array($smodule['filepathname'], self::$_filesInFoler))
|
||||||
|
{
|
||||||
|
self::$_filesInFoler[] = $smodule['filepathname'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
119
core/c/registry.php
Normal file
119
core/c/registry.php
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
namespace Nibiru;
|
||||||
|
/**
|
||||||
|
* User - stephan
|
||||||
|
* Date - 11.11.19
|
||||||
|
* Time - 17:20
|
||||||
|
* @author - alllinux.de GbR
|
||||||
|
* @category - [PLEASE SPECIFIY]
|
||||||
|
* @license - BSD License
|
||||||
|
*/
|
||||||
|
use Nibiru\Autoloader\Autoloader;
|
||||||
|
|
||||||
|
final class Registry
|
||||||
|
{
|
||||||
|
const CONFIG_MODULE_KEY = 'module';
|
||||||
|
const CONFIG_SETTINGS_KEY = 'settings';
|
||||||
|
|
||||||
|
private $_modules_config = array();
|
||||||
|
private $_module_name = '';
|
||||||
|
private $_modules_path = '';
|
||||||
|
|
||||||
|
private static $_instance;
|
||||||
|
|
||||||
|
protected function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInstance(): Registry
|
||||||
|
{
|
||||||
|
$className = get_called_class();
|
||||||
|
if(self::$_instance==null) self::$_instance = new $className();
|
||||||
|
self::$_instance->loadModuleRegistry();
|
||||||
|
return self::$_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getModulesPath(): string
|
||||||
|
{
|
||||||
|
return $this->_modules_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the path to the modules
|
||||||
|
*/
|
||||||
|
private function _setModulesPath( ): void
|
||||||
|
{
|
||||||
|
$this->_modules_path = __DIR__ . str_replace(Autoloader::REGEX_PATH_NAME, '', Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::CONFIG_MODULE_KEY]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getModulesConfig(): array
|
||||||
|
{
|
||||||
|
return $this->_modules_config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the modules configuration by module name
|
||||||
|
*/
|
||||||
|
private function _setModulesConfig( ): void
|
||||||
|
{
|
||||||
|
$modules_setting_path = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getModulesPath()));
|
||||||
|
foreach($modules_setting_path as $settings)
|
||||||
|
{
|
||||||
|
if(strstr($settings->getPathName(), self::CONFIG_SETTINGS_KEY) && $settings->getFileName()!='.' && $settings->getFileName()!='..')
|
||||||
|
{
|
||||||
|
$module = new \stdClass();
|
||||||
|
$module_settings = parse_ini_file($settings->getPathName(), true);
|
||||||
|
foreach ( $module_settings[strtoupper($this->getModuleName())] as $key=>$value)
|
||||||
|
{
|
||||||
|
$module->$key = $value;
|
||||||
|
}
|
||||||
|
$this->_modules_config[$this->getModuleName()] = $module;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getModuleName(): string
|
||||||
|
{
|
||||||
|
return $this->_module_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $module_name
|
||||||
|
*/
|
||||||
|
private function _setModuleName(string $module_name): void
|
||||||
|
{
|
||||||
|
$this->_module_name = $module_name;
|
||||||
|
$this->_setModulesPath();
|
||||||
|
$this->_setModulesConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function loadModuleRegistry(): void
|
||||||
|
{
|
||||||
|
foreach(Config::getInstance()->getConfig()[Autoloader::SETTINGS_SECTION][Autoloader::SETTINGS_CLASS_POS] as $module)
|
||||||
|
{
|
||||||
|
$this->_setModuleName($module);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $module_name
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
public function loadModuleConfigByName(string $module_name): object
|
||||||
|
{
|
||||||
|
return $this->getModulesConfig()[$module_name];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ require_once __DIR__ . '/t/messages.php';
|
|||||||
require_once __DIR__ . '/t/pageination.php';
|
require_once __DIR__ . '/t/pageination.php';
|
||||||
require_once __DIR__ . '/c/settings.php';
|
require_once __DIR__ . '/c/settings.php';
|
||||||
require_once __DIR__ . '/c/config.php';
|
require_once __DIR__ . '/c/config.php';
|
||||||
|
require_once __DIR__ . '/c/registry.php';
|
||||||
require_once __DIR__ . '/c/router.php';
|
require_once __DIR__ . '/c/router.php';
|
||||||
require_once __DIR__ . '/i/engine.php';
|
require_once __DIR__ . '/i/engine.php';
|
||||||
require_once __DIR__ . '/c/engine.php';
|
require_once __DIR__ . '/c/engine.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user