Merge branch 'master' into Issue_#7,_Continuous_Integration
Conflicts: index.php
This commit is contained in:
commit
58f0910f63
@ -1,5 +0,0 @@
|
||||
<?php return array (
|
||||
'register' =>
|
||||
array (
|
||||
),
|
||||
) ;
|
@ -2,7 +2,6 @@
|
||||
'SITE_URL' => '',
|
||||
'SITE_DOMAIN' => '',
|
||||
'SERVER_NAME' => '',
|
||||
'registers_update_interval' => 3600,
|
||||
'administrator_mail' => '',
|
||||
'default_controller' => 'standard',
|
||||
'default_function' => 'index',
|
||||
|
@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
class Standard extends Bus {
|
||||
namespace Controller;
|
||||
use \FuzeWorks\Controller;
|
||||
|
||||
class Standard extends Controller {
|
||||
public function __construct(&$core) {
|
||||
parent::__construct($core);
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Model;
|
||||
use \FuzeWorks\Model;
|
||||
|
||||
class Example extends Model{
|
||||
|
||||
public function __construct(&$core){
|
||||
|
22
Core/Events/event.controllerLoadEvent.php
Normal file
22
Core/Events/event.controllerLoadEvent.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use \FuzeWorks\Event;
|
||||
|
||||
class ControllerLoadEvent extends Event {
|
||||
|
||||
public $route;
|
||||
public $controllerName;
|
||||
public $function;
|
||||
public $parameters;
|
||||
public $directory;
|
||||
|
||||
public function init($route, $controllerName, $function, $parameters, $directory) {
|
||||
$this->route = $route;
|
||||
$this->controllerName = $controllerName;
|
||||
$this->function = $function;
|
||||
$this->parameters = $parameters;
|
||||
$this->directory = $directory;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
class EventRegisterBuildEvent extends Event {
|
||||
|
||||
public $register = array();
|
||||
|
||||
public function init($call){}
|
||||
|
||||
public function addEvent($modName, $eventName) {
|
||||
if (!isset($this->register[$eventName])) {
|
||||
$this->register[$eventName] = array();
|
||||
}
|
||||
$this->register[$eventName][] = $modName;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
15
Core/Events/event.layoutLoadEvent.php
Normal file
15
Core/Events/event.layoutLoadEvent.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use \FuzeWorks\Event;
|
||||
|
||||
class LayoutLoadEvent extends Event {
|
||||
|
||||
public $directory;
|
||||
public $layout;
|
||||
|
||||
public function init($layout){
|
||||
$this->layout = $layout;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
15
Core/Events/event.modelLoadEvent.php
Normal file
15
Core/Events/event.modelLoadEvent.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use \FuzeWorks\Event;
|
||||
|
||||
class ModelLoadEvent extends Event {
|
||||
|
||||
public $directory;
|
||||
public $model;
|
||||
|
||||
public function init($model){
|
||||
$this->model = $model;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use \FuzeWorks\Event;
|
||||
|
||||
class RouterRouteEvent extends Event {
|
||||
|
||||
public $controller;
|
||||
|
@ -1,145 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Database extends Bus {
|
||||
|
||||
private $DBH;
|
||||
public $prefix;
|
||||
|
||||
public function __construct(&$core) {
|
||||
parent::__construct($core);
|
||||
}
|
||||
|
||||
public function onLoad() {
|
||||
$this->connect($this->getSystemDbSettings());
|
||||
$this->config->dbActive = true;
|
||||
}
|
||||
|
||||
public function connect($params = array()) {
|
||||
if (isset($params['type'])) {
|
||||
$type = $params['type'];
|
||||
} else {
|
||||
throw (new Exception("No database type given"));
|
||||
}
|
||||
|
||||
if (isset($params['datb'])) {
|
||||
$database = $params['datb'];
|
||||
} else {
|
||||
throw (new Exception("No database given. Can not connect without database."));
|
||||
}
|
||||
|
||||
if (isset($params['host'])) {
|
||||
$host = $params['host'];
|
||||
} else {
|
||||
throw (new Exception("No database host given. Can not connect without hostname."));
|
||||
}
|
||||
|
||||
$username = $params['user'];
|
||||
$password = $params['pass'];
|
||||
$this->prefix = $params['prefix'];
|
||||
|
||||
if (isset($params['options'])) {
|
||||
$options = $params['options'];
|
||||
} else {
|
||||
$options = null;
|
||||
}
|
||||
|
||||
|
||||
$DSN_FINAL = "";
|
||||
|
||||
switch ($type) {
|
||||
case 'MYSQL':
|
||||
$DSN = "mysql:host=";
|
||||
$DSN2 = ";dbname=";
|
||||
|
||||
// Check if charset is required
|
||||
if (isset($extraOptions)) {
|
||||
if (isset($extraOptions->charset)) {
|
||||
$DSN3 = ";charset=" . $extraOptions->charset;
|
||||
} else {
|
||||
$DSN3 = ";";
|
||||
}
|
||||
} else {
|
||||
$DSN3 = ";";
|
||||
}
|
||||
$DSN_FINAL = $DSN . $host . $DSN2 . $database . $DSN3;
|
||||
break;
|
||||
case 'sqlite':
|
||||
$DSN = 'sqlite:' . $host . ($database != '' ? ";dbname=" .$database : "");
|
||||
$DSN_FINAL = $DSN;
|
||||
break;
|
||||
default:
|
||||
throw (new Exception("Unknown database type given: '" . $type . "'"));
|
||||
break;
|
||||
}
|
||||
|
||||
// Try and connect
|
||||
try{
|
||||
$this->mods->logger->logInfo("Connecting to '" . $DSN_FINAL. "'", "Database", __FILE__, __LINE__);
|
||||
$this->DBH = new \PDO($DSN_FINAL, $username, $password, $options);
|
||||
$this->DBH->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$this->mods->logger->logInfo("Connected!", "Database", __FILE__, __LINE__);
|
||||
}catch(\PDOException $e){
|
||||
throw (new Exception('Could not connect to the database: "'. $e->getMessage() . '"'));
|
||||
}
|
||||
}
|
||||
|
||||
public function __call($name, $params) {
|
||||
if ($this->is_active()) {
|
||||
return call_user_func_array(array($this->DBH, $name), $params);
|
||||
} else {
|
||||
$this->connect($this->getSystemDbSettings());
|
||||
return call_user_func_array(array($this->DBH, $name), $params);
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
if ($this->is_active()) {
|
||||
return $this->DBH->$name;
|
||||
} else {
|
||||
$this->connect($this->getSystemDbSettings());
|
||||
return $this->DBH->$name;
|
||||
}
|
||||
}
|
||||
|
||||
public function __set($name, $value) {
|
||||
if ($this->is_active()) {
|
||||
$this->DBH->$name = $value;
|
||||
} else {
|
||||
$this->connect($this->getSystemDbSettings());
|
||||
$this->DBH->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function is_active() {
|
||||
if($this->DBH === null){
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPrefix() {
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an array of the system DB settings. This is the configuration in the config file of FuzeWorks
|
||||
* @access public
|
||||
* @return DBSettings array
|
||||
*/
|
||||
public function getSystemDbSettings() {
|
||||
$dbsettings = array(
|
||||
'type' => $this->mods->config->database->type,
|
||||
'host' => $this->mods->config->database->host,
|
||||
'user' => $this->mods->config->database->username,
|
||||
'pass' => $this->mods->config->database->password,
|
||||
'datb' => $this->mods->config->database->database,
|
||||
'prefix' => $this->mods->config->database->prefix,
|
||||
);
|
||||
return $dbsettings;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -1,154 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Sections module, see usage documentation
|
||||
* @author TechFuze
|
||||
*/
|
||||
class Sections extends Module {
|
||||
|
||||
/**
|
||||
* The config holder for this module. Holds an StdObject
|
||||
* @access public
|
||||
* @var StdObject Module Config
|
||||
*/
|
||||
public $cfg;
|
||||
|
||||
/**
|
||||
* The current section that we are using right now!
|
||||
* @access private
|
||||
* @var String name of section or null
|
||||
*/
|
||||
private $currentSection = null;
|
||||
|
||||
/**
|
||||
* Loads the module and registers the events
|
||||
* @access public
|
||||
*/
|
||||
public function onLoad() {
|
||||
// Load module configuration
|
||||
$this->cfg = $this->config->loadConfigFile('sections', $this->getModulePath());
|
||||
|
||||
// Register Events
|
||||
$this->events->addListener(array($this, 'eventRegisterBuild'), 'eventRegisterBuildEvent', EventPriority::NORMAL);
|
||||
$this->events->addListener(array($this, 'routerEvent'), 'routerRouteEvent', EventPriority::NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this module in the eventRegister for routerRouteEvent
|
||||
* @access public
|
||||
* @param eventRegisterBuildEvent Event
|
||||
* @return eventRegisterBuildEvent Event
|
||||
*/
|
||||
public function eventRegisterBuild($event) {
|
||||
$event->addEvent('sections', 'routerRouteEvent');
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a section to the config file
|
||||
* @access public
|
||||
* @param String section_name, name of the section
|
||||
* @param Boolean module_section wether this is a module_section
|
||||
* @param String module_name to use when this is a module_section
|
||||
* @param String Controller_path, where to find the controllers for this section
|
||||
* @param String Model_path, where to find the models for this section
|
||||
* @param String View_path, where to find the views for this section
|
||||
*/
|
||||
public function addSection($name, $module_section = false, $module_name = null, $controller_path = null, $model_path = null, $view_path = null) {
|
||||
$data = array(
|
||||
'name' => $name,
|
||||
'module_section' => $module_section,
|
||||
'module_name' => $module_name,
|
||||
'controller_path' => FUZEPATH . $controller_path,
|
||||
'model_path' => FUZEPATH . $model_path,
|
||||
'view_path' => FUZEPATH . $view_path,
|
||||
);
|
||||
$this->config->set('sections', $name, $data, $this->getModulePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a section from the config file
|
||||
* @access public
|
||||
* @param String section_name, name of the section to remove
|
||||
*/
|
||||
public function removeSection($name) {
|
||||
$this->config->set('sections', $name, null, $this->getModulePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's called on routerRouteEvent. Redirects when a section is found
|
||||
* @access public
|
||||
* @param routerRouteEvent Event
|
||||
* @return routerRouteEvent Event
|
||||
*/
|
||||
public function routerEvent($event) {
|
||||
$name = $event->controller;
|
||||
$controller = null;
|
||||
$function = null;
|
||||
$parameters = array();
|
||||
$section = $this->{$name};
|
||||
|
||||
if ($section !== null) {
|
||||
// Section found
|
||||
$this->logger->log("Section found with name: '".$name."'", 'Sections');
|
||||
$this->currentSection = $name;
|
||||
|
||||
// Logic here, first for module sections
|
||||
if ($section['module_section']) {
|
||||
$mod = $this->core->loadMod($section['module_name']);
|
||||
$event->directory = $mod->getModulePath() . "/Controller/";
|
||||
} else {
|
||||
// Now for regular sections
|
||||
$event->directory = $section['controller_path'];
|
||||
}
|
||||
|
||||
// Move the path so it matches the new regime
|
||||
if (count($event->parameters) > 0) {
|
||||
$function = $event->parameters[0];
|
||||
$parameters = array_slice($event->parameters, 1);
|
||||
} else {
|
||||
$function = $this->config->main->default_function;
|
||||
}
|
||||
|
||||
// And finally set the controller, if no parameters are set, load the default function
|
||||
$controller = (!empty($event->function) ? $event->function : $this->config->main->default_controller );
|
||||
} else {
|
||||
$this->logger->log("No section was found with name: '".$name."'", 'Sections');
|
||||
}
|
||||
|
||||
if($controller !== null)$event->controller = $controller;
|
||||
if($function !== null)$event->function = $function;
|
||||
if(count($parameters) !== 0)$event->parameters = $parameters;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves section information from the config file
|
||||
* @access public
|
||||
* @param String section_name, name of the section
|
||||
* @return Array section_information or null
|
||||
*/
|
||||
public function __get($name){
|
||||
// Something given?
|
||||
if(empty($name)) {
|
||||
// Currently in a section?
|
||||
if($this->currentSection !== null){
|
||||
// Return that one then
|
||||
return $this->cfg[$this->currentSection];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return element $name of the config file
|
||||
if (isset($this->cfg->$name)) {
|
||||
$section = $this->cfg->$name;
|
||||
} else {
|
||||
$section = null;
|
||||
}
|
||||
|
||||
return $section;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1 +0,0 @@
|
||||
<?php return 1;
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
class Interpret extends Model {
|
||||
|
||||
public function __construct(&$core){
|
||||
@ -21,17 +23,6 @@ class Interpret extends Model {
|
||||
// Append to model
|
||||
$this->fields = $table_fields;
|
||||
}
|
||||
|
||||
public function toPHP() {
|
||||
$values = array();
|
||||
foreach ($this->fields as $key => $value) {
|
||||
$values[] = '"'.$value.'"';
|
||||
}
|
||||
$values = implode(', ', $values);
|
||||
$text = 'VALUES: array('.$values.')
|
||||
TABLE: '.$this->table;
|
||||
echo $text;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
abstract class Bus {
|
||||
protected $core;
|
||||
protected $mods;
|
||||
|
78
Core/System/class.abstract.controller.php
Normal file
78
Core/System/class.abstract.controller.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Interface for a Module that gives abstract Controller types
|
||||
* A Controller server must contain the methods from this interface in order to correctly serve Controllers
|
||||
*/
|
||||
interface ControllerServer {
|
||||
public function giveController($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract class Controller
|
||||
*
|
||||
* Abstract for a Controller data representation, loads the correct parent type
|
||||
*/
|
||||
abstract class Controller extends Bus{
|
||||
|
||||
/**
|
||||
* The parent class holder object
|
||||
* Requests get redirected to this class
|
||||
* @access private
|
||||
* @var Parent Object
|
||||
*/
|
||||
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 Controller. Eg, use techfuze/databaseController and DatabaseController to get a SQL connected Controller
|
||||
* @access protected
|
||||
* @param String Module_name, the name of the module where the Controller can be found
|
||||
* @param String Controller_type, Controller type to return
|
||||
*/
|
||||
protected function setType($module_name, $controller_type) {
|
||||
$mod = $this->core->loadMod($module_name);
|
||||
$this->parentClass = $mod->giveController($controller_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value from the controller class
|
||||
* @access public
|
||||
* @param Any key
|
||||
* @return Any value from the controller class
|
||||
*/
|
||||
public function __get($name) {
|
||||
return $this->parentClass->$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value in the controller class
|
||||
* @access public
|
||||
* @param Any key
|
||||
* @param Any value
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
$this->parentClass->$name = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a function in the controller class
|
||||
* @access public
|
||||
* @param String function_name
|
||||
* @param Array values
|
||||
* @return Function return
|
||||
*/
|
||||
public function __call($name, $params) {
|
||||
return call_user_func_array(array($this->parentClass, $name), $params);
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
class Event {
|
||||
|
||||
private $cancelled = false;
|
||||
@ -17,4 +19,6 @@ class Event {
|
||||
}
|
||||
}
|
||||
|
||||
class NotifierEvent extends Event {}
|
||||
|
||||
?>
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Class EventPriority
|
||||
*
|
||||
|
@ -1,5 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Interface for a Module that gives abstract model types
|
||||
* A model server must contain the methods from this interface in order to correctly serve models
|
||||
*/
|
||||
interface ModelServer {
|
||||
public function giveModel($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract class Model
|
||||
*
|
||||
@ -28,11 +38,11 @@ abstract class Model extends Bus{
|
||||
* Set the type of this model. Eg, use techfuze/databasemodel and Databasemodel to get a SQL connected model
|
||||
* @access protected
|
||||
* @param String Module_name, the name of the module where the model can be found
|
||||
* @param String class name, the class to load and connect to
|
||||
* @param String Model_type, model type to return
|
||||
*/
|
||||
protected function setType($module_name, $class_name) {
|
||||
$this->core->loadMod($module_name);
|
||||
$this->parentClass = new $class_name($this->core);
|
||||
protected function setType($module_name, $model_type) {
|
||||
$mod = $this->core->loadMod($module_name);
|
||||
$this->parentClass = $mod->giveModel($model_type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Class Module
|
||||
*
|
||||
|
@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* Config Module
|
||||
* Config Class
|
||||
*
|
||||
* This class gives access to the config files. Allows for reading and editting
|
||||
* This class gives access to the config files. Can read and write .php files with an array in a file
|
||||
*/
|
||||
class Config extends Bus{
|
||||
|
||||
@ -38,14 +41,14 @@ class Config extends Bus{
|
||||
* @return StdObject of config
|
||||
*/
|
||||
public function loadConfigFile($name, $directory = null) {
|
||||
$dir = (isset($directory) ? $directory : FUZEPATH . "Application//config/");
|
||||
$dir = (isset($directory) ? $directory : "Application/config/");
|
||||
$file = $dir . 'config.' . strtolower($name).".php";
|
||||
|
||||
if (file_exists($file)) {
|
||||
$DECODED = (object) require($file);
|
||||
return $DECODED;
|
||||
} else {
|
||||
$this->core->loadMod('database');
|
||||
$this->core->loadMod('techfuze/database');
|
||||
if ($this->dbActive) {
|
||||
// Fetch me a query of 5
|
||||
$prefix = $this->mods->database->getPrefix();
|
||||
@ -85,7 +88,7 @@ class Config extends Bus{
|
||||
* @param String directory, default is Application/Config
|
||||
*/
|
||||
public function set($name, $key, $value, $directory = null) {
|
||||
$dir = (isset($directory) ? $directory : FUZEPATH . "Application//config/");
|
||||
$dir = (isset($directory) ? $directory : "Application/config/");
|
||||
$file = $dir . 'config.' . strtolower($name).".php";
|
||||
if (file_exists($file)) {
|
||||
$DECODED = require($file);
|
||||
|
@ -1,20 +1,32 @@
|
||||
<?php
|
||||
|
||||
if (!defined('FUZESYSPATH')) {
|
||||
define('STARTTIME', microtime(true));
|
||||
define( 'FUZESYSPATH', dirname(__FILE__) . '/' );
|
||||
}
|
||||
namespace FuzeWorks;
|
||||
use \stdClass;
|
||||
use \Exception;
|
||||
|
||||
// NotifierEvent, base event
|
||||
// Framework
|
||||
/**
|
||||
* FuzeWorks Core
|
||||
*
|
||||
* Holds all the modules and starts the framework. Allows for starting and managing modules
|
||||
*/
|
||||
class Core {
|
||||
|
||||
public $mods;
|
||||
public $mods;
|
||||
public $register;
|
||||
|
||||
/**
|
||||
* An array which modules are loaded, and should not be loaded again
|
||||
* @access private
|
||||
* @var Array of module names
|
||||
*/
|
||||
private $loaded_modules = array();
|
||||
private $loaded = false;
|
||||
private $register;
|
||||
|
||||
## START/STOP
|
||||
public function init() {
|
||||
if (!defined('STARTTIME')) {
|
||||
define('STARTTIME', microtime(true));
|
||||
}
|
||||
// Load basics
|
||||
ignore_user_abort(true);
|
||||
register_shutdown_function(array($this, "shutdown"));
|
||||
@ -23,12 +35,12 @@ class Core {
|
||||
$this->mods = new stdClass();
|
||||
$this->loadStartupFiles();
|
||||
|
||||
$this->mods->events->fireEvent('coreStartEvent');
|
||||
// Mod register exists, check if expired
|
||||
if ( ( date('U') - $this->mods->config->main->registers_last_update) > $this->mods->config->main->registers_update_interval) {
|
||||
$this->mods->logger->log("Registers have expired. Updating...", 'Core');
|
||||
$this->buildModRegister();
|
||||
$this->mods->events->buildEventRegister();
|
||||
$this->buildRegister();
|
||||
$this->mods->events->buildEventRegister();
|
||||
|
||||
$event = $this->mods->events->fireEvent('coreStartEvent');
|
||||
if ($event->isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,18 +49,19 @@ class Core {
|
||||
return;
|
||||
|
||||
// Load core abstracts
|
||||
require_once(FUZESYSPATH . "/class.abstract.bus.php");
|
||||
require_once(FUZESYSPATH . "/class.abstract.event.php");
|
||||
require_once(FUZESYSPATH . "/class.abstract.module.php");
|
||||
require_once(FUZESYSPATH . "/class.abstract.model.php");
|
||||
require_once(FUZESYSPATH . "/class.abstract.eventPriority.php");
|
||||
require_once("Core/System/class.abstract.bus.php");
|
||||
require_once("Core/System/class.abstract.event.php");
|
||||
require_once("Core/System/class.abstract.module.php");
|
||||
require_once("Core/System/class.abstract.model.php");
|
||||
require_once("Core/System/class.abstract.controller.php");
|
||||
require_once("Core/System/class.abstract.eventPriority.php");
|
||||
|
||||
// Load the core classes
|
||||
require_once(FUZESYSPATH . "/class.config.php");
|
||||
require_once(FUZESYSPATH . "/class.logger.php");
|
||||
require_once(FUZESYSPATH . "/class.models.php");
|
||||
require_once(FUZESYSPATH . "/class.layout.php");
|
||||
require_once(FUZESYSPATH . "/class.events.php");
|
||||
require_once("Core/System/class.config.php");
|
||||
require_once("Core/System/class.logger.php");
|
||||
require_once("Core/System/class.models.php");
|
||||
require_once("Core/System/class.layout.php");
|
||||
require_once("Core/System/class.events.php");
|
||||
|
||||
// Load them
|
||||
$this->mods->events = new Events ($this);
|
||||
@ -64,133 +77,101 @@ class Core {
|
||||
$this->mods->events->fireEvent('coreShutdownEvent');
|
||||
}
|
||||
|
||||
## MODLOADING
|
||||
public function loadMod($name, $version = null) {
|
||||
// Get class information
|
||||
$data = $this->loadModule($name, $version);
|
||||
public function loadMod($name) {
|
||||
// Where the modules are
|
||||
$path = "Modules/";
|
||||
|
||||
// If it is an abstract class, create and StdClass
|
||||
if (empty($data)) {
|
||||
return $this->mods->{strtolower($name)} = new StdClass();
|
||||
}
|
||||
|
||||
// Otherwise load the class
|
||||
$class_name = $data['className'];
|
||||
|
||||
// Create the class object if not created yet
|
||||
if (!isset($this->mods->{strtolower($data['moduleLinkName'])})) {
|
||||
$CLASS = new $class_name($this);
|
||||
if (method_exists($CLASS, 'setModulePath')) {
|
||||
$CLASS->setModulePath($data['modulePath']);
|
||||
}
|
||||
if (method_exists($CLASS, 'setModuleLinkName')) {
|
||||
$CLASS->setModuleLinkName($data['moduleLinkName']);
|
||||
}
|
||||
if (method_exists($CLASS, 'setModuleName')) {
|
||||
$CLASS->setModuleName($data['moduleName']);
|
||||
}
|
||||
$CLASS->onLoad();
|
||||
|
||||
return $this->mods->{strtolower($data['moduleLinkName'])} = &$CLASS;
|
||||
}
|
||||
}
|
||||
|
||||
private function loadModule($name, $version = null) {
|
||||
// Load the register if not loaded yet
|
||||
if (!isset($this->mods->config->modregister->register)) {
|
||||
$this->buildModRegister();
|
||||
} else {
|
||||
$this->register = $this->mods->config->modregister->register;
|
||||
}
|
||||
|
||||
// The basic module path
|
||||
$path = FUZEPATH . "/Core/Mods/";
|
||||
|
||||
// Chech if the requested module is set
|
||||
// Check if the requested module is registered
|
||||
if (isset($this->register[$name])) {
|
||||
// Check if the config file is loaded
|
||||
if (!empty($this->register[$name])) {
|
||||
// Load the config file
|
||||
// Load the moduleInfo
|
||||
$cfg = (object) $this->register[$name];
|
||||
|
||||
// Check if the module is enabled, otherwise abort
|
||||
if (isset($cfg->enabled)) {
|
||||
if (!$cfg->enabled) {
|
||||
// Module is disabled
|
||||
throw new Exception("Module '".$name."' is not enabled!", 1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 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)) {
|
||||
// return the link
|
||||
$msg = "Module '".ucfirst((isset($cfg->name) ? $cfg->name : $cfg->module_name)) . "' is already loaded";
|
||||
$this->mods->logger->log($msg);
|
||||
$c = &$this->mods->{strtolower($cfg->module_name)};
|
||||
return $c;
|
||||
} else {
|
||||
// Load the module
|
||||
$file = $cfg->directory . $cfg->module_file;
|
||||
|
||||
// Check if a specific version is requested
|
||||
if (isset($version)) {
|
||||
if (isset($cfg->versions)) {
|
||||
if (isset($cfg->versions[$version])) {
|
||||
$ncfg = (object) $cfg->versions[$version];
|
||||
foreach ($ncfg as $key => $value) {
|
||||
$cfg->$key = $value;
|
||||
}
|
||||
// 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]);
|
||||
}
|
||||
|
||||
// Check if the file exists
|
||||
if (file_exists($file)) {
|
||||
// And load it
|
||||
require_once($file);
|
||||
$class_name = $cfg->module_class;
|
||||
$msg = "Loading Module '".ucfirst((isset($cfg->name) ? $cfg->name : $cfg->module_name)) . "'";
|
||||
$msg .= (isset($cfg->version) ? "; version: ".$cfg->version : "");
|
||||
$msg .= (isset($cfg->author) ? "; made by ".$cfg->author : "");
|
||||
$msg .= (isset($cfg->website) ? "; from ".$cfg->website: "");
|
||||
$this->mods->logger->log($msg);
|
||||
} else {
|
||||
// Throw Exception if the file does not exist
|
||||
throw new Exception("Requested mod '".$name."' could not be loaded. Class file not found", 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it is an abstract module, load an StdClass for the module address
|
||||
if (isset($cfg->abstract)) {
|
||||
if ($cfg->abstract) {
|
||||
$CLASS = new stdClass();
|
||||
return $this->mods->{strtolower($cfg->module_name)} = &$CLASS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Or load the main version
|
||||
$file = $cfg->directory . $cfg->module_file;
|
||||
|
||||
// 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]);
|
||||
}
|
||||
|
||||
// Check if the file exists
|
||||
if (file_exists($file)) {
|
||||
// And load it
|
||||
require_once($file);
|
||||
// Load the module class
|
||||
$class_name = $cfg->module_class;
|
||||
$msg = "Loading Module '".ucfirst((isset($cfg->name) ? $cfg->name : $cfg->module_name)) . "'";
|
||||
$msg .= (isset($cfg->version) ? " version:".$cfg->version : "");
|
||||
$msg .= (isset($cfg->author) ? " made by ".$cfg->author : "");
|
||||
$msg .= (isset($cfg->website) ? " from ".$cfg->website: "");
|
||||
$this->mods->logger->log($msg);
|
||||
} else {
|
||||
// Throw Exception if the file does not exist
|
||||
throw new Exception("Requested mod '".$name."' could not be loaded. Class file not found", 1);
|
||||
return false;
|
||||
$CLASS = new $class_name($this);
|
||||
|
||||
// Apply default methods
|
||||
if (method_exists($CLASS, 'setModulePath')) {
|
||||
$CLASS->setModulePath($cfg->directory);
|
||||
}
|
||||
if (method_exists($CLASS, 'setModuleLinkName')) {
|
||||
$CLASS->setModuleLinkName(strtolower($cfg->module_name));
|
||||
}
|
||||
if (method_exists($CLASS, 'setModuleName')) {
|
||||
$CLASS->setModuleName($name);
|
||||
}
|
||||
|
||||
if (!method_exists($CLASS, 'onLoad')) {
|
||||
throw new Exception("Module '".$name."' does not have an onLoad() method! Invalid module", 1);
|
||||
}
|
||||
$CLASS->onLoad();
|
||||
|
||||
// Add to the loaded modules
|
||||
$this->loaded_modules[] = $name;
|
||||
|
||||
// Return a reference
|
||||
return $this->mods->{strtolower($cfg->module_name)} = &$CLASS;
|
||||
}
|
||||
} else {
|
||||
// Throw Exception if the module has an invalid config file
|
||||
throw new Exception("Requested mod '".$name."' could not be loaded. Invalid config", 1);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Throw Exception if the module is not defined
|
||||
throw new Exception("Requested mod '".$name."' was not found", 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it is an abstract module, return an StdClass for the memory address
|
||||
if (isset($cfg->abstract)) {
|
||||
if ($cfg->abstract) {
|
||||
$c = new stdClass();
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
return array('className' => $class_name,
|
||||
'modulePath' => $cfg->directory,
|
||||
'moduleLinkName' => $cfg->module_name,
|
||||
'moduleName' => $name);
|
||||
}
|
||||
|
||||
public function buildModRegister() {
|
||||
$this->mods->logger->newLevel("Building Mod Register", 'Core');
|
||||
$dir = FUZEPATH . "Core/Mods/";
|
||||
$mods = array_values(array_diff(scandir($dir), array('..', '.')));
|
||||
$register = array();
|
||||
for ($i=0; $i < count($mods); $i++) {
|
||||
$mod_dir = $dir . $mods[$i] . "/";
|
||||
if (file_exists($mod_dir . "/moduleInfo.php")) {
|
||||
public function buildRegister() {
|
||||
$this->mods->logger->newLevel("Loading Module Headers", 'Core');
|
||||
|
||||
// Get all the module directories
|
||||
$dir = "Modules/";
|
||||
$mod_dirs = array();
|
||||
$mod_dirs = array_values(array_diff(scandir($dir), array('..', '.')));
|
||||
|
||||
// Build the module register
|
||||
$register = array();
|
||||
for ($i=0; $i < count($mod_dirs); $i++) {
|
||||
$mod_dir = $dir . $mod_dirs[$i] . "/";
|
||||
// If a moduleInfo.php exists, load it
|
||||
if (file_exists($mod_dir . "/moduleInfo.php")) {
|
||||
$cfg = (object) require($mod_dir . "/moduleInfo.php");
|
||||
$name = "";
|
||||
$name .= (!empty($cfg->author) ? strtolower($cfg->author)."/" : "");
|
||||
@ -198,12 +179,24 @@ class Core {
|
||||
|
||||
// Append directory
|
||||
$cfg->directory = $mod_dir;
|
||||
$register[$name] = (array) $cfg;
|
||||
} else {
|
||||
if (isset($cfg->enabled)) {
|
||||
if ($cfg->enabled) {
|
||||
$register[$name] = (array) $cfg;
|
||||
$this->mods->logger->log("[ON] '".$name."'");
|
||||
} else {
|
||||
$this->mods->logger->log("[OFF] '".$name."'");
|
||||
}
|
||||
} else {
|
||||
$register[$name] = (array) $cfg;
|
||||
$this->mods->logger->log("[ON] '".$name."'");
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
// Get the name
|
||||
$name = $mods[$i];
|
||||
$name = $mod_dirs[$i];
|
||||
|
||||
// Build a dynamic module config
|
||||
// Build a default module config
|
||||
$cfg = new stdClass();
|
||||
$cfg->module_class = ucfirst($name);
|
||||
$cfg->module_file = 'class.'.strtolower($name).".php";
|
||||
@ -212,12 +205,13 @@ class Core {
|
||||
$cfg->versions = array();
|
||||
$cfg->directory = $mod_dir;
|
||||
$register[$name] = (array)$cfg;
|
||||
}
|
||||
}
|
||||
$this->mods->logger->log("[ON] '".$name."'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->mods->logger->stopLevel();
|
||||
$this->mods->config->set('modregister', 'register', $register);
|
||||
$this->mods->config->set('main', 'registers_last_update', date('U'));
|
||||
$this->register = $register;
|
||||
$this->mods->logger->stopLevel();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,21 @@
|
||||
* @author FuzeNetwork
|
||||
* @package files
|
||||
*/
|
||||
|
||||
|
||||
namespace FuzeWorks;
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* @name Events
|
||||
*/
|
||||
* Event Class
|
||||
*
|
||||
* Controls FuzeWorks Events. Events are classes that get loaded during special moments in the program.
|
||||
* These Event objects get send to so-called 'listeners', which can modify the event object, and eventually return them to invoker.
|
||||
* Typically an event process goes like this:
|
||||
* - Event get's called
|
||||
* - Event object is created
|
||||
* - Event object is send to all listeners in order of EventPriority
|
||||
* - Event is returned
|
||||
*/
|
||||
class Events extends Bus{
|
||||
|
||||
private $listeners;
|
||||
@ -71,23 +82,23 @@ class Events extends Bus{
|
||||
## EVENTS
|
||||
public function fireEvent($input) {
|
||||
if (is_string($input)) {
|
||||
// STRING
|
||||
// If the input is a string
|
||||
$eventClass = $input;
|
||||
$eventName = $input;
|
||||
if(!class_exists($eventClass)){
|
||||
// Check if the file even exists
|
||||
$file = FUZEPATH . "/Core/Events/event.".$eventName.".php";
|
||||
$file = "Core/Events/event.".$eventName.".php";
|
||||
if(file_exists($file)){
|
||||
// Load the file
|
||||
require_once($file);
|
||||
}else{
|
||||
// No event arguments? Looks like an notify-event
|
||||
// No event arguments? Looks like a notify-event
|
||||
if(func_num_args() == 1){
|
||||
// Load notify-event-class
|
||||
$eventClass = 'NotifierEvent';
|
||||
$eventClass = '\FuzeWorks\NotifierEvent';
|
||||
}else{
|
||||
// No notify-event: we tried all we could
|
||||
throw new \Exception("Event ".$eventName." could not be found!");
|
||||
throw new Exception("Event ".$eventName." could not be found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,7 +123,7 @@ class Events extends Bus{
|
||||
$this->logger->log("Checking for Listeners");
|
||||
|
||||
// Read the event register for listeners
|
||||
$register = $this->config->eventregister->register;
|
||||
$register = $this->register;
|
||||
if (isset($register[$eventName])) {
|
||||
for ($i=0; $i < count($register[$eventName]); $i++) {
|
||||
$this->core->loadMod($register[$eventName][$i]);
|
||||
@ -154,22 +165,24 @@ class Events extends Bus{
|
||||
|
||||
// Event Preparation:
|
||||
public function buildEventRegister() {
|
||||
$this->logger->newLevel("Building Event Register", 'Events');
|
||||
$dir = FUZEPATH . "/Core/Mods/";
|
||||
$mods = $this->config->modregister->register;
|
||||
foreach ($mods as $key => $value) {
|
||||
try {
|
||||
$this->core->loadMod($key);
|
||||
} catch (Exception $e) {}
|
||||
$event_register = array();
|
||||
foreach ($this->core->register as $key => $value) {
|
||||
if (isset($value['events'])) {
|
||||
if (!empty($value['events'])) {
|
||||
for ($i=0; $i < count($value['events']); $i++) {
|
||||
if (isset($event_register[$value['events'][$i]])) {
|
||||
$event_register[$value['events'][$i]][] = $key;
|
||||
} else {
|
||||
$event_register[$value['events'][$i]] = array($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$event = $this->fireEvent('eventRegisterBuildEvent', '');
|
||||
$this->config->set('eventregister', 'register', $event->register);
|
||||
|
||||
$this->logger->stopLevel();
|
||||
$this->register = $event_register;
|
||||
}
|
||||
}
|
||||
|
||||
class NotifierEvent extends Event {}
|
||||
|
||||
|
||||
?>
|
@ -1,5 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* Layout Class
|
||||
*
|
||||
* The Layout class is a wrapper for the Smarty Template engine. Smarty loads .tpl files and variables, and converts them to HTML.
|
||||
* See the Smarty documentation for more information
|
||||
* This class typically loads files from Application/Views unless specified otherwise.
|
||||
*
|
||||
*/
|
||||
class Layout extends Bus {
|
||||
|
||||
private $Smarty = array();
|
||||
@ -12,7 +23,7 @@ class Layout extends Bus {
|
||||
|
||||
private function load() {
|
||||
// Load Smarty
|
||||
$smartyDir = FUZEPATH . "/Core/System/Smarty";
|
||||
$smartyDir = "Core/System/Smarty";
|
||||
|
||||
if (!defined('SMARTY_DIR')) {
|
||||
define('SMARTY_DIR', $smartyDir . DIRECTORY_SEPARATOR . "libs" . DIRECTORY_SEPARATOR);
|
||||
@ -29,8 +40,8 @@ class Layout extends Bus {
|
||||
}
|
||||
|
||||
public function getSmartyBasicVars($Smarty) {
|
||||
$Smarty->setCompileDir(FUZEPATH . "/Core/Cache/Compile");
|
||||
$Smarty->setCacheDir(FUZEPATH . "/Core/Cache/");
|
||||
$Smarty->setCompileDir("Core/Cache/Compile");
|
||||
$Smarty->setCacheDir("Core/Cache/");
|
||||
$Smarty->assign('siteURL', $this->config->main->SITE_URL);
|
||||
$Smarty->assign('serverName', $this->config->main->SERVER_NAME);
|
||||
$Smarty->assign('siteDomain', $this->config->main->SITE_DOMAIN);
|
||||
@ -72,11 +83,15 @@ class Layout extends Bus {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function view($view = "default", $dir = null) {
|
||||
public function view($view = "default") {
|
||||
// Chech if Smarty is loaded
|
||||
if (!$this->loaded)
|
||||
$this->load();
|
||||
|
||||
$event = $this->events->fireEvent('layoutLoadEvent', $view);
|
||||
$directory = ($event->directory === null ? "Application/Views" : $event->directory);
|
||||
$view = ($event->layout === null ? $view : $event->layout);
|
||||
|
||||
// Set the file name and location
|
||||
$vw = explode('/', $view);
|
||||
if (count($vw) == 1) {
|
||||
@ -98,65 +113,54 @@ class Layout extends Bus {
|
||||
}
|
||||
|
||||
// Set the directory
|
||||
$dir = (!isset($dir) ? FUZEPATH . "/Application/" . '/Views' : $dir);
|
||||
$this->Smarty['main']->setTemplateDir($dir);
|
||||
$this->Smarty['main']->setTemplateDir($directory);
|
||||
|
||||
// Set the title
|
||||
$this->Smarty['main']->assign('title', $this->title);
|
||||
|
||||
// Get the viewdir
|
||||
// @TODO: Fix this for custom directories
|
||||
$one = FUZEPATH;
|
||||
$two = $dir . "/";
|
||||
$count_one = strlen($one);
|
||||
$count_two = strlen($two);
|
||||
$length_three = $count_two - $count_one;
|
||||
$three = $this->config->main->SITE_URL . "/" . substr($two, -$length_three);
|
||||
$this->layout->assign('viewDir', $three);
|
||||
$viewDir = $this->config->main->SITE_URL . "/" . substr($directory . "/", -strlen($directory . "/"));
|
||||
$this->layout->assign('viewDir', $viewDir);
|
||||
|
||||
try{
|
||||
|
||||
// Load the page
|
||||
$this->Smarty['main']->display($vw);
|
||||
$this->logger->logInfo("VIEW LOAD: '".$vw."'", "FuzeWorks->Layout", __FILE__, __LINE__);
|
||||
$this->logger->logInfo("VIEW LOAD: '".$vw."'", "Layout", __FILE__, __LINE__);
|
||||
}catch (\SmartyException $e){
|
||||
|
||||
// Throw error on failure
|
||||
$this->logger->logError('Could not load view '.$dir.'/'.$vw.' :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__);
|
||||
throw new Exception\Layout('Could not load view '.$dir.'/'.$vw);
|
||||
$this->logger->logError('Could not load view '.$directory.'/'.$vw.' :: ' . $e->getMessage(), 'Layout', __FILE__, __LINE__);
|
||||
throw new Exception\Layout('Could not load view '.$directory.'/'.$vw);
|
||||
}
|
||||
}
|
||||
|
||||
public function get($view = "default", $dir = "") {
|
||||
public function get($view = "default", $directory = "") {
|
||||
// Chech if Smarty is loaded
|
||||
if (!$this->loaded)
|
||||
$this->load();
|
||||
|
||||
// Set the directory
|
||||
$dir = ($dir == "" ? FUZEPATH . "/Application/" . '/Views' : $dir);
|
||||
$this->Smarty['main']->setTemplateDir($dir);
|
||||
$directory = ($directory == "" ? "Application/" . '/Views' : $directory);
|
||||
$this->Smarty['main']->setTemplateDir($directory);
|
||||
|
||||
// Set the title
|
||||
$this->Smarty['main']->assign('title', $this->title);
|
||||
|
||||
// Get the viewdir
|
||||
$one = FUZEPATH;
|
||||
$two = $dir . "/";
|
||||
$count_one = strlen($one);
|
||||
$count_two = strlen($two);
|
||||
$length_three = $count_two - $count_one;
|
||||
$three = $this->config->main->SITE_URL . "/" . substr($two, -$length_three);
|
||||
$this->layout->assign('viewdir', $three);
|
||||
$viewDir = $this->config->main->SITE_URL . "/" . substr($directory . "/", -strlen($directory . "/"));
|
||||
$this->layout->assign('viewDir', $viewDir);
|
||||
|
||||
try{
|
||||
|
||||
// Load the page
|
||||
return $this->Smarty['main']->fetch('view.'.$view.'.tpl');
|
||||
$this->logger->logInfo("VIEW LOAD: 'view.".$view.'.tpl'."'", "FuzeWorks->Layout", __FILE__, __LINE__);
|
||||
$this->logger->logInfo("VIEW LOAD: 'view.".$view.'.tpl'."'", "Layout", __FILE__, __LINE__);
|
||||
}catch (\SmartyException $e){
|
||||
|
||||
// Throw error on failure
|
||||
$this->logger->logError('Could not load view '.$dir.'/view.'.$view.'.tpl :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__);
|
||||
throw new Exception\Layout('Could not load view '.$dir.'/view.'.$view.'.tpl');
|
||||
$this->logger->logError('Could not load view '.$directory.'/view.'.$view.'.tpl :: ' . $e->getMessage(), 'Layout', __FILE__, __LINE__);
|
||||
throw new Exception\Layout('Could not load view '.$directory.'/view.'.$view.'.tpl');
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* Logger Class
|
||||
*
|
||||
* The main tool to handle errors and exceptions. Provides some tools for debugging and tracking where errors take place
|
||||
* All fatal errors get catched by this class and get displayed if configured to do so.
|
||||
*/
|
||||
class Logger extends Bus{
|
||||
|
||||
public $infoErrors = array();
|
||||
@ -37,6 +46,7 @@ class Logger extends Bus{
|
||||
|
||||
// Log it!
|
||||
$this->errorHandler($errno, $errstr, $errfile, $errline);
|
||||
$this->logInfo($this->backtrace());
|
||||
}
|
||||
|
||||
if ($this->mods->config->error->debug == true || $this->print_to_screen) {
|
||||
@ -88,6 +98,13 @@ class Logger extends Bus{
|
||||
}
|
||||
|
||||
public function logToScreen() {
|
||||
// Send a screenLogEvent, allows for new screen log designs
|
||||
$event = $this->mods->events->fireEvent('screenLogEvent');
|
||||
if ($event->isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise just load it
|
||||
echo '<h3>FuzeWorks debug log</h3>';
|
||||
$layer = 0;
|
||||
for($i = 0; $i < count($this->Logs); $i++){
|
||||
@ -113,6 +130,24 @@ class Logger extends Bus{
|
||||
}
|
||||
}
|
||||
|
||||
public function backtrace() {
|
||||
$e = new Exception();
|
||||
$trace = explode("\n", $e->getTraceAsString());
|
||||
// reverse array to make steps line up chronologically
|
||||
$trace = array_reverse($trace);
|
||||
array_shift($trace); // remove {main}
|
||||
array_pop($trace); // remove call to this method
|
||||
$length = count($trace);
|
||||
$result = array();
|
||||
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
{
|
||||
$result[] = ($i + 1) . ')' . substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering
|
||||
}
|
||||
|
||||
return "<b>BACKTRACE: <br/>\t" . implode("<br/>", $result)."</b>";
|
||||
}
|
||||
|
||||
/* =========================================LOGGING METHODS==============================================================*/
|
||||
|
||||
|
||||
@ -267,8 +302,8 @@ class Logger extends Bus{
|
||||
511 => 'Network Authentication Required'
|
||||
);
|
||||
|
||||
$this->logError('HTTP-error '.$errno.' called', 'FuzeWorks->Logger');
|
||||
$this->logInfo('Sending header HTTP/1.1 '.$errno.' '.$http_codes[$errno], 'FuzeWorks->Logger', __FILE__, __LINE__);
|
||||
$this->logError('HTTP-error '.$errno.' called', 'Logger');
|
||||
$this->logInfo('Sending header HTTP/1.1 '.$errno.' '.$http_codes[$errno], 'Logger', __FILE__, __LINE__);
|
||||
header('HTTP/1.1 '.$errno.' '.$http_codes[$errno]);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,14 @@
|
||||
* @author FuzeNetwork
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Models Class
|
||||
*
|
||||
* Simple loader class for MVC Models. Typically loads models from Application/Models unless otherwise specified.
|
||||
* If a model is not found, it will load a DatabaseModel type which will analyze the database and can directly be used.
|
||||
*/
|
||||
class Models extends Bus{
|
||||
|
||||
private $models_array = array();
|
||||
@ -14,9 +22,10 @@ class Models extends Bus{
|
||||
}
|
||||
|
||||
public function loadModel($name, $directory = null){
|
||||
if($directory === null){
|
||||
$directory = FUZEPATH . "/Application/Models";
|
||||
}
|
||||
// Model load event
|
||||
$event = $this->events->fireEvent('modelLoadEvent', $name);
|
||||
$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])) {
|
||||
@ -24,12 +33,12 @@ class Models extends Bus{
|
||||
$this->models_array[$name] = $this->model_types[$name];
|
||||
} elseif (file_exists($file)){
|
||||
require_once($file);
|
||||
$model = ucfirst($name);
|
||||
$model = "\Model\\" . ucfirst($name);
|
||||
$this->logger->logInfo('Loading Model: '.$model, $model);
|
||||
$this->models_array[$name] = new $model($this->core);
|
||||
} else{
|
||||
$this->logger->logWarning('The requested model: \''.$name.'\' could not be found. Loading empty model', 'Models');
|
||||
require_once(FUZEPATH . "/Core/System/Models/model.interpret.php");
|
||||
require_once("Core/System/Models/model.interpret.php");
|
||||
$this->logger->logInfo('Loading Model: interprated databasemodel', 'Models');
|
||||
$model = new Interpret($this->core);
|
||||
$model->table($name);
|
||||
|
99
Modules/database/class.database.php
Normal file
99
Modules/database/class.database.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Module\Database;
|
||||
use \FuzeWorks\Module;
|
||||
use \PDO;
|
||||
|
||||
class Main extends Module {
|
||||
|
||||
/**
|
||||
* The default database connection
|
||||
* @access private
|
||||
* @var PDO Class
|
||||
*/
|
||||
private $DBH;
|
||||
public $prefix;
|
||||
|
||||
public function __construct(&$core) {
|
||||
parent::__construct($core);
|
||||
}
|
||||
|
||||
public function onLoad() {
|
||||
$this->config->dbActive = true;
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
$db = $config;
|
||||
}
|
||||
|
||||
// Get the DSN for popular types of databases or a custom DSN
|
||||
switch (strtolower($db->type)) {
|
||||
case 'mysql':
|
||||
$dsn = "mysql:host=".$db->host.";";
|
||||
$dsn .= (!empty($db->database) ? "dbname=".$db->database.";" : "");
|
||||
break;
|
||||
case 'custom':
|
||||
$dsn = $db->dsn;
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->mods->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");
|
||||
|
||||
// And set the prefix
|
||||
$this->prefix = $db->prefix;
|
||||
} catch (Exception $e) {
|
||||
throw (new Exception('Could not connect to the database: "'. $e->getMessage() . '"'));
|
||||
}
|
||||
}
|
||||
|
||||
public function getPrefix() {
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
public function is_active() {
|
||||
if($this->DBH === null){
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function __call($name, $params) {
|
||||
if ($this->is_active()) {
|
||||
return call_user_func_array(array($this->DBH, $name), $params);
|
||||
} else {
|
||||
$this->connect();
|
||||
return call_user_func_array(array($this->DBH, $name), $params);
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
if ($this->is_active()) {
|
||||
return $this->DBH->$name;
|
||||
} else {
|
||||
$this->connect();
|
||||
return $this->DBH->$name;
|
||||
}
|
||||
}
|
||||
|
||||
public function __set($name, $value) {
|
||||
if ($this->is_active()) {
|
||||
$this->DBH->$name = $value;
|
||||
} else {
|
||||
$this->connect();
|
||||
$this->DBH->$name = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
23
Modules/database/moduleInfo.php
Normal file
23
Modules/database/moduleInfo.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
return array(
|
||||
|
||||
'module_class' => 'Module\Database\Main',
|
||||
'module_file' => 'class.database.php',
|
||||
'module_name' => 'Database',
|
||||
|
||||
'abstract' => false,
|
||||
'dependencies' => array(),
|
||||
'events' => array(),
|
||||
'sections' => array(),
|
||||
|
||||
'name' => 'FuzeWorks Database Module',
|
||||
'description' => 'PDO Wrapper class for FuzeWorks',
|
||||
'author' => 'TechFuze',
|
||||
'version' => '1.0.0',
|
||||
'website' => 'http://fuzeworks.techfuze.net/',
|
||||
|
||||
'date_created' => '30-04-2015',
|
||||
'date_updated' => '30-04-2015',
|
||||
|
||||
'enabled' => true,
|
||||
);
|
@ -1,6 +1,11 @@
|
||||
<?php
|
||||
|
||||
class DatabaseModel extends Bus{
|
||||
namespace Module;
|
||||
use \FuzeWorks\Module;
|
||||
use \FuzeWorks\ModelServer;
|
||||
use \Exception;
|
||||
|
||||
class DatabaseModel extends Module implements ModelServer {
|
||||
|
||||
public $fields = array();
|
||||
public $primary = 'id';
|
||||
@ -8,7 +13,12 @@ class DatabaseModel extends Bus{
|
||||
|
||||
public function __construct(&$core){
|
||||
parent::__construct($core);
|
||||
$this->core->loadMod('database');
|
||||
}
|
||||
|
||||
public function onLoad() {}
|
||||
|
||||
public function giveModel($type) {
|
||||
return new DatabaseModel($this->core);
|
||||
}
|
||||
|
||||
public function select(){
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
return array(
|
||||
|
||||
'module_class' => 'DatabaseModel',
|
||||
'module_class' => 'Module\DatabaseModel',
|
||||
'module_file' => 'class.model.php',
|
||||
'module_name' => 'databasemodel',
|
||||
|
||||
'abstract' => true,
|
||||
'abstract' => false,
|
||||
'dependencies' => array('techfuze/database'),
|
||||
|
||||
'name' => 'DatabaseModel',
|
||||
'description' => 'Abstract type for easy database queries',
|
||||
@ -15,4 +16,6 @@ return array(
|
||||
|
||||
'date_created' => '26-02-2015',
|
||||
'date_updated' => '26-02-2015',
|
||||
|
||||
'enabled' => true,
|
||||
);
|
@ -1,13 +1,16 @@
|
||||
<?php
|
||||
|
||||
class Router extends Bus {
|
||||
use \FuzeWorks\Module;
|
||||
|
||||
class Router extends Module {
|
||||
|
||||
public $controller = null;
|
||||
public $controllerName = null;
|
||||
public $function = null;
|
||||
private $route = array();
|
||||
private $parameters = array();
|
||||
private $path;
|
||||
public $route = array();
|
||||
public $parameters = array();
|
||||
public $directory;
|
||||
public $path;
|
||||
|
||||
public function __construct(&$core) {
|
||||
parent::__construct($core);
|
||||
@ -89,10 +92,7 @@ class Router extends Bus {
|
||||
$this->controllerName = ($event->controller === null || empty($event->controller) ? $this->config->main->default_controller : $event->controller);
|
||||
$this->function = ($event->function === null || empty($event->function) ? $this->config->main->default_function : $event->function);
|
||||
$this->parameters = $event->parameters;
|
||||
$this->directory = ($event->directory === null || empty($event->directory) ? FUZEPATH . "/Application/Controller/" : $event->directory);
|
||||
|
||||
// Load the controller
|
||||
$this->loadController();
|
||||
$this->directory = ($event->directory === null || empty($event->directory) ? "Application/Controller/" : $event->directory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,6 +100,21 @@ class Router extends Bus {
|
||||
* @access public
|
||||
*/
|
||||
public function loadController() {
|
||||
// Initate the controllerLoadEvent
|
||||
$event = $this->events->fireEvent('controllerLoadEvent',
|
||||
$this->route,
|
||||
$this->controllerName,
|
||||
$this->function,
|
||||
$this->parameters,
|
||||
$this->directory
|
||||
);
|
||||
|
||||
$this->route = ($event->route === null ? $this->route : $event->route);
|
||||
$this->controllerName = ($event->controllerName === null ? $this->controllerName : $event->controllerName);
|
||||
$this->function = ($event->function === null ? $this->function : $event->function);
|
||||
$this->parameters = ($event->parameters === null ? $this->parameters : $event->parameters);
|
||||
$this->directory = ($event->directory === null ? $this->directory : $event->directory);
|
||||
|
||||
$file = $this->directory . "controller.".strtolower($this->controllerName).".php";
|
||||
$this->logger->log("Loading controller from file: '".$file."'");
|
||||
|
||||
@ -107,7 +122,7 @@ class Router extends Bus {
|
||||
if (!class_exists(ucfirst($this->controllerName)))
|
||||
require_once($file);
|
||||
|
||||
$this->controllerClass = ucfirst($this->controllerName);
|
||||
$this->controllerClass = "\Controller\\" . ucfirst($this->controllerName);
|
||||
$this->controller = new $this->controllerClass($this->core);
|
||||
|
||||
if (method_exists($this->controller, $this->function) || method_exists($this->controller, '__call')) {
|
246
Modules/sections/class.sections.php
Normal file
246
Modules/sections/class.sections.php
Normal file
@ -0,0 +1,246 @@
|
||||
<?php
|
||||
|
||||
namespace Module\Sections;
|
||||
use \FuzeWorks\Module;
|
||||
use \FuzeWorks\EventPriority;
|
||||
|
||||
/**
|
||||
* Sections module, see usage documentation
|
||||
* @author TechFuze
|
||||
*/
|
||||
class Main extends Module {
|
||||
|
||||
/**
|
||||
* The config holder for this module. Holds an StdObject
|
||||
* @access public
|
||||
* @var StdObject Module Config
|
||||
*/
|
||||
public $cfg;
|
||||
|
||||
/**
|
||||
* The current section that we are using right now!
|
||||
* @access private
|
||||
* @var String name of section or null
|
||||
*/
|
||||
private $currentSection = null;
|
||||
|
||||
/**
|
||||
* Loads the module and registers the events
|
||||
* @access public
|
||||
*/
|
||||
public function onLoad() {
|
||||
// Load the config
|
||||
$config = $this->config->loadConfigFile('sections', $this->getModulePath());
|
||||
|
||||
$this->logger->newLevel('Adding module sections', 'Sections');
|
||||
// Add the modules to the config
|
||||
$section_register = array();
|
||||
foreach ($this->core->register as $key => $value) {
|
||||
// Check if the sections value exists in the config file
|
||||
if (isset($value['sections'])) {
|
||||
// Check if it is empty
|
||||
if (!empty($value['sections'])) {
|
||||
// If not, cycle through all sections
|
||||
foreach ($value['sections'] as $section_name => $section) {
|
||||
// Check if the section is already set
|
||||
if (isset($config->$section_name)) {
|
||||
// If the priority is higher, replace the section
|
||||
if ($section->priority > $config->$section_name->priority) {
|
||||
$config->$section_name = $section;
|
||||
$this->logger->log('Added section with higher priority: \''.$section_name.'\'', 'Sections');
|
||||
}
|
||||
} else {
|
||||
$config->$section_name = $section;
|
||||
$this->logger->log('Added section: \''.$section_name.'\'', 'Sections');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the changes and log it
|
||||
$this->cfg = $config;
|
||||
$this->logger->log('Added all module sections to the config file', 'Sections');
|
||||
$this->logger->stopLevel();
|
||||
|
||||
// Register Events
|
||||
$this->events->addListener(array($this, 'routerRouteEvent'), 'routerRouteEvent', EventPriority::LOWEST);
|
||||
$this->events->addListener(array($this, 'layoutLoadEvent'), 'layoutLoadEvent', EventPriority::LOWEST);
|
||||
$this->events->addListener(array($this, 'modelLoadevent'), 'modelLoadEvent', EventPriority::LOWEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects layouts to the new section
|
||||
* @access public
|
||||
* @param layoutLoadEvent Event
|
||||
* @return layoutLoadEvent Event
|
||||
*/
|
||||
public function layoutLoadEvent($event) {
|
||||
$layout_name = $event->layout;
|
||||
if ($this->currentSection !== null) {
|
||||
$section = $this->getSection($this->currentSection);
|
||||
if ($section['module_section']) {
|
||||
$mod = $this->core->loadMod($section['module_name']);
|
||||
$event->directory = $mod->getModulePath() . '/Views/';
|
||||
} else {
|
||||
$event->directory = $section['view_path'];
|
||||
}
|
||||
}
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects models to the new section
|
||||
* @access public
|
||||
* @param layoutLoadEvent Event
|
||||
* @return layoutLoadEvent Event
|
||||
*/
|
||||
public function modelLoadEvent($event) {
|
||||
$model_name = $event->model;
|
||||
if ($this->currentSection !== null) {
|
||||
$section = $this->getSection($this->currentSection);
|
||||
if ($section['module_section']) {
|
||||
$mod = $this->core->loadMod($section['module_name']);
|
||||
$event->directory = $mod->getModulePath() . '/Models/';
|
||||
} else {
|
||||
$event->directory = $section['model_path'];
|
||||
}
|
||||
}
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a section to the config file
|
||||
* @access public
|
||||
* @param String section_name, name of the section
|
||||
* @param Boolean module_section wether this is a module_section
|
||||
* @param String module_name to use when this is a module_section
|
||||
* @param String Controller_path, where to find the controllers for this section
|
||||
* @param String Model_path, where to find the models for this section
|
||||
* @param String View_path, where to find the views for this section
|
||||
*/
|
||||
public function addSection($name, $module_section = false, $module_name = null, $controller_path = null, $model_path = null, $view_path = null) {
|
||||
if ($module_section) {
|
||||
$m = $this->core->loadMod($module_name);
|
||||
$m_dir = $m->getModulePath();
|
||||
$data = array(
|
||||
'name' => $name,
|
||||
'module_section' => $module_section,
|
||||
'module_name' => $module_name,
|
||||
'controller_path' => $m_dir . '/Controller/',
|
||||
'model_path' => $m_dir . '/Models/',
|
||||
'view_path' => $m_dir . '/Views/',
|
||||
);
|
||||
} else {
|
||||
$data = array(
|
||||
'name' => $name,
|
||||
'module_section' => $module_section,
|
||||
'module_name' => $module_name,
|
||||
'controller_path' => $controller_path,
|
||||
'model_path' => $model_path,
|
||||
'view_path' => $view_path,
|
||||
);
|
||||
}
|
||||
|
||||
$this->config->set('sections', $name, $data, $this->getModulePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a section from the config file
|
||||
* @access public
|
||||
* @param String section_name, name of the section to remove
|
||||
*/
|
||||
public function removeSection($name) {
|
||||
$this->config->set('sections', $name, null, $this->getModulePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's called on routerRouteEvent. Redirects when a section is found
|
||||
* @access public
|
||||
* @param routerRouteEvent Event
|
||||
* @return routerRouteEvent Event
|
||||
*/
|
||||
public function routerRouteEvent($event) {
|
||||
$name = $event->controller;
|
||||
$controller = null;
|
||||
$function = null;
|
||||
$parameters = array();
|
||||
$section = $this->{$name};
|
||||
|
||||
if ($section !== null) {
|
||||
// Section found
|
||||
$this->logger->log("Section found with name: '".$name."'", 'Sections');
|
||||
$this->currentSection = $name;
|
||||
|
||||
// Logic here, first for module sections
|
||||
if ($section['module_section']) {
|
||||
$mod = $this->core->loadMod($section['module_name']);
|
||||
$event->directory = $mod->getModulePath() . "/Controller/";
|
||||
} else {
|
||||
// Now for regular sections
|
||||
$event->directory = $section['controller_path'];
|
||||
}
|
||||
|
||||
// Move the path so it matches the new regime
|
||||
if (count($event->parameters) > 0) {
|
||||
$function = $event->parameters[0];
|
||||
$parameters = array_slice($event->parameters, 1);
|
||||
} else {
|
||||
$function = $this->config->main->default_function;
|
||||
}
|
||||
|
||||
// And finally set the controller, if no parameters are set, load the default function
|
||||
$controller = (!empty($event->function) ? $event->function : $this->config->main->default_controller );
|
||||
} else {
|
||||
$this->logger->log("No section was found with name: '".$name."'", 'Sections');
|
||||
}
|
||||
|
||||
if($controller !== null)$event->controller = $controller;
|
||||
if($function !== null)$event->function = $function;
|
||||
if(count($parameters) !== 0)$event->parameters = $parameters;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a section file
|
||||
* @access public
|
||||
* @param String section name
|
||||
* @return Array Section
|
||||
*/
|
||||
public function getSection($name) {
|
||||
if (isset($this->cfg->$name)) {
|
||||
return $this->cfg->$name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves section information from the config file
|
||||
* @access public
|
||||
* @param String section_name, name of the section
|
||||
* @return Array section_information or null
|
||||
*/
|
||||
public function __get($name){
|
||||
// Something given?
|
||||
if(empty($name)) {
|
||||
// Currently in a section?
|
||||
if($this->currentSection !== null){
|
||||
// Return that one then
|
||||
return $this->cfg[$this->currentSection];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return element $name of the config file
|
||||
if (isset($this->cfg->$name)) {
|
||||
$section = $this->cfg->$name;
|
||||
} else {
|
||||
$section = null;
|
||||
}
|
||||
|
||||
return $section;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
1
Modules/sections/config.sections.php
Normal file
1
Modules/sections/config.sections.php
Normal file
@ -0,0 +1 @@
|
||||
<?php return array() ;
|
22
Modules/sections/moduleInfo.php
Normal file
22
Modules/sections/moduleInfo.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
return array(
|
||||
|
||||
'module_class' => 'Module\Sections\Main',
|
||||
'module_file' => 'class.sections.php',
|
||||
'module_name' => 'Sections',
|
||||
|
||||
'abstract' => false,
|
||||
'dependencies' => array(),
|
||||
'events' => array('routerRouteEvent', 'layoutLoadEvent', 'modelLoadEvent'),
|
||||
|
||||
'name' => 'FuzeWorks Sections',
|
||||
'description' => 'Submodules for FuzeWorks',
|
||||
'author' => 'TechFuze',
|
||||
'version' => '1.0.0',
|
||||
'website' => 'http://fuzeworks.techfuze.net/',
|
||||
|
||||
'date_created' => '29-04-2015',
|
||||
'date_updated' => '29-04-2015',
|
||||
|
||||
'enabled' => true,
|
||||
);
|
Loading…
Reference in New Issue
Block a user