From c5318a2e99ece72483ed17f5bfb686b9cfbad187 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 29 Apr 2015 17:18:33 +0200 Subject: [PATCH] Added new namespaces as described in Issue #37. The following namespaces are used: \FuzeWorks for Core classes \Controller for controller classes \Model for model classes \Module for modules Also did the following changes: - DatabaseModel now loads the database module as a dependency - DatabaseModel is no longer abstract because of ModelServer - Implemented a new mechanism for model types in the name of a ModelServer. This interface requires a Model Type Server to return a Model parent class based on a given type - Added a backtrace to the logger class for easy and fast debugging And that was it for this commit --- .../Controller/controller.standard.php | 3 +++ Application/Models/model.example.php | 3 +++ Core/Events/event.controllerLoadEvent.php | 2 ++ Core/Events/event.layoutLoadEvent.php | 2 ++ Core/Events/event.modelLoadEvent.php | 2 ++ Core/Events/event.routerRouteEvent.php | 2 ++ Core/System/class.abstract.bus.php | 2 ++ Core/System/class.abstract.event.php | 2 ++ Core/System/class.abstract.eventPriority.php | 2 ++ Core/System/class.abstract.model.php | 18 ++++++++++++---- Core/System/class.abstract.module.php | 2 ++ Core/System/class.config.php | 3 +++ Core/System/class.core.php | 10 ++++++++- Core/System/class.events.php | 9 +++++--- Core/System/class.layout.php | 3 +++ Core/System/class.logger.php | 21 +++++++++++++++++++ Core/System/class.models.php | 4 +++- Modules/database/class.database.php | 6 +++++- Modules/databasemodel/class.model.php | 14 +++++++++++-- Modules/databasemodel/moduleInfo.php | 7 +++++-- Modules/router/class.router.php | 6 ++++-- Modules/sections/class.sections.php | 4 ++-- Modules/sections/moduleInfo.php | 2 ++ index.php | 2 +- 24 files changed, 112 insertions(+), 19 deletions(-) diff --git a/Application/Controller/controller.standard.php b/Application/Controller/controller.standard.php index 644309c..a17d212 100644 --- a/Application/Controller/controller.standard.php +++ b/Application/Controller/controller.standard.php @@ -1,5 +1,8 @@ core->loadMod($module_name); - $this->parentClass = new $class_name($this->core); + protected function setType($module_name, $model_type) { + $mod = $this->core->loadMod($module_name); + $this->parentClass = $mod->giveModel($model_type); } /** diff --git a/Core/System/class.abstract.module.php b/Core/System/class.abstract.module.php index 0003a7c..fa1550c 100644 --- a/Core/System/class.abstract.module.php +++ b/Core/System/class.abstract.module.php @@ -1,5 +1,7 @@ setModulePath($cfg->directory); } if (method_exists($CLASS, 'setModuleLinkName')) { - $CLASS->setModuleLinkName($cfg->name); + $CLASS->setModuleLinkName(strtolower($cfg->module_name)); } if (method_exists($CLASS, 'setModuleName')) { $CLASS->setModuleName($name); } + + if (!method_exists($CLASS, 'onLoad')) { + throw new Exception("Module '".$name."' does not have an onLoad() method! Invalid module", 1); + } $CLASS->onLoad(); // Add to the loaded modules diff --git a/Core/System/class.events.php b/Core/System/class.events.php index e3a98be..53bd4ba 100644 --- a/Core/System/class.events.php +++ b/Core/System/class.events.php @@ -3,7 +3,10 @@ * @author FuzeNetwork * @package files */ - + +namespace FuzeWorks; +use \Exception; + /** * @name Events */ @@ -84,10 +87,10 @@ class Events extends Bus{ // No event arguments? Looks like an notify-event if(func_num_args() == 1){ // Load notify-event-class - $eventClass = 'NotifierEvent'; + $eventClass = '\FuzeWorks\NotifierEvent'; }else{ // No notify-event: we tried all we could - throw new \Exception("Event ".$eventName." could not be found!"); + throw new Exception("Event ".$eventName." could not be found!"); } } } diff --git a/Core/System/class.layout.php b/Core/System/class.layout.php index f6aeb89..0539d6e 100644 --- a/Core/System/class.layout.php +++ b/Core/System/class.layout.php @@ -1,5 +1,8 @@ getTraceAsString()); + // reverse array to make steps line up chronologically + $trace = array_reverse($trace); + array_shift($trace); // remove {main} + array_pop($trace); // remove call to this method + $length = count($trace); + $result = array(); + + for ($i = 0; $i < $length; $i++) + { + $result[] = ($i + 1) . ')' . substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering + } + + return "\t" . implode("
", $result); + } + /* =========================================LOGGING METHODS==============================================================*/ diff --git a/Core/System/class.models.php b/Core/System/class.models.php index 1e4b574..0386e00 100644 --- a/Core/System/class.models.php +++ b/Core/System/class.models.php @@ -3,6 +3,8 @@ * @author FuzeNetwork */ +namespace FuzeWorks; + class Models extends Bus{ private $models_array = array(); @@ -25,7 +27,7 @@ class Models extends Bus{ $this->models_array[$name] = $this->model_types[$name]; } elseif (file_exists($file)){ require_once($file); - $model = ucfirst($name); + $model = "\Model\\" . ucfirst($name); $this->logger->logInfo('Loading Model: '.$model, $model); $this->models_array[$name] = new $model($this->core); } else{ diff --git a/Modules/database/class.database.php b/Modules/database/class.database.php index c7cacd3..5e077a3 100644 --- a/Modules/database/class.database.php +++ b/Modules/database/class.database.php @@ -1,6 +1,10 @@ core->loadMod('database'); + } + + public function onLoad() {} + + public function giveModel($type) { + return new DatabaseModel($this->core); } public function select(){ diff --git a/Modules/databasemodel/moduleInfo.php b/Modules/databasemodel/moduleInfo.php index aafc5dc..f4c85d6 100644 --- a/Modules/databasemodel/moduleInfo.php +++ b/Modules/databasemodel/moduleInfo.php @@ -1,11 +1,12 @@ 'DatabaseModel', + 'module_class' => 'Module\DatabaseModel', 'module_file' => 'class.model.php', 'module_name' => 'databasemodel', - 'abstract' => true, + 'abstract' => false, + 'dependencies' => array('database'), 'name' => 'DatabaseModel', 'description' => 'Abstract type for easy database queries', @@ -15,4 +16,6 @@ return array( 'date_created' => '26-02-2015', 'date_updated' => '26-02-2015', + + 'enabled' => true, ); diff --git a/Modules/router/class.router.php b/Modules/router/class.router.php index e7208d5..bf5e37d 100644 --- a/Modules/router/class.router.php +++ b/Modules/router/class.router.php @@ -1,6 +1,8 @@ controllerName))) require_once($file); - $this->controllerClass = ucfirst($this->controllerName); + $this->controllerClass = "\Controller\\" . ucfirst($this->controllerName); $this->controller = new $this->controllerClass($this->core); if (method_exists($this->controller, $this->function) || method_exists($this->controller, '__call')) { diff --git a/Modules/sections/class.sections.php b/Modules/sections/class.sections.php index 9be87b5..d5f99a1 100644 --- a/Modules/sections/class.sections.php +++ b/Modules/sections/class.sections.php @@ -1,8 +1,8 @@ '29-04-2015', 'date_updated' => '29-04-2015', + + 'enabled' => true, ); diff --git a/index.php b/index.php index 5d28680..a6c445f 100644 --- a/index.php +++ b/index.php @@ -7,7 +7,7 @@ if (!defined('FUZEPATH')) { require_once( dirname(__FILE__) . "/Core/System/class.core.php"); // Load it -$core = new Core(); +$core = new \FuzeWorks\Core(); $core->init(); $core->loadMod('router'); $core->mods->router->setPath( (isset($_GET['path']) ? $_GET['path'] : null) );