Skip to content

Commit

Permalink
Merge pull request #4 from alllinux/v0.9.4
Browse files Browse the repository at this point in the history
V0.9.4
  • Loading branch information
alllinux authored Nov 11, 2019
2 parents aaf4ae3 + 7c36f12 commit b3d34d4
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 26 deletions.
1 change: 1 addition & 0 deletions application/controller/controllerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public function pageAction()
View::assign([
'name' => 'rapid prototyping framework',
'title' => 'Nibiru Controller Example',
'ndbraw_output' => print_r(Registry::getInstance()->loadModuleConfigByName('users'), true),
'css' => Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS]["smarty.css"],
'js' => Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS]["smarty.js"]
]);
Expand Down
3 changes: 3 additions & 0 deletions application/module/users/settings/users.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[USERS]
name = "users"
path = "/application/module/users"
4 changes: 2 additions & 2 deletions application/settings/config/settings.development.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ debug_template = "/../../application/view/templates/shared/debug.tpl"
debugbar = true

[AUTOLOADER]
class.pos[] = "users"
trait.pos[] = "users"
iface.pos[] = "users"
trait.pos[] = "users"
class.pos[] = "users"

[EMAIL]
register.smtp = 1
Expand Down
2 changes: 2 additions & 0 deletions application/view/templates/shared/debugbar.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@
<p>
<!-- Smarty $raw output -->
{if isset($ndbraw_output)}
<pre>
{$ndbraw_output}
</pre>
{else}
{$message}
{/if}
Expand Down
99 changes: 75 additions & 24 deletions core/c/autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
class Autoloader
{
const MY_FILE_NAME = "autoloader.php";
const PHP_FILE_EXTENSION = ".php";
const DB_MODEL_FOLDER = "dbmodel";
const MODULES = [
'module',
'interfaces',
'traits'
];
const MODULE_FOLDER = "module";
const INTERFACE_FOLDER = "interfaces";
const TRAIT_FOLDER = "traits";
const SETTINGS_SECTION = "AUTOLOADER";
const SETTINGS_CLASS_POS = "class.pos";
const SETTINGS_TRAIT_POS = "trait.pos";
Expand All @@ -32,7 +31,7 @@ class Autoloader

protected function __construct()
{
self::_setFilesInFoler();
self::_setFilesInFolder();
}

public static function getInstance()
Expand Down Expand Up @@ -67,11 +66,10 @@ public static function debug( bool $debug ): void
* @param mixed $section
* @return array
*/
private static function sortOrderModules( array $modules, $section ): array
private static function sortOrderModules( array $modules, $section ): ?array
{
(bool) $skip = false;
(array) $normal = array();

if($section == self::SETTINGS_CLASS_POS)
{
$moduleSortOrder = Config::getInstance()->getConfig()[self::SETTINGS_SECTION][self::SETTINGS_CLASS_POS];
Expand Down Expand Up @@ -163,28 +161,29 @@ protected static function getModules(): array

/**
* @param string $folderPath
* @param string $moduleName
* @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];
foreach($folderSettings as $moduleFolderName)
if(strstr($folderPath, self::REGEX_PATH_NAME) && $moduleName!="")
{
$folderPath = str_replace(self::REGEX_PATH_NAME, $moduleFolderName, $folderPath);
$folderPath = str_replace(self::REGEX_PATH_NAME, $moduleName, $folderPath);
}
return new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator( $folderPath ));
}

/**
* @param array $filesInFoler
*/
private static function _setFilesInFoler( )
private static function _setFilesInFolder( )
{
/**
* @desc arrays for sorting the module order, so they will load
* alphabetically
*/
$modules = array();
self::$_filesInFoler = array();

if( is_array( Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::DB_MODEL_FOLDER] ) )
{
Expand All @@ -193,7 +192,7 @@ private static function _setFilesInFoler( )
$iterator = self::folderContent( __DIR__ . $modelfolder );
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();
}
Expand All @@ -205,33 +204,85 @@ private static function _setFilesInFoler( )
$iterator = self::folderContent(__DIR__ . Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::DB_MODEL_FOLDER] );
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();
}
}
}
/**
* @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 )
{
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()),
'filepathname' => $item->getPath() . '/' . $item->getFileName()
);
}
}
asort($moduleFolder);
$itms = self::sortOrderModules($moduleFolder, self::SETTINGS_IFACE_POS);
foreach ($itms as $itm)
asort($traits);
$Straits = self::sortOrderModules($traits, self::SETTINGS_TRAIT_POS);
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'];
}
}
}
}
Expand Down
119 changes: 119 additions & 0 deletions core/c/registry.php
Original file line number Diff line number Diff line change
@@ -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];
}
}
1 change: 1 addition & 0 deletions core/framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require_once __DIR__ . '/t/pageination.php';
require_once __DIR__ . '/c/settings.php';
require_once __DIR__ . '/c/config.php';
require_once __DIR__ . '/c/registry.php';
require_once __DIR__ . '/c/router.php';
require_once __DIR__ . '/i/engine.php';
require_once __DIR__ . '/c/engine.php';
Expand Down

0 comments on commit b3d34d4

Please sign in to comment.