Made the core of FuzeWorks static.

Resolves #74

More tests are needed in order to prove functioning of renewed core
This commit is contained in:
Abel Hoogeveen 2015-09-05 21:47:35 +02:00
parent d2ec5b0c2a
commit 68b3b402e7
33 changed files with 612 additions and 994 deletions

View File

@ -1,10 +1,4 @@
<?php return array (
'enable_events' => true,
'enable_logger' => true,
'enable_models' => true,
'enable_layout' => true,
'enable_router' => true,
'enable_modules' => true,
'enable_composer' => true
) ;

View File

@ -2,14 +2,12 @@
namespace Controller;
use \FuzeWorks\Controller;
use \FuzeWorks\Layout;
class Standard extends Controller {
public function __construct(&$core) {
parent::__construct($core);
}
public function index($path = null) {
$this->layout->view('home');
Layout::view('home');
}
}

View File

@ -40,9 +40,7 @@ namespace FuzeWorks;
*/
class Interpret extends Model {
public function __construct(&$core){
parent::__construct($core);
public function __construct(){
$this->setType('techfuze/databaseutils', 'Model');
$this->table = '';
}

View File

@ -1,132 +0,0 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author TechFuze
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
* @link http://fuzeworks.techfuze.net
* @since Version 0.0.1
* @version Version 0.0.1
*/
namespace FuzeWorks;
/**
* Class Bus
*
* Every class in this framework does somehow extend this class. Because it rocks.
* This class offers a lot of pointers to important core classes, so every class can find other classes.
*
* @package net.techfuze.fuzeworks.core
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
abstract class Bus {
/**
* @var \FuzeWorks\Core
*/
protected $core;
/**
* @var \FuzeWorks\ModHolder
*/
public $mods;
/**
* @var \FuzeWorks\Router
*/
protected $router;
/**
* @var \FuzeWorks\Config
*/
protected $config;
/**
* @var \FuzeWorks\Logger
*/
protected $logger;
/**
* @var \FuzeWorks\Models
*/
protected $models;
/**
* @var \FuzeWorks\Layout
*/
protected $layout;
/**
* @var \FuzeWorks\Events
*/
protected $events;
/**
* @var \FuzeWorks\Modules
*/
protected $modules;
/**
* Create references to our core objects
*
* Because all of these variables are references, they are completely identical / always updated.
* Any class that extends the CoreAbstract class now has access to the whole core.
*
* @param \FuzeWorks\Core $core
*/
protected function __construct(&$core){
$this->core = &$core;
$this->mods = new ModHolder($this->core);
$this->config = &$core->mods->config;
$this->logger = &$core->mods->logger;
$this->models = &$core->mods->models;
$this->layout = &$core->mods->layout;
$this->events = &$core->mods->events;
$this->router = &$core->mods->router;
$this->modules = &$core->mods->modules;
}
}
/**
* An object class which holds modules so that other classes can access it.
* This is used so that all classes that somehow extend Bus can access modules
* using $this->mods->MOD_NAME;
*/
class ModHolder {
protected $core;
public function __construct(&$core) {
$this->core = &$core;
}
public function __get($name) {
if (isset($this->core->mods->$name)) {
return $this->core->mods->$name;
} else {
$this->core->loadMod($name);
return $this->core->mods->$name;
}
}
}
?>

View File

@ -38,4 +38,4 @@ namespace FuzeWorks;
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
abstract class Controller extends Bus{}
abstract class Controller {}

View File

@ -49,7 +49,7 @@ interface ModelServer {
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
abstract class Model extends Bus{
abstract class Model {
/**
* The parent class holder object
@ -59,15 +59,6 @@ abstract class Model extends Bus{
*/
private $parentClass;
/**
* Constructs the class and Bus
* @access public
* @param Core Object, gets referenced
*/
public function __construct(&$core) {
parent::__construct($core);
}
/**
* Set the type of this model. Eg, use techfuze/databasemodel and Databasemodel to get a SQL connected model
* @access protected
@ -75,7 +66,7 @@ abstract class Model extends Bus{
* @param String Model_type, model type to return
*/
protected function setType($module_name, $model_type) {
$mod = $this->core->loadMod($module_name);
$mod = Modules::get($module_name);
$this->parentClass = $mod->giveModel($model_type);
}

View File

@ -38,7 +38,7 @@ namespace FuzeWorks;
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Module extends Bus {
class Module {
/**
* @var null|string Relative path to the module
@ -60,15 +60,6 @@ class Module extends Bus {
*/
protected $cfg;
/**
* Constructor
*
* @param Core $core Pointer to the core class
*/
public function __construct(&$core){
parent::__construct($core);
}
/**
* Returns the name of the module
*
@ -121,7 +112,7 @@ class Module extends Bus {
$this->linkName = $linkName;
}
/**
/**
* The name that is required to load itself, eg 'exampleauthor/examplemodulename' or 'techfuze/cms'
* @access public
* @param String module name
@ -151,7 +142,7 @@ class Module extends Bus {
// Check if the module path is set yet
if ($this->getModulePath() == null) {
$this->logger->logWarning("Could not write module config. ModulePath is not set", get_class($this));
Logger::logWarning("Could not write module config. ModulePath is not set", get_class($this));
return false;
}

View File

@ -1,126 +0,0 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author TechFuze
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
* @link http://fuzeworks.techfuze.net
* @since Version 0.0.1
* @version Version 0.0.1
*/
namespace FuzeWorks;
/**
* Catcher Class
*
* This class catches requests and returns nothing. Handy for a temporary replacement object
* @package net.techfuze.fuzeworks.core
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
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() {}
}
/**
* Events catcher class.
*
* Used for replacing the events core module
* @package net.techfuze.fuzeworks.core
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
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;
}
}
?>

View File

@ -42,29 +42,27 @@ use \PDOException;
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Config extends Bus{
class Config {
/**
* Wether or not the database is active at the moment
* @access public
* @var Boolean true on active database
*/
public $dbActive = false;
public static $dbActive = false;
/**
* Class Constructor
* @access public
* @param FuzeWorks Core Reference
*/
public function __construct(&$core) {
parent::__construct($core);
}
public static function init() {}
/**
* All loaded Config files
* @var Array of ConfigORM
*/
private $cfg = array();
private static $cfg = array();
/**
* Loads a config file and returns it as an object
@ -74,30 +72,30 @@ class Config extends Bus{
* @throws \Exception on file not found
* @return StdObject of config
*/
public function loadConfigFile($name, $directory = null) {
public static function loadConfigFile($name, $directory = null) {
$dir = (isset($directory) ? $directory : "Application/Config/");
$file = $dir . 'config.' . strtolower($name).".php";
// If already loaded, return a reference to the ORM
if (isset($this->cfg[$name])) {
return $cfg = &$this->cfg[$name];
if (isset(self::$cfg[$name])) {
return $cfg = self::$cfg[$name];
}
// Is this the real file?
if (file_exists($file)) {
// Is it just reference?
return $cfg = $this->cfg[$name] = new ConfigFileORM($file);
return $cfg = self::$cfg[$name] = new ConfigFileORM($file);
} else {
// Caught in a datastream
$this->core->loadMod('techfuze/database');
// No escape from dbactive
if ($this->dbActive) {
if (self::$dbActive) {
// Open your stream
$dborm = new ConfigDatabaseORM($this->mods->database, $name);
// Lookup for the success
if ($dborm->success) {
// And see
return $cfg = $this->cfg[$name] = $dborm;
return $cfg = self::$cfg[$name] = $dborm;
}
}
@ -115,8 +113,8 @@ class Config extends Bus{
* @param String config file name
* @return StdObject of config
*/
public function __get($name) {
return $this->loadConfigFile($name);
public static function get($name) {
return self::loadConfigFile($name);
}
}

View File

@ -46,122 +46,86 @@ class Core {
* @access public
* @var String Framework version
*/
public $version = "0.0.1";
private $loaded = false;
public $mods;
public static $version = "0.0.1";
## START/STOP
public function init() {
/**
* @var bool Whether the files has been loaded
*/
private static $loaded = false;
/**
* Initializes the core
*
* @throws \Exception
*/
public static function init() {
// Defines the time the framework starts. Used for timing functions in the framework
if (!defined('STARTTIME')) {
define('STARTTIME', microtime(true));
}
// Load basics
ignore_user_abort(true);
register_shutdown_function(array($this, "shutdown"));
register_shutdown_function(array('\FuzeWorks\Core', "shutdown"));
// Load core functionality
$this->loadStartupFiles();
self::loadStartupFiles();
// Load Composer
if ($this->mods->config->core->enable_composer) {
$this->loadComposer();
}
Logger::init();
$this->mods->modules->buildRegister();
$this->mods->events->buildEventRegister();
Modules::buildRegister();
Events::buildEventRegister();
// And initialize the router paths
$this->mods->router->init();
Router::init();
$event = $this->mods->events->fireEvent('coreStartEvent');
// Load Composer
if (Config::get('core')->enable_composer) {
self::loadComposer();
}
$event = Events::fireEvent('coreStartEvent');
if ($event->isCancelled()) {
return true;
}
}
public function loadStartupFiles($config = array()) {
if ($this->loaded)
public static function loadStartupFiles($config = array()) {
if (self::$loaded)
return;
// Load core abstracts
require_once("Core/System/class.abstract.bus.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.abstract.eventPriority.php");
require_once("Core/System/class.events.php");
require_once("Core/System/class.logger.php");
require_once("Core/System/class.abstract.model.php");
require_once("Core/System/class.models.php");
require_once("Core/System/class.layout.php");
require_once("Core/System/class.abstract.controller.php");
require_once("Core/System/class.router.php");
require_once("Core/System/class.abstract.module.php");
require_once("Core/System/class.modules.php");
// Create the module holder
$this->mods->config = new Config ($this);
$core_mods = $this->mods->config->core;
new Config();
new Events();
new Logger();
new Models();
new Layout();
new Router();
new Modules();
// 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;
self::$loaded = true;
}
public function shutdown() {
$this->mods->events->fireEvent('coreShutdownEvent');
$this->mods->logger->shutdown();
}
public function loadMod($name) {
return $this->mods->modules->loadMod($name);
}
public function addMod($moduleInfo_file) {
return $this->mods->modules->addModule($moduleInfo_file);
public static function shutdown() {
Events::fireEvent('coreShutdownEvent');
Logger::shutdown();
}
/**
@ -169,7 +133,7 @@ class Core {
* @access private
* @param String directory of composer autoload file (optional)
*/
private function loadComposer($file = "vendor/autoload.php") {
private static function loadComposer($file = "vendor/autoload.php") {
if (file_exists($file)) {
require($file);
}

View File

@ -39,7 +39,7 @@ namespace FuzeWorks;
* If we want to add the current time at the end of each page title, we need to hook to the corresponding event. Those events are found in the 'events' directory in the system directory.
* The event that will be fired when the title is changing is called layoutSetTitleEvent. So if we want our module to hook to that event, we add the following to the constructor:
*
* $this->events->addListener(array($this, "onLayoutSetTitleEvent"), "layoutSetTitleEvent", EventPriority::NORMAL);
* Events::addListener(array($this, "onLayoutSetTitleEvent"), "layoutSetTitleEvent", EventPriority::NORMAL);
*
* This will add the function "onLayoutSetTitleEvent" of our current class ($this) to the list of listeners with priority NORMAL. So we need to add
* a method called onLayoutSetTitleEvent($event) it is very important to add the pointer-reference (&) or return the event, otherwise it doesn't change the event variables.
@ -52,15 +52,11 @@ namespace FuzeWorks;
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Events extends Bus{
class Events {
private $listeners;
private $enabled = true;
public function __construct(&$core) {
parent::__construct($core);
$this->listeners = array();
}
private static $listeners = array();
private static $enabled = true;
private static $register;
/**
* Adds a function as listener
@ -72,17 +68,17 @@ class Events extends Bus{
*
* @throws EventException
*/
public function addListener($callback, $eventName, $priority = EventPriority::NORMAL){
public static function addListener($callback, $eventName, $priority = EventPriority::NORMAL){
if(EventPriority::getPriority($priority) == false)
throw new Exception("Unknown priority " . $priority);
if(!isset($this->listeners[$eventName]))
$this->listeners[$eventName] = array();
if(!isset(self::$listeners[$eventName]))
self::$listeners[$eventName] = array();
if(!isset($this->listeners[$eventName][$priority]))
$this->listeners[$eventName][$priority] = array();
if(!isset(self::$listeners[$eventName][$priority]))
self::$listeners[$eventName][$priority] = array();
$this->listeners[$eventName][$priority][] = $callback;
self::$listeners[$eventName][$priority][] = $callback;
}
/**
@ -95,27 +91,27 @@ class Events extends Bus{
*
* @throws EventException
*/
public function removeListener($callback, $eventName, $priority = EventPriority::NORMAL){
public static function removeListener($callback, $eventName, $priority = EventPriority::NORMAL){
if(EventPriority::getPriority($priority) == false)
throw new Exception("Unknown priority " . $priority);
if(!isset($this->listeners[$eventName]))
if(!isset(self::$listeners[$eventName]))
return;
if(!isset($this->listeners[$eventName][$priority]))
if(!isset(self::$listeners[$eventName][$priority]))
return;
foreach($this->listeners[$eventName][$priority] as $i => $_callback){
foreach(self::$listeners[$eventName][$priority] as $i => $_callback){
if($_callback == $callback) {
unset($this->listeners[$eventName][$priority][$i]);
unset(self::$listeners[$eventName][$priority][$i]);
return;
}
}
}
## EVENTS
public function fireEvent($input) {
public static function fireEvent($input) {
if (is_string($input)) {
// If the input is a string
$eventClass = $input;
@ -143,75 +139,76 @@ class Events extends Bus{
$eventName = get_class($input);
$eventName = explode('\\', $eventName);
$eventName = end($eventName);
$event = $input;
$event = $input;
} else {
// INVALID EVENT
return false;
}
$this->logger->newLevel("Firing Event: '".$eventName."'");
$this->logger->log('Initializing Event');
Logger::newLevel("Firing Event: '".$eventName."'");
Logger::log('Initializing Event');
if (func_num_args() > 1)
call_user_func_array(array($event, 'init'), array_slice(func_get_args(), 1));
// Do not run if the event system is disabled
if (!$this->enabled) {
$this->logger->log("Event system is disabled");
$this->logger->stopLevel();
if (!self::$enabled) {
Logger::log("Event system is disabled");
Logger::stopLevel();
return $event;
}
$this->logger->log("Checking for Listeners");
Logger::log("Checking for Listeners");
// Read the event register for listeners
$register = $this->register;
$register = self::$register;
if (isset($register[$eventName])) {
for ($i=0; $i < count($register[$eventName]); $i++) {
$this->core->loadMod($register[$eventName][$i]);
for ($i=0; $i < count($register[$eventName]); $i++) {
Modules::get($register[$eventName][$i]);
}
}
//There are listeners for this event
if(isset($this->listeners[$eventName])) {
if(isset(self::$listeners[$eventName])) {
//Loop from the highest priority to the lowest
for ($priority = EventPriority::getHighestPriority(); $priority <= EventPriority::getLowestPriority(); $priority++) {
//Check for listeners in this priority
if (isset($this->listeners[$eventName][$priority])) {
$listeners = $this->listeners[$eventName][$priority];
$this->logger->newLevel('Found listeners with priority ' . EventPriority::getPriority($priority));
if (isset(self::$listeners[$eventName][$priority])) {
$listeners = self::$listeners[$eventName][$priority];
Logger::newLevel('Found listeners with priority ' . EventPriority::getPriority($priority));
//Fire the event to each listener
foreach ($listeners as $callback) {
if(!is_string($callback[0]))
$this->logger->log('Firing ' . get_class($callback[0]) . '->' . $callback[1]);
Logger::log('Firing ' . get_class($callback[0]) . '->' . $callback[1]);
else
$this->logger->log('Firing ' . join('->', $callback));
$this->logger->newLevel('');
Logger::log('Firing ' . join('->', $callback));
Logger::newLevel('');
try {
call_user_func($callback, $event);
} catch (ModuleException $e) {
$this->error->exceptionHandler($e);
Logger::exceptionHandler($e);
}
$this->logger->stopLevel();
Logger::stopLevel();
}
$this->logger->stopLevel();
Logger::stopLevel();
}
}
}
$this->logger->stopLevel();
Logger::stopLevel();
return $event;
}
// Event Preparation:
public function buildEventRegister() {
public static function buildEventRegister() {
$event_register = array();
// Check wether there is data or not
$data = $this->modules->register;
$data = Modules::$register;
$data = null;
if (is_null($data)) {
$this->register = array();
self::$register = array();
return true;
}
@ -230,24 +227,24 @@ class Events extends Bus{
}
}
$this->register = $event_register;
self::$register = $event_register;
return true;
}
/**
* Enables the event system
*/
public function enable() {
$this->logger->log("Enabled the Event system");
$this->enabled = true;
public static function enable() {
Logger::log("Enabled the Event system");
self::$enabled = true;
}
/**
* Disables the event system
*/
public function disable() {
$this->logger->log("Disabled the Event system");
$this->enabled = false;
public static function disable() {
Logger::log("Disabled the Event system");
self::$enabled = false;
}
}

View File

@ -37,45 +37,37 @@ use \Smarty;
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Layout extends Bus {
class Layout {
/**
* All assigned currently assigned to the template
* @var Array Associative Assigned Variable Array
*/
private $assigned_variables = array();
/**
* Initializes the core module
* @param \FuzeWorks\Core &$core reference to the core
*/
public function __construct(&$core) {
parent::__construct($core);
}
private static $assigned_variables = array();
/**
* All engines that can be used for templates
* @var array of engines
*/
private $engines = array();
private static $engines = array();
/**
* All file extensions that can be used and are bound to a template engine
* @var array of names of engines
*/
private $file_extensions = array();
private static $file_extensions = array();
/**
* Wether the template engines are already called.
* @var boolean True if loaded
*/
private $engines_loaded = false;
private static $engines_loaded = false;
/**
* The currently selected template engine
* @var String name of engine
*/
private $current_engine;
private static $current_engine;
/**
* Retrieve a template file using a string and a directory and immediatly echo it.
@ -85,10 +77,11 @@ class Layout extends Bus {
* Remember that doing so will result in an LayoutException when multiple compatible files are found.
* @param String $file File to load
* @param string $directory Directory to load it from
* @return true on success
* @throws LayoutException On error
*/
public function view($file, $directory = 'Application/Views') {
echo $this->get($file, $directory);
public static function view($file, $directory = 'Application/Views') {
echo self::get($file, $directory);
return true;
}
@ -104,39 +97,39 @@ class Layout extends Bus {
* @return String The output of the template
* @throws LayoutException On error
*/
public function get($file, $directory = 'Application/Views') {
$this->logger->newLevel("Loading template file '".$file."' in '".$directory."'");
public static function get($file, $directory = 'Application/Views') {
Logger::newLevel("Loading template file '".$file."' in '".$directory."'");
// First load the template engines
$this->loadTemplateEngines();
self::loadTemplateEngines();
// First retrieve the filepath
if (is_null($this->current_engine)) {
$file = $this->getFileFromString($file, $directory, array_keys($this->file_extensions));
if (is_null(self::$current_engine)) {
$file = self::getFileFromString($file, $directory, array_keys(self::$file_extensions));
} else {
$file = $this->getFileFromString($file, $directory, $this->current_engine->getFileExtensions());
$file = self::getFileFromString($file, $directory, self::$current_engine->getFileExtensions());
}
// Then assign some basic variables for the template
$this->assigned_variables['viewDir'] = $this->config->main->SITE_URL . preg_replace('#/+#','/', substr($directory . "/", -strlen($directory . "/") ) );
$this->assigned_variables['siteURL'] = $this->config->main->SITE_URL;
$this->assigned_variables['siteLogo'] = $this->config->main->SITE_LOGO_URL;
$this->assigned_variables['serverName'] = $this->config->main->SERVER_NAME;
$this->assigned_variables['siteDomain'] = $this->config->main->SITE_DOMAIN;
$this->assigned_variables['adminMail'] = $this->config->main->administrator_mail;
$this->assigned_variables['contact'] = $this->config->contact->toArray();
self::$assigned_variables['viewDir'] = Config::get('main')->SITE_URL . preg_replace('#/+#','/', substr($directory . "/", -strlen($directory . "/") ) );
self::$assigned_variables['siteURL'] = Config::get('main')->SITE_URL;
self::$assigned_variables['siteLogo'] = Config::get('main')->SITE_LOGO_URL;
self::$assigned_variables['serverName'] = Config::get('main')->SERVER_NAME;
self::$assigned_variables['siteDomain'] = Config::get('main')->SITE_DOMAIN;
self::$assigned_variables['adminMail'] = Config::get('main')->administrator_mail;
self::$assigned_variables['contact'] = Config::get('contact')->toArray();
// Select an engine if one is not already selected
if (is_null($this->current_engine)) {
$this->current_engine = $this->getEngineFromExtension( $this->getExtensionFromFile($file) );
if (is_null(self::$current_engine)) {
self::$current_engine = self::getEngineFromExtension( self::getExtensionFromFile($file) );
}
$this->current_engine->setDirectory($directory);
self::$current_engine->setDirectory($directory);
$this->logger->stopLevel();
Logger::stopLevel();
// And finally run it
return $this->current_engine->get($file, $this->assigned_variables);
return self::$current_engine->get($file, self::$assigned_variables);
}
/**
@ -144,9 +137,9 @@ class Layout extends Bus {
* @param String $extension File extention to look for
* @return Object Template Engine
*/
public function getEngineFromExtension($extension) {
if (isset($this->file_extensions[strtolower($extension)])) {
return $this->engines[ $this->file_extensions[strtolower($extension)]];
public static function getEngineFromExtension($extension) {
if (isset(self::$file_extensions[strtolower($extension)])) {
return self::$engines[ self::$file_extensions[strtolower($extension)]];
}
throw new LayoutException("Could not get Template Engine. No engine has corresponding file extension", 1);
@ -157,7 +150,7 @@ class Layout extends Bus {
* @param String $fileString The path to the file
* @return String Extension of the file
*/
public function getExtensionFromFile($fileString) {
public static function getExtensionFromFile($fileString) {
return substr($fileString, strrpos($fileString, '.') + 1);
}
@ -170,7 +163,7 @@ class Layout extends Bus {
* @return String Filepath of the template
* @throws LayoutException On error
*/
public function getFileFromString($string, $directory, $extensions = array()) {
public static function getFileFromString($string, $directory, $extensions = array()) {
$directory = preg_replace('#/+#','/',(!is_null($directory) ? $directory : "Application/Views") . "/");
if (!file_exists($directory)) {
@ -206,7 +199,7 @@ class Layout extends Bus {
if (file_exists($file) && !$fileSelected) {
$selectedFile = $file;
$fileSelected = true;
$this->logger->log("Found matching file: '". $file . "'");
Logger::log("Found matching file: '". $file . "'");
} elseif (file_exists($file) && $fileSelected) {
throw new LayoutException("Could not select template. Multiple valid extensions detected. Can not choose.", 1);
}
@ -214,7 +207,7 @@ class Layout extends Bus {
// And choose what to output
if (!$fileSelected) {
$this->logger->logWarning("Could not select template. No matching file found.");
Logger::logWarning("Could not select template. No matching file found.");
}
return $selectedFile;
@ -225,24 +218,24 @@ class Layout extends Bus {
* @param String $key Key of the variable
* @param Mixed $value Value of the variable
*/
public function assign($key, $value) {
$this->assigned_variables[$key] = $value;
public static function assign($key, $value) {
self::$assigned_variables[$key] = $value;
}
/**
* Set the title of the template
* @param String $title title of the template
*/
public function setTitle($title) {
$this->assigned_variables['title'] = $title;
public static function setTitle($title) {
self::$assigned_variables['title'] = $title;
}
/**
* Get the title of the template
* @return String title of the template
*/
public function getTitle() {
return $this->assigned_variables['title'];
public static function getTitle() {
return self::$assigned_variables['title'];
}
/**
@ -251,11 +244,11 @@ class Layout extends Bus {
* @return boolean true on success
* @throws \FuzeWorks\LayoutException on error
*/
public function setEngine($name) {
$this->loadTemplateEngines();
if (isset($this->engines[$name])) {
$this->current_engine = $this->engines[$name];
$this->logger->log('Set the Template Engine to ' . $name);
public static function setEngine($name) {
self::loadTemplateEngines();
if (isset(self::$engines[$name])) {
self::$current_engine = self::$engines[$name];
Logger::log('Set the Template Engine to ' . $name);
return true;
}
throw new LayoutException("Could not set engine. Engine does not exist", 1);
@ -266,10 +259,10 @@ class Layout extends Bus {
* @param String $name Name of the template engine
* @return Object Object that implements \FuzeWorks\TemplateEngine
*/
public function getEngine($name) {
$this->loadTemplateEngines();
if (isset($this->engines[$name])) {
return $this->engines[$name];
public static function getEngine($name) {
self::loadTemplateEngines();
if (isset(self::$engines[$name])) {
return self::$engines[$name];
}
throw new LayoutException("Could not return engine. Engine does not exist", 1);
}
@ -282,16 +275,16 @@ class Layout extends Bus {
* @return boolean true on success
* @throws \FuzeWorks\LayoutException On error
*/
public function registerEngine($engineClass, $engineName, $engineFileExtensions) {
public static function registerEngine($engineClass, $engineName, $engineFileExtensions) {
// First check if the engine already exists
if (isset($this->engines[$engineName])) {
if (isset(self::$engines[$engineName])) {
throw new LayoutException("Could not register engine. Engine '".$engineName."' already registered", 1);
}
// Then check if the object is correct
if ($engineClass instanceof TemplateEngine) {
// Install it
$this->engines[$engineName] = $engineClass;
self::$engines[$engineName] = $engineClass;
// Then define for what file extensions this Template Engine will work
if (!is_array($engineFileExtensions)) {
@ -300,16 +293,16 @@ class Layout extends Bus {
// Then install them
foreach ($engineFileExtensions as $extension) {
if (isset($this->file_extensions[strtolower($extension)])) {
if (isset(self::$file_extensions[strtolower($extension)])) {
throw new LayoutException("Could not register engine. File extension already bound to engine", 1);
}
// And add it
$this->file_extensions[strtolower($extension)] = $engineName;
self::$file_extensions[strtolower($extension)] = $engineName;
}
// And log it
$this->logger->log('Registered Template Engine: ' . $engineName);
Logger::log('Registered Template Engine: ' . $engineName);
return true;
}
@ -319,63 +312,30 @@ class Layout extends Bus {
/**
* Load the template engines by sending a layoutLoadEngineEvent
*/
private function loadTemplateEngines() {
if (!$this->engines_loaded) {
$this->events->fireEvent('layoutLoadEngineEvent');
private static function loadTemplateEngines() {
if (!self::$engines_loaded) {
Events::fireEvent('layoutLoadEngineEvent');
// Load the engines provided in this file
$this->registerEngine(new PHPEngine(), 'PHP', array('php'));
$this->registerEngine(new SmartyEngine(), 'Smarty', array('tpl'));
$this->registerEngine(new JsonEngine(), 'JSON', array('json'));
$this->engines_loaded = true;
self::registerEngine(new PHPEngine(), 'PHP', array('php'));
self::registerEngine(new SmartyEngine(), 'Smarty', array('tpl'));
self::registerEngine(new JsonEngine(), 'JSON', array('json'));
self::$engines_loaded = true;
}
}
/**
* Retrieve a value from the template engine
* @param String $name Variable name
* @return Mixed Variable Value
* @throws \FuzeWorks\LayoutException on error
*/
public function __get($name) {
// First load the template engines
$this->loadTemplateEngines();
// Retrieve value from layout engine
if (!is_null($this->current_engine)) {
return $this->current_engine->$name;
}
throw new LayoutException("Could not access Engine. Engine not loaded", 1);
}
/**
* Set a variable in the template engine
* @param String $name Variable Name
* @param Mixed $value Variable Value
* @throws \FuzeWorks\LayoutException on error
*/
public function __set($name, $value) {
// First load the template engines
$this->loadTemplateEngines();
if (!is_null($this->current_engine)) {
$this->current_engine->$name = $value;
}
throw new LayoutException("Could not access Engine. Engine not loaded", 1);
}
/**
* Calls a function in the current Template engine
* @param String $name Name of the function to be called
* @param Paramaters $params Parameters to be used
* @return Mixed Function output
*/
public function __call($name, $params) {
public static function __callStatic($name, $params) {
// First load the template engines
$this->loadTemplateEngines();
self::loadTemplateEngines();
if (!is_null($this->current_engine)) {
if (!is_null(self::$current_engine)) {
// Call user func array here
return call_user_func_array(array($this->current_engine, $name), $params);
return call_user_func_array(array(self::$current_engine, $name), $params);
}
throw new LayoutException("Could not access Engine. Engine not loaded", 1);
}
@ -383,13 +343,13 @@ class Layout extends Bus {
/**
* Resets the layout manager to its default state
*/
public function reset() {
if (!is_null($this->current_engine)) {
$this->current_engine->reset();
public static function reset() {
if (!is_null(self::$current_engine)) {
self::$current_engine->reset();
}
$this->current_engine = null;
$this->assigned_variables = array();
$this->logger->log("Reset the layout manager to its default state");
self::$current_engine = null;
self::$assigned_variables = array();
Logger::log("Reset the layout manager to its default state");
}
}

View File

@ -39,29 +39,27 @@ namespace FuzeWorks;
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Logger extends Bus{
class Logger {
public $infoErrors = array();
public $criticalErrors = array();
public $warningErrors = array();
public $Logs = array();
private $print_to_screen = false;
public $debug = false;
public function __construct(&$core) {
parent::__construct($core);
public static $infoErrors = array();
public static $criticalErrors = array();
public static $warningErrors = array();
public static $Logs = array();
private static $print_to_screen = false;
public static $debug = false;
public static function init() {
// Register the error handler
if ($this->config->error->error_reporting == true) {
set_error_handler(array($this, "errorHandler"), E_ALL);
set_Exception_handler(array($this, "exceptionHandler"));
if (Config::get('error')->error_reporting == true) {
set_error_handler(array('\FuzeWorks\Logger', "errorHandler"), E_ALL);
set_Exception_handler(array('\FuzeWorks\Logger', "exceptionHandler"));
error_reporting(false);
}
$this->debug = $this->config->error->debug;
$this->newLevel("Logger Initiated");
self::$debug = Config::get('error')->debug;
self::newLevel("Logger Initiated");
}
public function shutdown() {
public static function shutdown() {
// Load last error if thrown
$errfile = "Unknown file";
$errstr = "shutdown";
@ -76,13 +74,13 @@ class Logger extends Bus{
$errstr = $error['message'];
// Log it!
$this->errorHandler($errno, $errstr, $errfile, $errline);
$this->logInfo($this->backtrace());
self::errorHandler($errno, $errstr, $errfile, $errline);
self::logInfo(self::backtrace());
}
if ($this->debug == true || $this->print_to_screen) {
$this->log("Parsing debug log", "Logger");
$this->logToScreen();
if (self::$debug == true || self::$print_to_screen) {
self::log("Parsing debug log", "Logger");
self::logToScreen();
}
}
@ -96,7 +94,7 @@ class Logger extends Bus{
* @param array context. Some of the error's relevant variables
* @return void
*/
public function errorHandler($type = E_USER_NOTICE, $error = "Undefined Error", $errFile = null, $errLine = null, $context = null) {
public static function errorHandler($type = E_USER_NOTICE, $error = "Undefined Error", $errFile = null, $errLine = null, $context = null) {
// Check type
$thisType = self::getType($type);
$LOG = array('type' => (!is_null($thisType) ? $thisType : "ERROR"),
@ -104,8 +102,8 @@ class Logger extends Bus{
'logFile' => (!is_null($errFile) ? $errFile : ""),
'logLine' => (!is_null($errLine) ? $errLine : ""),
'context' => (!is_null($context) ? $context : ""),
'runtime' => round($this->getRelativeTime(), 4));
$this->Logs[] = $LOG;
'runtime' => round(self::getRelativeTime(), 4));
self::$Logs[] = $LOG;
}
/**
@ -117,7 +115,7 @@ class Logger extends Bus{
* @param Exception $exception The occured exception.
* @return void
*/
public function exceptionHandler($exception)
public static function exceptionHandler($exception)
{
$message = $exception->getMessage();
$code = $exception->getCode();
@ -125,12 +123,12 @@ class Logger extends Bus{
$line = $exception->getLine();
$context = $exception->getTraceAsString();
$this->logError("Exception thrown: " . $message . " | " . $code, null, $file, $line);
self::logError("Exception thrown: " . $message . " | " . $code, null, $file, $line);
}
public function logToScreen() {
public static function logToScreen() {
// Send a screenLogEvent, allows for new screen log designs
$event = $this->mods->events->fireEvent('screenLogEvent');
$event = Events::fireEvent('screenLogEvent');
if ($event->isCancelled()) {
return false;
}
@ -138,9 +136,9 @@ class Logger extends Bus{
// Otherwise just load it
echo '<h3>FuzeWorks debug log</h3>';
$layer = 0;
for($i = 0; $i < count($this->Logs); $i++){
for($i = 0; $i < count(self::$Logs); $i++){
$log = $this->Logs[$i];
$log = self::$Logs[$i];
if($log['type'] == 'LEVEL_START'){
$layer++;
$color = 255-($layer*25);
@ -161,7 +159,7 @@ class Logger extends Bus{
}
}
public function backtrace() {
public static function backtrace() {
$e = new Exception();
$trace = explode("\n", $e->getTraceAsString());
// reverse array to make steps line up chronologically
@ -182,66 +180,66 @@ class Logger extends Bus{
/* =========================================LOGGING METHODS==============================================================*/
public function log($msg, $mod = null, $file = 0, $line = 0) {
$this->logInfo($msg, $mod, $file, $line);
public static function log($msg, $mod = null, $file = 0, $line = 0) {
self::logInfo($msg, $mod, $file, $line);
}
public function logInfo($msg, $mod = null, $file = 0, $line = 0) {
$LOG = array('type' => 'INFO',
public static function logInfo($msg, $mod = null, $file = 0, $line = 0) {
$LOG = array('type' => 'INFO',
'message' => (!is_null($msg) ? $msg : ""),
'logFile' => (!is_null($file) ? $file : ""),
'logLine' => (!is_null($line) ? $line : ""),
'context' => (!is_null($mod) ? $mod : ""),
'runtime' => round($this->getRelativeTime(), 4));
'runtime' => round(self::getRelativeTime(), 4));
$this->infoErrors[] = $LOG;
$this->Logs[] = $LOG;
self::$infoErrors[] = $LOG;
self::$Logs[] = $LOG;
}
public function logError($msg, $mod = null, $file = 0, $line = 0) {
public static function logError($msg, $mod = null, $file = 0, $line = 0) {
$LOG = array('type' => 'ERROR',
'message' => (!is_null($msg) ? $msg : ""),
'logFile' => (!is_null($file) ? $file : ""),
'logLine' => (!is_null($line) ? $line : ""),
'context' => (!is_null($mod) ? $mod : ""),
'runtime' => round($this->getRelativeTime(), 4));
'runtime' => round(self::getRelativeTime(), 4));
$this->criticalErrors[] = $LOG;
$this->Logs[] = $LOG;
self::$criticalErrors[] = $LOG;
self::$Logs[] = $LOG;
}
public function logWarning($msg, $mod = null, $file = 0, $line = 0) {
public static function logWarning($msg, $mod = null, $file = 0, $line = 0) {
$LOG = array('type' => 'WARNING',
'message' => (!is_null($msg) ? $msg : ""),
'logFile' => (!is_null($file) ? $file : ""),
'logLine' => (!is_null($line) ? $line : ""),
'context' => (!is_null($mod) ? $mod : ""),
'runtime' => round($this->getRelativeTime(), 4));
'runtime' => round(self::getRelativeTime(), 4));
$this->warningErrors[] = $LOG;
$this->Logs[] = $LOG;
self::$warningErrors[] = $LOG;
self::$Logs[] = $LOG;
}
public function newLevel($msg, $mod = null, $file = null, $line = null) {
public static function newLevel($msg, $mod = null, $file = null, $line = null) {
$LOG = array('type' => 'LEVEL_START',
'message' => (!is_null($msg) ? $msg : ""),
'logFile' => (!is_null($file) ? $file : ""),
'logLine' => (!is_null($line) ? $line : ""),
'context' => (!is_null($mod) ? $mod : ""),
'runtime' => round($this->getRelativeTime(), 4));
'runtime' => round(self::getRelativeTime(), 4));
$this->Logs[] = $LOG;
self::$Logs[] = $LOG;
}
public function stopLevel($msg = null, $mod = null, $file = null, $line = null) {
public static function stopLevel($msg = null, $mod = null, $file = null, $line = null) {
$LOG = array('type' => 'LEVEL_STOP',
'message' => (!is_null($msg) ? $msg : ""),
'logFile' => (!is_null($file) ? $file : ""),
'logLine' => (!is_null($line) ? $line : ""),
'context' => (!is_null($mod) ? $mod : ""),
'runtime' => round($this->getRelativeTime(), 4));
'runtime' => round(self::getRelativeTime(), 4));
$this->Logs[] = $LOG;
self::$Logs[] = $LOG;
}
/* =========================================OTHER METHODS==============================================================*/
@ -254,7 +252,7 @@ class Logger extends Bus{
* @param int $type PHP-constant errortype (e.g. E_NOTICE).
* @return string String representation
*/
public function getType($type) {
public static function getType($type) {
switch ($type)
{
@ -294,7 +292,7 @@ class Logger extends Bus{
return $type = 'Unknown error: '.$type;
}
public function http_error($errno = 500, $view = true){
public static function http_error($errno = 500, $view = true){
$http_codes = array(
@ -333,8 +331,8 @@ class Logger extends Bus{
511 => 'Network Authentication Required'
);
$this->logError('HTTP-error '.$errno.' called', 'Logger');
$this->logInfo('Sending header HTTP/1.1 '.$errno.' '.$http_codes[$errno], 'Logger', __FILE__, __LINE__);
self::logError('HTTP-error '.$errno.' called', 'Logger');
self::log('Sending header HTTP/1.1 '.$errno.' '.$http_codes[$errno], 'Logger', __FILE__, __LINE__);
header('HTTP/1.1 '.$errno.' '.$http_codes[$errno]);
// Do we want the error-view with it?
@ -342,11 +340,11 @@ class Logger extends Bus{
return;
$view = 'errors/'.$errno;
$this->logger->log('Loading view '.$view);
self::log('Loading view '.$view);
try{
$this->layout->view($view);
Layout::view($view);
}catch(LayoutException $exception){
// No error page could be found, just echo the result
@ -358,19 +356,19 @@ class Logger extends Bus{
* Enable error to screen logging
* @access public
*/
public function enable() {
$this->print_to_screen = true;
public static function enable() {
self::$print_to_screen = true;
}
/**
* Disable error to screen logging
* @access public
*/
public function disable() {
$this->print_to_screen = false;
public static function disable() {
self::$print_to_screen = false;
}
private function getRelativeTime() {
private static function getRelativeTime() {
$startTime = STARTTIME;
$time = microtime(true) - $startTime;
return $time;

View File

@ -39,47 +39,43 @@ namespace FuzeWorks;
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Models extends Bus{
class Models {
private $models_array = array();
private $model_types = array();
private $models_loaded = false;
private static $models_array = array();
private static $model_types = array();
private static $models_loaded = false;
public function __construct(&$core){
parent::__construct($core);
}
public function loadModel($name, $directory = null){
public static function loadModel($name, $directory = null){
// Model load event
$event = $this->events->fireEvent('modelLoadEvent', $name, $directory);
$event = Events::fireEvent('modelLoadEvent', $name, $directory);
$directory = ($event->directory === null ? "Application/Models" : $event->directory);
$name = ($event->model === null ? $name : $event->model);
$file = $directory.'/model.'.$name.'.php';
if (isset($this->model_types[$name])) {
$this->logger->logInfo('Loading Model: '.get_class($this->model_types[$name]), get_class($this->model_types[$name]));
$this->models_array[$name] = $this->model_types[$name];
if (isset(self::$model_types[$name])) {
Logger::log('Loading Model: '.get_class(self::$model_types[$name]), get_class(self::$model_types[$name]));
self::$models_array[$name] = self::$model_types[$name];
} elseif (file_exists($file)){
require_once($file);
$model = "\Model\\" . ucfirst($name);
$this->logger->logInfo('Loading Model: '.$model, $model);
$this->models_array[$name] = new $model($this->core);
Logger::log('Loading Model: '.$model, $model);
self::$models_array[$name] = new $model();
} else{
$this->logger->logWarning('The requested model: \''.$name.'\' could not be found. Loading empty model', 'Models');
Logger::logWarning('The requested model: \''.$name.'\' could not be found. Loading empty model', 'Models');
require_once("Core/System/Models/model.interpret.php");
$this->logger->logInfo('Loading Model: interprated databasemodel', 'Models');
$model = new Interpret($this->core);
Logger::log('Loading Model: interprated databasemodel', 'Models');
$model = new Interpret();
$model->table($name);
$this->models_array[$name] = $model;
self::$models_array[$name] = $model;
}
}
public function __get($name){
if (isset($this->models_array[strtolower($name)])) {
return $this->models_array[strtolower($name)];
public static function get($name){
if (isset(self::$models_array[strtolower($name)])) {
return self::$models_array[strtolower($name)];
} else {
$this->loadModel(strtolower($name));
return $this->models_array[strtolower($name)];
self::loadModel(strtolower($name));
return self::$models_array[strtolower($name)];
}
}
}

View File

@ -37,35 +37,34 @@ use \stdClass;
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Modules extends Bus{
class Modules {
public $register;
public $modules;
public static $register;
public static $modules = array();
/**
* An array which modules are loaded, and should not be loaded again
* @access private
* @var Array of module names
*/
private $loaded_modules = array();
public function __construct(&$core){
parent::__construct($core);
$this->modules = array();
}
private static $loaded_modules = array();
/**
* Retrieves a module and returns it.
* If a module is already loaded, it returns a reference to the loaded version
* @param String $name Name of the module
* @return \FuzeWorks\Module Module The module
* @throws FuzeWorks\ModuleException
*/
public function loadMod($name) {
public static function get($name) {
// Where the modules are
$path = "Modules/";
// Check if the requested module is registered
if (isset($this->register[$name])) {
if (!empty($this->register[$name])) {
if (isset(self::$register[$name])) {
if (!empty(self::$register[$name])) {
// Load the moduleInfo
$cfg = (object) $this->register[$name];
$cfg = (object) self::$register[$name];
// Check if the module is disabled
if (isset($cfg->meta)) {
@ -74,11 +73,11 @@ class Modules extends Bus{
}
// Check if the module is already loaded. If so, only return a reference, if not, load the module
if (in_array($name, $this->loaded_modules)) {
if (in_array($name, self::$loaded_modules)) {
// return the link
$msg = "Module '".ucfirst((isset($cfg->name) ? $cfg->name : $cfg->module_name)) . "' is already loaded";
$this->logger->log($msg);
$c = &$this->core->mods->{strtolower($cfg->module_name)};
Logger::log($msg);
$c = self::$modules[strtolower($cfg->module_name)];
return $c;
} else {
// Load the module
@ -87,7 +86,7 @@ class Modules extends Bus{
// Load the dependencies before the module loads
$deps = (isset($cfg->dependencies) ? $cfg->dependencies : array());
for ($i=0; $i < count($deps); $i++) {
$this->loadMod($deps[$i]);
self::get($deps[$i]);
}
// Check if the file exists
@ -99,7 +98,7 @@ class Modules extends Bus{
$msg .= (isset($cfg->version) ? "; version: ".$cfg->version : "");
$msg .= (isset($cfg->author) ? "; made by ".$cfg->author : "");
$msg .= (isset($cfg->website) ? "; from ".$cfg->website: "");
$this->logger->log($msg);
Logger::log($msg);
} else {
// Throw Exception if the file does not exist
throw new ModuleException("Requested mod '".$name."' could not be loaded. Class file not found", 1);
@ -110,13 +109,13 @@ class Modules extends Bus{
if (isset($cfg->abstract)) {
if ($cfg->abstract) {
$CLASS = new stdClass();
return $this->core->mods->{strtolower($cfg->module_name)} = &$CLASS;
return self::$modules[strtolower($cfg->module_name)] = &$CLASS;
}
}
// Load the module class
$class_name = $cfg->module_class;
$CLASS = new $class_name($this);
$CLASS = new $class_name();
// Apply default methods
if (method_exists($CLASS, 'setModulePath')) {
@ -146,16 +145,16 @@ class Modules extends Bus{
$CLASS->onLoad();
// Add to the loaded modules
$this->loaded_modules[] = $name;
self::$loaded_modules[] = $name;
// Return a reference
return $this->core->mods->{strtolower($cfg->module_name)} = &$CLASS;
return self::$modules[strtolower($cfg->module_name)] = &$CLASS;
}
}
}
}
private function setModuleValue($file, $key, $value) {
private static function setModuleValue($file, $key, $value) {
if (file_exists($file) && is_writable($file)) {
$cfg = require($file);
$cfg[$key] = $value;
@ -167,7 +166,7 @@ class Modules extends Bus{
/**
* @throws FuzeWorks\ModuleException
*/
public function addModule($moduleInfo_file) {
public static function addModule($moduleInfo_file) {
$file = $moduleInfo_file;
$directory = dirname($file);
if (file_exists($file)) {
@ -179,9 +178,9 @@ class Modules extends Bus{
$name .= (!empty($cfg->author) ? strtolower($cfg->author)."/" : "");
$name .= strtolower($cfg->module_name);
$this->logger->log("Adding module: '".$name."'");
if (isset($this->register[$name])) {
$this->logger->logError("Module '".$name."' can not be added. Module is already loaded");
Logger::log("Adding module: '".$name."'");
if (isset(self::$register[$name])) {
Logger::logError("Module '".$name."' can not be added. Module is already loaded");
return false;
}
@ -189,21 +188,21 @@ class Modules extends Bus{
if (isset($cfg->enabled)) {
if ($cfg->enabled) {
// Copy all the data into the register and enable
$this->register[$name] = (array) $cfg;
$this->logger->log("[ON] '".$name."'");
self::$register[$name] = (array) $cfg;
Logger::log("[ON] '".$name."'");
} else {
// If not, copy all the basic data so that it can be enabled in the future
$cfg2 = new StdClass();
$cfg2->module_name = $cfg->module_name;
$cfg2->directory = $cfg->directory;
$cfg2->meta = $cfg;
$this->register[$name] = (array)$cfg2;
$this->logger->log("[OFF] '".$name."'");
self::$register[$name] = (array)$cfg2;
Logger::log("[OFF] '".$name."'");
}
} else {
// Copy all the data into the register and enable
$this->register[$name] = (array) $cfg;
$this->logger->log("[ON] '".$name."'");
self::$register[$name] = (array) $cfg;
Logger::log("[ON] '".$name."'");
}
} else {
throw new ModuleException("Could not add module. '$moduleInfo_file' does not exist", 1);
@ -213,15 +212,15 @@ class Modules extends Bus{
/**
* @throws FuzeWorks\ModuleException
*/
public function enableModule($name, $permanent = true) {
if (isset($this->register[$name])) {
public static function enableModule($name, $permanent = true) {
if (isset(self::$register[$name])) {
// Change the register
$info = (object) $this->register[$name];
$info = (object) self::$register[$name];
// Do nothing if it is already enabled
if (isset($info->enabled)) {
if ($info->enabled) {
$this->logger->logWarning("Could not enable module '".$name."'. Module is already enabled.");
Logger::logWarning("Could not enable module '".$name."'. Module is already enabled.");
return false;
}
}
@ -229,18 +228,18 @@ class Modules extends Bus{
// Otherwise move data from meta to the module config
$info = $info->meta;
$info->enabled = true;
$this->register[$name] = (array)$info;
self::$register[$name] = (array)$info;
$this->logger->log("Enabled module '".$name."'");
Logger::log("Enabled module '".$name."'");
// Enable it permanently if so desired
if ($permanent) {
$file = $info->directory . "/moduleInfo.php";
$this->setModuleValue($file, 'enabled', true);
self::setModuleValue($file, 'enabled', true);
}
// Reload the eventRegister
$this->events->buildEventRegister();
Events::buildEventRegister();
} else {
throw new ModuleException("Could not enable module '".$name."'. Module does not exist.", 1);
}
@ -249,13 +248,13 @@ class Modules extends Bus{
/**
* @throws FuzeWorks\ModuleException
*/
public function disableModule($name, $permanent = true) {
if (isset($this->register[$name])) {
$info = (object) $this->register[$name];
public static function disableModule($name, $permanent = true) {
if (isset(self::$register[$name])) {
$info = (object) self::$register[$name];
// Do nothing if it is already disabled
if (isset($info->meta)) {
$this->logger->logWarning("Could not disable module '".$name."'. Module is already disabled.");
Logger::logWarning("Could not disable module '".$name."'. Module is already disabled.");
return false;
}
@ -264,26 +263,26 @@ class Modules extends Bus{
$disabled->directory = $info->directory;
$disabled->module_name = $info->module_name;
$this->register[$name] = (array)$disabled;
$this->logger->log("Disabled module '".$name."'");
self::$register[$name] = (array)$disabled;
Logger::log("Disabled module '".$name."'");
if ($permanent) {
$file = $info->directory . "/moduleInfo.php";
$this->setModuleValue($file, 'enabled', false);
self::setModuleValue($file, 'enabled', false);
}
// Reload the eventRegister
$this->events->buildEventRegister();
Events::buildEventRegister();
// Remove the existence of the module
unset($this->core->mods->{strtolower($info->module_name)});
unset(self::$modules[strtolower($cfg->module_name)]);
} else {
throw new ModuleException("Could not disable module '".$name."'. Module does not exist.", 1);
}
}
public function buildRegister() {
$this->logger->newLevel("Loading Module Headers", 'Core');
public static function buildRegister() {
Logger::newLevel("Loading Module Headers", 'Core');
// Get all the module directories
$dir = "Modules/";
@ -312,14 +311,14 @@ class Modules extends Bus{
if ($cfg->enabled) {
// Copy all the data into the register and enable
$register[$name] = (array) $cfg;
$this->logger->log("[ON] '".$name."'");
Logger::log("[ON] '".$name."'");
// Add all module aliases if available
if (isset($cfg->aliases)) {
foreach ($cfg->aliases as $alias) {
$register[$alias] = (array) $cfg;
unset($register[$alias]['events']);
$this->logger->log("&nbsp;&nbsp;&nbsp;'".$alias."' (alias of '".$name."')");
Logger::log("&nbsp;&nbsp;&nbsp;'".$alias."' (alias of '".$name."')");
}
}
} else {
@ -329,28 +328,28 @@ class Modules extends Bus{
$cfg2->directory = $cfg->directory;
$cfg2->meta = $cfg;
$register[$name] = (array)$cfg2;
$this->logger->log("[OFF] '".$name."'");
Logger::log("[OFF] '".$name."'");
// Add all module aliases if available
if (isset($cfg->aliases)) {
foreach ($cfg->aliases as $alias) {
$register[$alias] = (array) $cfg2;
unset($register[$alias]['events']);
$this->logger->log("&nbsp;&nbsp;&nbsp;'".$alias."' (alias of '".$name."')");
Logger::log("&nbsp;&nbsp;&nbsp;'".$alias."' (alias of '".$name."')");
}
}
}
} else {
// Copy all the data into the register and enable
$register[$name] = (array) $cfg;
$this->logger->log("[ON] '".$name."'");
Logger::log("[ON] '".$name."'");
// Add all module aliases if available
if (isset($cfg->aliases)) {
foreach ($cfg->aliases as $alias) {
$register[$alias] = (array) $cfg;
unset($register[$alias]['events']);
$this->logger->log("&nbsp;&nbsp;&nbsp;'".$alias."' (alias of '".$name."')");
Logger::log("&nbsp;&nbsp;&nbsp;'".$alias."' (alias of '".$name."')");
}
}
}
@ -369,12 +368,12 @@ class Modules extends Bus{
// Apply it
$register[$name] = (array)$cfg;
$this->logger->log("[ON] '".$name."'");
Logger::log("[ON] '".$name."'");
}
}
$this->register = $register;
$this->logger->stopLevel();
self::$register = $register;
Logger::stopLevel();
}

View File

@ -48,7 +48,7 @@ use \Application\Init;
* B would be the function to be called in the 'controller' (default: index)
* C would be the first parameter
*
* All controllers are to be placed in the /application/çontrollers-directory.
* All controllers are to be placed in the /Application/controller-directory.
*
* But because of this RegEx-table, modules can easily listen on completely different paths. You can, for example, make
* a module that only triggers when /admin/<controller>/<function>/.. is accessed. Or even complexer structure are
@ -72,60 +72,52 @@ use \Application\Init;
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Router extends Bus{
class Router{
/**
* @var null|string The provided path
*/
private $path = null;
private static $path = null;
/**
* @var array Routes
*/
private $routes = array();
/**
* @var null|mixed The callable
*/
private $callable = null;
private static $routes = array();
/**
* @var null|string The controller object
*/
private $controller= null;
* @var null|mixed The callable
*/
private static $callable = null;
/**
* @var null|string The extracted controller's function name
*/
private $function = null;
/**
* @var null|string The extracted controller's name
*/
private static $controller = null;
/**
* @var array The extracted parameters
*/
private $parameters = array();
/**
* @var null|string The extracted controller's function name
*/
private static $function = null;
/**
* @var array The extracted parameters
*/
private static $parameters = array();
/**
* The constructor adds the default route to the routing table
*
* @param Core $core Reference to the core object
*/
public function __construct(&$core){
parent::__construct($core);
}
public static function init(){
/**
* Add the default routes to the routing table
*/
public function init() {
foreach($this->config->routes as $route => $callable){
foreach(Config::get('routes') as $route => $callable){
if(is_int($route)) {
$route = $callable;
$callable = array($this, 'defaultCallable');
$callable = array('\FuzeWorks\Router', 'defaultCallable');
}
$this->addRoute($route, $callable, false);
self::addRoute($route, $callable, false);
}
}
@ -134,85 +126,86 @@ class Router extends Bus{
*
* @return bool|string
*/
public function getPath(){
public static function getPath(){
return $this->path;
return self::$path;
}
/**
* Returns an array with all the routes
* @return array
*/
public function getRoutes(){
public static function getRoutes(){
return $this->routes;
return self::$routes;
}
/**
* Returns the currently loaded callable
* @return null|callable
*/
public function getCallable(){
public static function getCallable(){
return $this->callable;
return self::$callable;
}
/**
* Returns the active controller
* Returns the active controller's name
*
* @return null|Controller The controller object
* @return null|string
*/
public function getController() {
public static function getController() {
return $this->controller;
return self::$controller;
}
/**
* Returns the name of the function
* Returns the name of the active controller's function
*
* @return null|string The name of the function
*/
public function getFunction() {
public static function getFunction() {
return $this->function;
return self::$function;
}
/**
* Returns the routing parameters
*
* @return array
*/
public function getParameters(){
/**
* Returns the routing parameters
*
* @return array
*/
public static function getParameters(){
return $this->parameters;
return self::$parameters;
}
/**
* Returns the routing parameter at given index
*
* @param int $index
* @return array
*/
public function getParameter($index = 0){
/**
* Returns the routing parameter at given index
*
* @param int $index
* @return array
*/
public static function getParameter($index = 0){
$parameters = $this->parameters;
$parameters = self::$parameters;
$index = ($index >= 0 ? $index : count($parameters)+$index);
if(isset($parameters[$index]))
return $parameters[$index];
return null;
}
}
/**
* Set the current routing path
*
* @param string $path The routing path (e.g. a/b/c/d/e)
* @return bool|string
*/
public static function setPath($path){
/**
* Set the current routing path
*
* @param string $path The routing path (e.g. a/b/c/d/e)
* @return bool|string
*/
public function setPath($path){
// Fire the event to notify our modules
$event = $this->events->fireEvent('routerSetPathEvent', $path);
$event = Events::fireEvent('routerSetPathEvent', $path);
// The event has been cancelled
if($event->isCancelled()){
@ -220,30 +213,56 @@ class Router extends Bus{
return false;
}
// Remove double slashes
$event->path = preg_replace('@[/]+@', '/', $event->path);
// Remove double slashes
$path = preg_replace('@[/]+@', '/', $path);
// Remove first slash
if(substr($event->path, 0, 1) == '/')
$event->path = substr($event->path, 1);
// Remove first slash
if(substr($path, 0, 1) == '/')
$path = substr($path, 1);
// Remove trailing slash
if(substr($event->path, -1, 1) == '/')
$event->path = substr($event->path, 0, strlen($event->path)-1);
if(substr($path, -1, 1) == '/')
$path = substr($path, 0, strlen($path)-1);
return $this->path = $event->path;
}
return self::$path = $path;
}
/**
* Set the controller name
*
* Until we decide what to do with name giving of controllers/functions,
* this function stays here.
*
* @param string $controller the name of the controller
*/
public static function setController($controller){
self::$controller = $controller;
}
/**
* Set the function name
*
* Until we decide what to do with name giving of controllers/functions,
* this function stays here.
*
* @param string $function the name of the controller
*/
public static function setFunction($function){
self::$function = $function;
}
/**
* Add a route
*
* The path will be checked before custom routes before the default route(/controller/function/param1/param2/etc)
* When the given RegEx matches the current routing-path, the callable will be called.
*
*
* The callable will be called with three arguments:
*
*
* Callable($controller, $function, $parameters)
*
*
* These three variables will be extracted from the named groups of your RegEx. When one or more named groups are
* not matched, they will be set to NULL. The default RegEx is:
*
@ -279,14 +298,14 @@ class Router extends Bus{
* @param callable $callable The callable to execute
* @param bool $prepend Whether or not to insert at the beginning of the routing table
*/
public function addRoute($route, $callable, $prepend = true){
public static function addRoute($route, $callable, $prepend = true){
if($prepend)
$this->routes = array($route => $callable) + $this->routes;
self::$routes = array($route => $callable) + self::$routes;
else
$this->routes[$route] = $callable;
self::$routes[$route] = $callable;
$this->logger->log('Route added at '.($prepend ? 'top' : 'bottom').': "'.$route.'"');
Logger::log('Route added at '.($prepend ? 'top' : 'bottom').': "'.$route.'"');
}
/**
@ -294,30 +313,23 @@ class Router extends Bus{
*
* @param $route string The route to remove
*/
public function removeRoute($route){
public static function removeRoute($route){
unset($this->routes[$route]);
unset(self::$routes[$route]);
$this->logger->log('Route removed: '.$route);
Logger::log('Route removed: '.$route);
}
/**
* Extracts the routing path to controller, function and parameters
*
* @param boolean $loadCallable Immediate load the callable after routing
*/
public function route($loadCallable = true)
* Extracts the routing path to controller, function and parameters
*
* @TODO: $loadCallable might not be needed anymore
* @param boolean $loadCallable Immediate load the callable when it's route matches
*/
public static function route($loadCallable = true)
{
// Default values
$callable = null;
$args = array();
$controller = null;
$function = null;
$parameters = null;
// Fire the event to notify our modules
$event = $this->events->fireEvent('routerRouteEvent', $this->routes, $loadCallable);
$event = Events::fireEvent('routerRouteEvent', self::$routes, $loadCallable);
// The event has been cancelled
if($event->isCancelled()){
@ -326,96 +338,87 @@ class Router extends Bus{
}
// Assign everything to the object to make it accessible, but let modules check it first
$this->routes = $event->routes;
$loadCallable = $event->loadCallable;
//self::$routes = $event->routes;
//$loadCallable = $event->loadCallable;
//Check the custom routes
foreach ($this->routes as $r => $c) {
foreach (self::$routes as $r => $c) {
//A custom route is found
if(preg_match($r, $this->path, $matches)) {
if(preg_match($r, self::$path, $matches)) {
$controller = !empty($matches['controller']) ? $matches['controller'] : null;
$function = !empty($matches['function']) ? $matches['function'] : null;
$parameters = !empty($matches['parameters']) ? explode('/', $matches['parameters']) : null;
self::$controller = !empty($matches['controller']) ? $matches['controller'] : null;
self::$function = !empty($matches['function']) ? $matches['function'] : null;
self::$parameters = !empty($matches['parameters']) ? explode('/', $matches['parameters']) : null;
$this->logger->log('Route matched: '.$r);
Logger::log('Route matched: '.$r);
$callable = $c;
break;
self::$callable = $c;
if(!$loadCallable || !self::loadCallable())
break;
}
}
$this->callable = $callable;
$this->controller = $controller;
$this->function = $function;
$this->parameters = $parameters;
// Check if we found a callable anyway
if($this->callable === null){
if(self::$callable === null){
$this->logger->logWarning('No routes found for given path: "'.$this->path.'"', 'Router');
$this->logger->http_error(404);
Logger::log('No routes found for given path: "'.self::$path.'"', E_WARNING);
Logger::http_error(404);
return;
}
}
if($loadCallable)
$this->loadCallable();
}
/**
* Load and execute the callable
*
* @return boolean Whether or not the callable was satisfied
*/
public static function loadCallable(){
/**
* Load and execute the callable
*/
public function loadCallable(){
$this->logger->newLevel('Loading callable');
Logger::newLevel('Loading callable');
// Fire the event to notify our modules
$event = $this->events->fireEvent('routerLoadCallableEvent', $this->callable, $this->controller, $this->function, $this->parameters);
$event = Events::fireEvent('routerLoadCallableEvent', self::$callable, self::$controller, self::$function, self::$parameters);
// The event has been cancelled
if($event->isCancelled()){
if($event->isCancelled())
return false;
return;
}
if(!is_callable(self::$callable))
if(isset(self::$callable['controller'])) {
// Assign everything to the object to make it accessible, but let modules check it first
$this->callable = $event->callable;
$this->controller = $event->controller;
$this->function = $event->function;
$this->parameters = $event->parameters;
self::$controller = isset(self::$callable['controller']) ? self::$callable['controller'] : self::$controller;
self::$function = isset(self::$callable['function']) ? self::$callable['function'] : self::$function;
self::$parameters = isset(self::$callable['parameters']) ? self::$callable['parameters'] : self::$parameters;
if(!is_callable($this->callable))
if(isset($this->callable['controller'])) {
$this->controller = isset($this->callable['controller']) ? $this->callable['controller'] : $this->controller;
$this->function = isset($this->callable['function']) ? $this->callable['function'] : $this->function;
$this->parameters = isset($this->callable['parameters']) ? $this->callable['parameters'] : $this->parameters;
$this->callable = array($this, 'defaultCallable');
self::$callable = array('\FuzeWorks\Router', 'defaultCallable');
}else{
$this->logger->log('The given callable is not callable!', E_ERROR);
$this->error->http_error(500);
$this->logger->stopLevel();
return;
Logger::log('The given callable is not callable!', E_ERROR);
Logger::http_error(500);
Logger::stopLevel();
return true;
}
$args = array(
$this->controller,
$this->function,
$this->parameters,
self::$controller,
self::$function,
self::$parameters,
);
$this->logger->newLevel('Calling Callable');
$this->logger->log('Controller: '. ($args[0] === null ? 'null' : $args[0]));
$this->logger->log('Function: '. ($args[1] === null ? 'null' : $args[1]));
$this->logger->log('Parameters: '. (empty($args[2]) ? '[]' : implode(', ',$args[2])));
$this->logger->stopLevel();
Logger::newLevel('Calling callable');
Logger::log('Controller: '. ($args[0] === null ? 'null' : $args[0]));
Logger::log('Function: '. ($args[1] === null ? 'null' : $args[1]));
Logger::log('Parameters: '. (empty($args[2]) ? '[]' : implode(', ',$args[2])));
Logger::stopLevel();
call_user_func_array($this->callable, $args);
$skip = call_user_func_array(self::$callable, $args) === false;
$this->logger->stopLevel();
if($skip)
Logger::log('Callable not satisfied, skipping to next callable');
Logger::stopLevel();
return $skip;
}
/**
@ -424,22 +427,18 @@ class Router extends Bus{
* This callable will do the 'old skool' routing. It will load the controllers from the controller-directory
* in the application-directory.
*/
public function defaultCallable(){
public static function defaultCallable(){
$this->logger->log('Default callable called!');
Logger::log('Default callable called!');
$this->controller = $this->controller === null ? $this->config->main->default_controller : $this->controller;
$this->function = $this->function === null ? $this->config->main->default_function : $this->function;
self::$controller = self::$controller === null ? Config::get('main')->default_controller : self::$controller;
self::$function = self::$function === null ? Config::get('main')->default_function : self::$function;
// Construct file paths and classes
$class = '\Controller\\'.ucfirst($this->controller);
$file = 'Application/Controller/controller.'.$this->controller.'.php';
$class = '\Controller\\'.ucfirst(self::$controller);
$file = 'Application/Controller/controller.'.self::$controller.'.php';
$this->logger->log('Loading controller '.$class.' from file: '.$file);
// First load the Application init class, so that some important functions can be executed first.
require_once("Application/class.init.php");
$init = new Init($this->core);
Logger::log('Loading controller '.$class.' from file: '.$file);
// Check if the file exists
if(file_exists($file)){
@ -447,24 +446,24 @@ class Router extends Bus{
if(!class_exists($class))
require $file;
$this->callable = new $class($this->core);
self::$callable = new $class();
// Check if method exists or if there is a caller function
if(method_exists($this->callable, $this->function) || method_exists($this->callable, '__call')){
if(method_exists(self::$callable, self::$function) || method_exists(self::$callable, '__call')){
// Execute the function on the controller
$this->callable->{$this->function}($this->parameters);
self::$callable->{self::$function}(self::$parameters);
}else{
// Function could not be found
$this->logger->log('Could not find function '.$this->function.' on controller '.$class);
$this->logger->http_error(404);
Logger::log('Could not find function '.self::$function.' on controller '.$class);
Logger::http_error(404);
}
}else{
// Controller could not be found
$this->logger->log('Could not find controller '.$class);
$this->logger->http_error(404);
Logger::log('Could not find controller '.$class);
Logger::http_error(404);
}
}
}

View File

@ -5,10 +5,6 @@ use \FuzeWorks\Module;
class Main extends Module {
public function __construct(&$core){
parent::__construct($core);
}
public function onLoad() {
require_once($this->getModulePath() . "/class.rest.php");
}

View File

@ -5,10 +5,6 @@ use \FuzeWorks\Module;
class RestApi extends Module {
public function __construct(&$core){
parent::__construct($core);
}
public function onLoad() {}
/**

View File

@ -30,6 +30,8 @@
namespace Module\Database;
use \FuzeWorks\Module;
use \FuzeWorks\Config;
use \FuzeWorks\Logger;
use \PDO;
use \FuzeWorks\DatabaseException;
@ -52,12 +54,8 @@ class Main extends Module {
private $DBH;
public $prefix;
public function __construct(&$core) {
parent::__construct($core);
}
public function onLoad() {
$this->config->dbActive = true;
Config::$dbActive = true;
}
/**
@ -68,7 +66,7 @@ class Main extends Module {
public function connect($config = null) {
// If nothing is given, connect to database from the main config, otherwise use the served configuration
if (is_null($config)) {
$db = $this->mods->config->database;
$db = Config::get('database');
} else {
$db = $config;
}
@ -76,7 +74,7 @@ class Main extends Module {
if (empty($db->type) || empty($db->host)) {
throw (new DatabaseException('Database is not configured!'));
}
// Get the DSN for popular types of databases or a custom DSN
switch (strtolower($db->type)) {
case 'mysql':
@ -89,11 +87,11 @@ class Main extends Module {
}
try {
$this->mods->logger->logInfo("Connecting to '".$dsn."'", "Database");
Logger::logInfo("Connecting to '".$dsn."'", "Database");
// And create the connection
$this->DBH = new PDO($dsn, $db->username, $db->password, (isset($db->options) ? $db->options : null));
$this->DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->mods->logger->logInfo("Connected to database", "Database");
Logger::logInfo("Connected to database", "Database");
// And set the prefix
$this->prefix = $db->prefix;

View File

@ -38,7 +38,7 @@ return array(
'dependencies' => array(),
'events' => array(),
'sections' => array(),
'aliases' => array('techfuze/database'),
'aliases' => array(),
'name' => 'FuzeWorks Database Module',
'description' => 'PDO Wrapper class for FuzeWorks',

View File

@ -47,16 +47,12 @@ class Main extends Module implements ModelServer {
public $primary = 'id';
public $table = '';
public function __construct(&$core){
parent::__construct($core);
}
public function onLoad() {
require_once($this->getModulePath() . '/class.query.php');
}
public function giveModel($type) {
return new Model($this->core);
return new Model();
}
}
@ -76,7 +72,7 @@ class Main extends Module implements ModelServer {
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
* @link http://goframework.net
*/
class Model extends Bus {
class Model {
/**
* @var string The name of the database table

View File

@ -30,7 +30,10 @@
namespace Module\DatabaseUtils;
use \FuzeWorks\Module;
use \FuzeWorks\Modules;
use \FuzeWorks\DatabaseException;
use \FuzeWorks\Config;
use \FuzeWorks\Logger;
/**
@ -66,11 +69,6 @@ class Query extends Module {
*/
private $sth = null;
public function __construct(&$core){
parent::__construct($core);
}
/**
* Default module function on creation
*/
@ -713,7 +711,7 @@ class Query extends Module {
*/
public function commit(){
$this->mods->database->commit();
Modules::get('core/database')->commit();
return $this;
}
@ -723,7 +721,7 @@ class Query extends Module {
*/
public function beginTransaction(){
$this->mods->database->beginTransaction();
Modules::get('core/database')->beginTransaction();
return $this;
}
@ -733,7 +731,7 @@ class Query extends Module {
*/
public function rollback(){
$this->mods->database->rollback();
Modules::get('core/database')->rollback();
return $this;
}
@ -747,12 +745,12 @@ class Query extends Module {
public function execute(){
if($this->config->database->debug)
$this->logger->log("Generated query: ".$this->query, 'QueryBuilder');
if(Config::get('database')->debug)
Logger::log("Generated query: ".$this->query, 'QueryBuilder');
try{
$this->sth = $this->mods->database->prepare($this->query);
$this->sth = Modules::get('core/database')->prepare($this->query);
if(count($this->binds) === 0){
$this->sth->execute();
@ -812,7 +810,7 @@ class Query extends Module {
*/
public function getLastInsertId(){
return $this->mods->database->lastInsertId();
return Modules::get('core/database')->lastInsertId();
}

View File

@ -9,7 +9,7 @@ return array(
'dependencies' => array('core/database'),
'events' => array(),
'sections' => array(),
'aliases' => array('techfuze/databaseutils'),
'aliases' => array(),
'name' => 'FuzeWorks Database Utilities',
'description' => 'Automatically build SQL queries using methods in this class',

View File

@ -32,6 +32,8 @@ namespace Module\Example;
use \FuzeWorks\Module;
use \FuzeWorks\Event;
use \FuzeWorks\EventPriority;
use \FuzeWorks\Events;
use \FuzeWorks\Logger;
/**
* Example module.
@ -51,7 +53,7 @@ class Main extends Module {
*/
public function onLoad() {
// Here we register an eventListener for the ExampleEvent. See ExampleListener for more info
$this->events->addListener(array($this, 'exampleListener'), 'ExampleEvent', EventPriority::NORMAL);
Events::addListener(array($this, 'exampleListener'), 'ExampleEvent', EventPriority::NORMAL);
}
/**
@ -68,7 +70,7 @@ class Main extends Module {
* @return ExampleEvent The event after it has been handled
*/
public function exampleListener($event) {
$this->logger->log("Called the eventListener. This listener can now handle the event and change some data");
Logger::log("Called the eventListener. This listener can now handle the event and change some data");
// For this listener, we only change one variable
$event->setVariable("New Value");
@ -81,14 +83,14 @@ class Main extends Module {
*/
public function createEvent() {
// First we log some data
$this->logger->log("Now creating a test event.");
Logger::log("Now creating a test event.");
// First we create the event object and some variables to assign to it
$eventObject = new ExampleEvent();
$variable = "Test Variable";
// Then we fire the event by parsing the event object and the variables into the fireEvent function.
$event = $this->events->fireEvent($eventObject, $variable);
$event = Events::fireEvent($eventObject, $variable);
// Here we can read some variables from the event
$result = $event->getVariable();

View File

@ -43,7 +43,7 @@ return array(
'abstract' => false,
// Other names for this module. Setting an alias will allow you to load the module with a different name.
'aliases' => array('techfuze/example'),
'aliases' => array(),
// Array of modules that should be loaded before this module
'dependencies' => array(),

View File

@ -30,6 +30,7 @@
namespace Module\Mailer;
use \FuzeWorks\Module;
use \FuzeWorks\Config;
use \PHPMailer;
/**
@ -54,7 +55,7 @@ use \PHPMailer;
* @access public
*/
public function onLoad() {
$this->cfg = $this->config->loadConfigFile('mailer', $this->getModulePath());
$this->cfg = Config::loadConfigFile('mailer', $this->getModulePath());
}
/**

View File

@ -33,7 +33,7 @@ return array(
# Sendmail Settings
'sendmail_enabled' => true,
# SMTP Settings
# SMTP Settings
'smtp_enabled' => false,
'smtp_host' => '',
'smtp_port' => 25,

View File

@ -35,7 +35,7 @@ return array(
'module_name' => 'Mailer',
'dependencies' => array(),
'aliases' => array('techfuze/mailer'),
'aliases' => array(),
'name' => 'Mailer',
'description' => 'PHPMailer wrapper for FuzeWorks',

View File

@ -4,9 +4,6 @@ namespace Controller;
use \FuzeWorks\Controller;
class Standard extends Controller {
public function __construct(&$core) {
parent::__construct($core);
}
public function index($path = null) {
}

View File

@ -31,6 +31,11 @@
namespace Module\Users;
use \FuzeWorks\Module;
use \FuzeWorks\EventPriority;
use \FuzeWorks\Config;
use \FuzeWorks\Modules;
use \FuzeWorks\Events;
use \FuzeWorks\Logger;
use \FuzeWorks\Layout;
/**
* Main class of the Sessions and User Management module.
@ -61,8 +66,8 @@ class Users extends Module {
*/
public function onLoad() {
require_once($this->getmodulePath() . "/class.events.php");
$this->setModuleConfig($this->config->loadConfigFile('sessions', $this->getModulePath()));
$this->db = &$this->mods->database;
$this->setModuleConfig(Config::loadConfigFile('sessions', $this->getModulePath()));
$this->db = Modules::get('core/database');
}
/**
@ -96,12 +101,12 @@ class Users extends Module {
$udt = $this->getGuestUdt();
$user_id = 0;
$username = 'Guest';
$email = 'Guest@'.$this->config->main->SITE_DOMAIN;
$email = 'Guest@'.Config::get('main')->SITE_DOMAIN;
$guest_session = true;
}
// Fire the event
$event = $this->events->fireEvent(new SessionStartEvent(), $user_id, $username, $email, $udt, $guest_session);
$event = Events::fireEvent(new SessionStartEvent(), $user_id, $username, $email, $udt, $guest_session);
if ($event->isCancelled() || $event->guest_session) {
return $this->sendUserSession($udt);
}
@ -120,7 +125,7 @@ class Users extends Module {
*/
private function sendGuestSession() {
if (isset($_COOKIE[$this->cfg->cookie_name])) {
setcookie($this->cfg->cookie_name, '', time()-3600, '/', $this->config->main->SITE_DOMAIN);
setcookie($this->cfg->cookie_name, '', time()-3600, '/', Config::get('main')->SITE_DOMAIN);
}
$udt = $this->getGuestUdt();
$this->udt = $udt;
@ -138,8 +143,8 @@ class Users extends Module {
'user_id' => 0,
'user_username' => 'Guest',
'username' => 'Guest',
'user_email' => 'Guest@'.$this->config->main->SITE_DOMAIN,
'email' => 'Guest@'.$this->config->main->SITE_DOMAIN,
'user_email' => 'Guest@'.Config::get('main')->SITE_DOMAIN,
'email' => 'Guest@'.Config::get('main')->SITE_DOMAIN,
'permissions' => array('GUEST' => 'GUEST', 'LOGIN' => 'LOGIN'),
'session_hash' => '0'
);
@ -165,9 +170,9 @@ class Users extends Module {
* @access private
*/
private function logSessionData() {
$this->logger->newLevel("Activating Session");
$this->logger->logInfo("<br />SessionKey: " . $this->session_hash . "<br />Username: " . $this->user_username . "<br/>Email: " . $this->user_email . "<br/>Permissions: " . implode('-', $this->permissions));
$this->logger->stopLevel();
Logger::newLevel("Activating Session");
Logger::logInfo("<br />SessionKey: " . $this->session_hash . "<br />Username: " . $this->user_username . "<br/>Email: " . $this->user_email . "<br/>Permissions: " . implode('-', $this->permissions));
Logger::stopLevel();
}
/**
@ -310,7 +315,7 @@ class Users extends Module {
// Broadcast data with an event
if ($valid) {
// If valid, provide all required data
$event = $this->events->fireEvent(new SessionLoginEvent(),
$event = Events::fireEvent(new SessionLoginEvent(),
$identifier,
$password,
$remember_me,
@ -320,7 +325,7 @@ class Users extends Module {
);
} else {
// If not, provide only the identifiers
$event = $this->events->fireEvent(new SessionLoginEvent(), $identifier, $password, $remember_me);
$event = Events::fireEvent(new SessionLoginEvent(), $identifier, $password, $remember_me);
}
// Firest check for full blown deny
@ -380,7 +385,7 @@ class Users extends Module {
$stmnt->execute($insert_array);
if ($stmnt->rowCount() == 1) {
// Set the cookie
setcookie($this->cfg->cookie_name, $sessionData['hash'], $sessionData['valid_time'], '/', $this->config->main->SITE_DOMAIN);
setcookie($this->cfg->cookie_name, $sessionData['hash'], $sessionData['valid_time'], '/', Config::get('main')->SITE_DOMAIN);
return true;
} else {
throw new SessionException("Could not log user in. Database error", 1);
@ -411,7 +416,7 @@ class Users extends Module {
$user_id = $data[0]['user_id'];
// Then fire the event
$event = $this->events->fireEvent(new SessionLogoutEvent(), $user_id, $username, $email);
$event = Events::fireEvent(new SessionLogoutEvent(), $user_id, $username, $email);
if ($event->isCancelled()) {
return false;
}
@ -428,7 +433,7 @@ class Users extends Module {
// And after that remove the cookie
if ($stmnt->rowCount() == 1) {
// Set the cookie
setcookie($this->cfg->cookie_name, $sessionKey, date('U') - 3600, '/', $this->config->main->SITE_DOMAIN);
setcookie($this->cfg->cookie_name, $sessionKey, date('U') - 3600, '/', Config::get('main')->SITE_DOMAIN);
return true;
}
@ -471,7 +476,7 @@ class Users extends Module {
}
// Fire the event
$event = $this->events->fireEvent(new SessionRegisterEvent(), $username, $email, $password);
$event = Events::fireEvent(new SessionRegisterEvent(), $username, $email, $password);
if ($event->isCancelled()) {
return false;
}
@ -500,7 +505,7 @@ class Users extends Module {
// Check for the existence of an account
$qry = "SELECT * FROM hi_session_users WHERE user_username = :username OR user_email = :email";
$stmnt = $this->mods->database->prepare($qry);
$stmnt = Modules::get('core/database')->prepare($qry);
$stmnt->execute(['username' => $username, 'email' => $email]);
$data = $stmnt->fetch(\PDO::FETCH_ASSOC);
if (empty($data)) {
@ -509,22 +514,22 @@ class Users extends Module {
$qry1 = "INSERT INTO ".$prefix."session_users (user_username,user_password,user_email,verify_code) VALUES (:username,:password,:email,:verify_code)";
$qry2 = "INSERT INTO ".$prefix."session_permissions (permission_tag_id,permission_user_id) VALUES (:tag_id,:user_id)";
$this->mods->database->beginTransaction();
$stmnt1 = $this->mods->database->prepare($qry1);
$stmnt2 = $this->mods->database->prepare($qry2);
Modules::get('core/database')->beginTransaction();
$stmnt1 = Modules::get('core/database')->prepare($qry1);
$stmnt2 = Modules::get('core/database')->prepare($qry2);
$stmnt1->execute(['username' => $username, 'password' => $password, 'email' => $email, 'verify_code' => substr(sha1(uniqid()), 0, 15)]);
$id = $this->mods->database->lastInsertId();
$id = Modules::get('core/database')->lastInsertId();
$stmnt2->execute(['tag_id' => 1, 'user_id' => $id]);
// And then fire the event
$event = $this->events->fireEvent(new SessionUserCreateEvent(), $user_id, $username, $password);
$event = Events::fireEvent(new SessionUserCreateEvent(), $user_id, $username, $password);
if ($event->isCancelled()) {
$this->mods->database->rollBack();
Modules::get('core/database')->rollBack();
return false;
}
$this->mods->database->commit();
Modules::get('core/database')->commit();
// After that send a registration mail
if ($send_email) {
@ -553,22 +558,22 @@ class Users extends Module {
$udt = $udt[0];
// Load the mailer module
$mailer = $this->core->loadMod('techfuze/mailer')->mailer;
$mailer->setFrom('no-reply@'.$this->config->main->SITE_DOMAIN, 'Auth Service');
$mailer = Modules::get('core/mailer')->mailer;
$mailer->setFrom('no-reply@'.Config::get('main')->SITE_DOMAIN, 'Auth Service');
// First prepare the layout manager
$this->layout->setEngine('PHP');
Layout::setEngine('PHP');
// Assign all variables
$verifyCode = $udt['user_verify_code'];
if (empty($this->cfg->verify_controller) && $verify) {
throw new SessionException("Could not send mail. No verification controller set. Please set one in the sessions config.", 1);
}
$verifyURL = $this->config->main->SITE_URL . "/" . $this->cfg->verify_controller . "?verify&code=".$verifyCode;
$verifyURL = Config::get('main')->SITE_URL . "/" . $this->cfg->verify_controller . "?verify&code=".$verifyCode;
$event = $this->events->fireEvent(new SessionRegisterMailEvent(), $udt, $verifyCode, $verifyURL);
$event = Events::fireEvent(new SessionRegisterMailEvent(), $udt, $verifyCode, $verifyURL);
if ($event->isCancelled()) {
$this->logger->log("Sending of Registration Mail has been cancelled");
Logger::log("Sending of Registration Mail has been cancelled");
return false;
}
@ -576,12 +581,12 @@ class Users extends Module {
$udt = $event->udt;
// Assign new variables
$this->layout->assign('username', $udt['user_username']);
$this->layout->assign('email', $udt['user_email'] );
Layout::assign('username', $udt['user_username']);
Layout::assign('email', $udt['user_email'] );
// More if there is a need to verify
if ($verify) {
$this->layout->assign('verifyURL', $event->verifyURL);
Layout::assign('verifyURL', $event->verifyURL);
}
// Check if a custom HTML should be used
@ -589,14 +594,14 @@ class Users extends Module {
$html = $event->html;
} else {
// Or retrieve it from a layout file
$html = $this->layout->get('email_layout', $this->getModulePath() . "/Views/" );
$html = Layout::get('email_layout', $this->getModulePath() . "/Views/" );
}
// And finally send it
$mailer->addAddress($udt['email']);
$mailer->isHTML(true);
$mailer->Body = $html;
$mailer->Subject = $this->config->main->SERVER_NAME . " | Registration";
$mailer->Subject = Config::get('main')->SERVER_NAME . " | Registration";
$mailer->send();
if (!empty($mailer->ErrorInfo)) {
// Throw Exception if something goes wrong
@ -622,14 +627,14 @@ class Users extends Module {
$from = $udt[$key];
// Then fire the event
$event = $this->events->fireEvent(new SessionUserModifyEvent(), $userId, $key, $value, $from);
$event = Events::fireEvent(new SessionUserModifyEvent(), $userId, $key, $value, $from);
if ($event->isCancelled()) {
return false;
}
// And fetch tag information
$prefix = $this->db->getPrefix();
$stmnt = $this->mods->database->prepare("UPDATE ".$prefix."session_users SET $key = ?");
$stmnt = Modules::get('core/database')->prepare("UPDATE ".$prefix."session_users SET $key = ?");
$stmnt->execute([$value]);
if ($stmnt->rowCount() == 1) {
return true;
@ -655,7 +660,7 @@ class Users extends Module {
// First check if the oldPassword is correct
if (is_null($oldPassword) || password_verify($oldPassword, $udt['user_password'])) {
// Send out the event
$event = $this->events->fireEvent(new SessionChangePasswordEvent(),
$event = Events::fireEvent(new SessionChangePasswordEvent(),
$userId,
$udt['user_username'],
$oldPassword,
@ -691,7 +696,7 @@ class Users extends Module {
$email = $udt['user_email'];
// Then fire the event
$event = $this->events->fireEvent(new SessionUserSuspendEvent(), $user_id, $username, $email);
$event = Events::fireEvent(new SessionUserSuspendEvent(), $user_id, $username, $email);
// Cancel if denied by module
if ($event->isCancelled()) {
@ -716,7 +721,7 @@ class Users extends Module {
$email = $udt['user_email'];
// Then fire the event
$event = $this->events->fireEvent(new SessionUserUnsuspendEvent(), $user_id, $username, $email);
$event = Events::fireEvent(new SessionUserUnsuspendEvent(), $user_id, $username, $email);
// Cancel if denied by module
if ($event->isCancelled()) {
@ -741,7 +746,7 @@ class Users extends Module {
$email = $udt['user_email'];
// Then fire an event
$event = $this->events->fireEvent(new SessionUserRemoveEvent(), $userId, $username, $email);
$event = Events::fireEvent(new SessionUserRemoveEvent(), $userId, $username, $email);
if ($event->isCancelled()) {
return false;
}
@ -760,7 +765,7 @@ class Users extends Module {
public function verifyUser($verifyCode) {
// And fetch tag information
$prefix = $this->db->getPrefix();
$stmnt = $this->mods->database->prepare("SELECT * FROM ".$prefix."session_users WHERE user_verify_code = ?");
$stmnt = Modules::get('core/database')->prepare("SELECT * FROM ".$prefix."session_users WHERE user_verify_code = ?");
$stmnt->execute([$verifyCode]);
$data = $stmnt->fetchAll(\PDO::FETCH_ASSOC);
if (count($data == 1)) {
@ -779,7 +784,7 @@ class Users extends Module {
*/
public function verifyPassword($userId, $password) {
$prefix = $this->db->getPrefix();
$stmnt = $this->mods->database->prepare("SELECT * FROM ".$prefix."session_users WHERE user_id = ?");
$stmnt = Modules::get('core/database')->prepare("SELECT * FROM ".$prefix."session_users WHERE user_id = ?");
$stmnt->execute([$userId]);
$data = $stmnt->fetchAll(\PDO::FETCH_ASSOC);
if (!empty($data)) {
@ -868,7 +873,7 @@ class Users extends Module {
// And fetch tag information
$prefix = $this->db->getPrefix();
$stmnt = $this->mods->database->prepare("SELECT * FROM ".$prefix."session_tags WHERE tag_name = ?");
$stmnt = Modules::get('core/database')->prepare("SELECT * FROM ".$prefix."session_tags WHERE tag_name = ?");
$stmnt->execute([strtoupper($permissionTag)]);
$tag = $stmnt->fetch(\PDO::FETCH_ASSOC);
if (!empty($tag)) {
@ -876,16 +881,16 @@ class Users extends Module {
}
// And now remove the reference in the database
$stmnt = $this->mods->database->prepare("DELETE FROM ".$prefix."session_permissions WHERE permission_tag_id = :tag_id AND permission_user_id = :user_id");
$stmnt = Modules::get('core/database')->prepare("DELETE FROM ".$prefix."session_permissions WHERE permission_tag_id = :tag_id AND permission_user_id = :user_id");
$stmnt->execute(['tag_id' => $tag_id, 'user_id' => $user_id]);
if ($stmnt->rowCount() == 1) {
// Check if the tag is still used
if ($removeTag) {
$stmnt = $this->mods->database->prepare("SELECT * FROM ".$prefix."session_permissions WHERE permission_tag_id = ?");
$stmnt = Modules::get('core/database')->prepare("SELECT * FROM ".$prefix."session_permissions WHERE permission_tag_id = ?");
$stmnt->execute([strtoupper($permissionTag)]);
if (count($stmnt->fetchAll(\PDO::FETCH_ASSOC)) == 0) {
// Remove the tag
$stmnt = $this->mods->database->prepare("DELETE FROM ".$prefix."session_tags WHERE tag_name = ?");
$stmnt = Modules::get('core/database')->prepare("DELETE FROM ".$prefix."session_tags WHERE tag_name = ?");
$stmnt->execute([strtoupper($permissionTag)]);
if ($stmnt->rowCount() == 0) {
// Something went wrong
@ -928,13 +933,13 @@ class Users extends Module {
// Check if the tag already exists
$prefix = $this->db->getPrefix();
$stmnt = $this->mods->database->prepare("SELECT * FROM ".$prefix."session_tags WHERE tag_name = ?");
$stmnt = Modules::get('core/database')->prepare("SELECT * FROM ".$prefix."session_tags WHERE tag_name = ?");
$stmnt->execute([strtoupper($permissionTag)]);
$d = $stmnt->fetchAll(\PDO::FETCH_ASSOC);
if (count($d) == 0) {
// Create tag
$stmnt = $this->mods->database->prepare("INSERT INTO ".$prefix."session_tags (tag_name) VALUES (:tag_name)");
$stmnt = Modules::get('core/database')->prepare("INSERT INTO ".$prefix."session_tags (tag_name) VALUES (:tag_name)");
$stmnt->execute(['tag_name' => strtoupper($permissionTag)]);
$id = $stmnt->lastInsertId();
} elseif (count($d) == 1) {
@ -944,7 +949,7 @@ class Users extends Module {
}
// Add the permission
$stmnt = $this->mods->database->prepare("INSERT INTO ".$prefix."session_permissions (permission_tag_id,permission_user_id) VALUES (:permission_tag_id,:permission_user_id)");
$stmnt = Modules::get('core/database')->prepare("INSERT INTO ".$prefix."session_permissions (permission_tag_id,permission_user_id) VALUES (:permission_tag_id,:permission_user_id)");
$stmnt->execute(['permission_tag_id' => $id, 'permission_user_id' => $user_id]);
if ($stmnt->rowCount() == 1) {
@ -977,7 +982,7 @@ class Users extends Module {
WHERE users.user_username = ?
";
$stmnt = $this->mods->database->prepare($query);
$stmnt = Modules::get('core/database')->prepare($query);
$users = array();
for ($i=0; $i < count($usernames); $i++) {
$username = $usernames[$i];
@ -1014,7 +1019,7 @@ class Users extends Module {
WHERE users.user_id = ?
";
$stmnt = $this->mods->database->prepare($query);
$stmnt = Modules::get('core/database')->prepare($query);
$users = array();
for ($i=0; $i < count($ids); $i++) {
$id = $ids[$i];
@ -1051,7 +1056,7 @@ class Users extends Module {
WHERE users.user_email = ?
";
$stmnt = $this->mods->database->prepare($query);
$stmnt = Modules::get('core/database')->prepare($query);
$users = array();
for ($i=0; $i < count($emails); $i++) {
$email = $emails[$i];
@ -1087,7 +1092,7 @@ class Users extends Module {
WHERE tags.tag_name = ?
";
$stmnt = $this->mods->database->prepare($query);
$stmnt = Modules::get('core/database')->prepare($query);
$users = array();
for ($i=0; $i < count($permissionTags); $i++) {
$tag = $permissionTags[$i];

View File

@ -33,6 +33,6 @@ return array(
'cookie_name' => 'FuzeCookie',
// Should be filled in if you want email verification to work
'verify_controller' => 'login',
'verify_controller' => '',
);

View File

@ -35,7 +35,7 @@ return array(
'module_name' => 'users',
'dependencies' => array('core/database'),
'aliases' => array('techfuze/sessions'),
'aliases' => array(),
'events' => array(),
'name' => 'Users',

View File

@ -28,13 +28,17 @@
* @version Version 0.0.1
*/
use \FuzeWorks\Core;
use \FuzeWorks\Router;
// Include framework
require_once( dirname(__FILE__) . "/Core/System/class.core.php");
// Load it
$core = new \FuzeWorks\Core();
$core->init();
$core->mods->router->setPath( (isset($_GET['path']) ? $_GET['path'] : null) );
$core->mods->router->route();
new Core();
Core::init();
Router::setPath( (isset($_GET['path']) ? $_GET['path'] : null) );
Router::route();
?>