Implemented the ability to disable core modules.
Using the config.core.php, you can choose what modules should run in FuzeWorks
This commit is contained in:
parent
b2aea986c3
commit
338d0d2a43
|
@ -0,0 +1,9 @@
|
|||
<?php return array (
|
||||
'enable_events' => true,
|
||||
'enable_logger' => true,
|
||||
'enable_models' => true,
|
||||
'enable_layout' => true,
|
||||
'enable_router' => true,
|
||||
'enable_modules' => true
|
||||
|
||||
) ;
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Catcher Class
|
||||
*
|
||||
* This class catches requests and returns nothing. Handy for a temporary replacement object
|
||||
*/
|
||||
class Catcher extends Bus{
|
||||
|
||||
public function __construct(&$core) {
|
||||
parent::__construct($core);
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
return new Catcher($this->core);
|
||||
}
|
||||
|
||||
public function __set($name, $value) {}
|
||||
|
||||
public function __unset($name) {}
|
||||
|
||||
public function __isset($name) {}
|
||||
|
||||
public function __call($name, $params) {
|
||||
return new Catcher($this->core);
|
||||
}
|
||||
|
||||
public static function __callStatic($name, $params) {}
|
||||
|
||||
public function __sleep() {}
|
||||
|
||||
public function __wakeup() {}
|
||||
|
||||
public function __toString() {}
|
||||
|
||||
}
|
||||
|
||||
class EventsCatcher extends Catcher {
|
||||
public function __construct(&$core) {
|
||||
parent::__construct($core);
|
||||
}
|
||||
|
||||
public function fireEvent($input) {
|
||||
if (is_string($input)) {
|
||||
// If the input is a string
|
||||
$eventClass = $input;
|
||||
$eventName = $input;
|
||||
if(!class_exists($eventClass)){
|
||||
// Check if the file even exists
|
||||
$file = "Core/Events/event.".$eventName.".php";
|
||||
if(file_exists($file)){
|
||||
// Load the file
|
||||
require_once($file);
|
||||
}else{
|
||||
// No event arguments? Looks like a notify-event
|
||||
if(func_num_args() == 1){
|
||||
// Load notify-event-class
|
||||
$eventClass = '\FuzeWorks\NotifierEvent';
|
||||
}else{
|
||||
// No notify-event: we tried all we could
|
||||
throw new Exception("Event ".$eventName." could not be found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$event = new $eventClass($this);
|
||||
} elseif (is_object($input)) {
|
||||
$eventName = get_class($input);
|
||||
$eventName = explode('\\', $eventName);
|
||||
$eventName = end($eventName);
|
||||
$event = $input;
|
||||
} else {
|
||||
// INVALID EVENT
|
||||
return false;
|
||||
}
|
||||
|
||||
if (func_num_args() > 1)
|
||||
call_user_func_array(array($event, 'init'), array_slice(func_get_args(), 1));
|
||||
|
||||
return $event;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -46,39 +46,74 @@ class Core {
|
|||
}
|
||||
}
|
||||
|
||||
public function loadStartupFiles() {
|
||||
public function loadStartupFiles($config = array()) {
|
||||
if ($this->loaded)
|
||||
return;
|
||||
|
||||
// Load core abstracts
|
||||
require_once("Core/System/class.abstract.bus.php");
|
||||
require_once("Core/System/class.abstract.event.php");
|
||||
require_once("Core/System/class.abstract.module.php");
|
||||
require_once("Core/System/class.abstract.model.php");
|
||||
require_once("Core/System/class.abstract.controller.php");
|
||||
require_once("Core/System/class.abstract.eventPriority.php");
|
||||
require_once("Core/System/class.catcher.php");
|
||||
require_once("Core/System/class.exceptions.php");
|
||||
require_once("Core/System/class.abstract.event.php");
|
||||
|
||||
// Load the core classes
|
||||
require_once("Core/System/class.config.php");
|
||||
require_once("Core/System/class.logger.php");
|
||||
require_once("Core/System/class.models.php");
|
||||
require_once("Core/System/class.layout.php");
|
||||
require_once("Core/System/class.events.php");
|
||||
require_once("Core/System/class.router.php");
|
||||
require_once("Core/System/class.modules.php");
|
||||
|
||||
// Create the module holder
|
||||
|
||||
|
||||
// Load the modules
|
||||
$this->mods->events = new Events ($this);
|
||||
$this->mods->config = new Config ($this);
|
||||
$this->mods->logger = new Logger ($this);
|
||||
$this->mods->models = new Models ($this);
|
||||
$this->mods->layout = new Layout ($this);
|
||||
$this->mods->router = new Router ($this);
|
||||
$this->mods->modules = new Modules ($this);
|
||||
$core_mods = $this->mods->config->core;
|
||||
|
||||
// Events
|
||||
if ($core_mods->enable_events) {
|
||||
require_once("Core/System/class.abstract.eventPriority.php");
|
||||
require_once("Core/System/class.events.php");
|
||||
$this->mods->events = new Events ($this);
|
||||
} else {
|
||||
$this->mods->events = new EventsCatcher ($this);
|
||||
}
|
||||
|
||||
// Logger
|
||||
if ($core_mods->enable_logger) {
|
||||
require_once("Core/System/class.logger.php");
|
||||
$this->mods->logger = new Logger ($this);
|
||||
} else {
|
||||
$this->mods->logger = new Catcher ($this);
|
||||
}
|
||||
|
||||
// Models
|
||||
if ($core_mods->enable_models) {
|
||||
require_once("Core/System/class.abstract.model.php");
|
||||
require_once("Core/System/class.models.php");
|
||||
$this->mods->models = new Models ($this);
|
||||
} else {
|
||||
$this->mods->models = new Catcher ($this);
|
||||
}
|
||||
|
||||
// Layout
|
||||
if ($core_mods->enable_layout) {
|
||||
require_once("Core/System/class.layout.php");
|
||||
$this->mods->layout = new Layout ($this);
|
||||
} else {
|
||||
$this->mods->layout = new Catcher ($this);
|
||||
}
|
||||
|
||||
// Router
|
||||
if ($core_mods->enable_router) {
|
||||
require_once("Core/System/class.abstract.controller.php");
|
||||
require_once("Core/System/class.router.php");
|
||||
$this->mods->router = new Router ($this);
|
||||
} else {
|
||||
$this->mods->router = new Catcher ($this);
|
||||
}
|
||||
|
||||
// Modules
|
||||
if ($core_mods->enable_modules) {
|
||||
require_once("Core/System/class.abstract.module.php");
|
||||
require_once("Core/System/class.modules.php");
|
||||
$this->mods->modules = new Modules ($this);
|
||||
} else {
|
||||
$this->mods->modules = new Catcher ($this);
|
||||
}
|
||||
|
||||
$this->loaded = true;
|
||||
}
|
||||
|
|
|
@ -173,7 +173,15 @@ class Events extends Bus{
|
|||
// Event Preparation:
|
||||
public function buildEventRegister() {
|
||||
$event_register = array();
|
||||
foreach ($this->modules->register as $key => $value) {
|
||||
// Check wether there is data or not
|
||||
$data = $this->modules->register;
|
||||
if (is_null($data)) {
|
||||
$this->register = array();
|
||||
return true;
|
||||
}
|
||||
|
||||
// If there is, handle it
|
||||
foreach ($data as $key => $value) {
|
||||
if (isset($value['events'])) {
|
||||
if (!empty($value['events'])) {
|
||||
for ($i=0; $i < count($value['events']); $i++) {
|
||||
|
@ -188,6 +196,7 @@ class Events extends Bus{
|
|||
}
|
||||
|
||||
$this->register = $event_register;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue