Merge branch 'master' into 'master'
Recent changes All recent changes during the downtime of Gitlab See merge request !34
This commit is contained in:
commit
46998a19ba
|
@ -0,0 +1,9 @@
|
|||
<?php return array (
|
||||
'enable_events' => true,
|
||||
'enable_logger' => true,
|
||||
'enable_models' => true,
|
||||
'enable_layout' => true,
|
||||
'enable_router' => true,
|
||||
'enable_modules' => true
|
||||
|
||||
) ;
|
|
@ -2,18 +2,67 @@
|
|||
|
||||
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.
|
||||
*
|
||||
*/
|
||||
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);
|
||||
|
@ -29,7 +78,11 @@ abstract class Bus {
|
|||
|
||||
}
|
||||
|
||||
// Holds the mods in a seperate object besides the bus
|
||||
/**
|
||||
* 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) {
|
||||
|
|
|
@ -5,6 +5,6 @@ namespace FuzeWorks;
|
|||
/**
|
||||
* Abstract class Controller
|
||||
*
|
||||
* Abstract for a Controller data representation, loads the correct parent type
|
||||
* At this point does nothing, can be extended in the future to allow special controller functions
|
||||
*/
|
||||
abstract class Controller extends Bus{}
|
|
@ -2,14 +2,25 @@
|
|||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Class Event
|
||||
*
|
||||
* A simple class for events. The only current purpose is to be able to cancel events, but it can be easily extended.
|
||||
*/
|
||||
class Event {
|
||||
|
||||
private $cancelled = false;
|
||||
|
||||
/**
|
||||
* @return boolean True if the event is cancelled, false if the event is not cancelled
|
||||
*/
|
||||
public function isCancelled() {
|
||||
return $this->cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $cancelled True if the event is cancelled, false if the event is not cancelled
|
||||
*/
|
||||
public function setCancelled($cancelled) {
|
||||
if ($cancelled == true){
|
||||
$this->cancelled = true;
|
||||
|
@ -19,6 +30,9 @@ class Event {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple event which will notify components of an event, but does not contain any data
|
||||
*/
|
||||
class NotifierEvent extends Event {}
|
||||
|
||||
?>
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Catcher Class
|
||||
*
|
||||
* This class catches requests and returns nothing. Handy for a temporary replacement object
|
||||
*/
|
||||
class Catcher extends Bus{
|
||||
|
||||
public function __construct(&$core) {
|
||||
parent::__construct($core);
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
return new Catcher($this->core);
|
||||
}
|
||||
|
||||
public function __set($name, $value) {}
|
||||
|
||||
public function __unset($name) {}
|
||||
|
||||
public function __isset($name) {}
|
||||
|
||||
public function __call($name, $params) {
|
||||
return new Catcher($this->core);
|
||||
}
|
||||
|
||||
public static function __callStatic($name, $params) {}
|
||||
|
||||
public function __sleep() {}
|
||||
|
||||
public function __wakeup() {}
|
||||
|
||||
public function __toString() {}
|
||||
|
||||
}
|
||||
|
||||
class EventsCatcher extends Catcher {
|
||||
public function __construct(&$core) {
|
||||
parent::__construct($core);
|
||||
}
|
||||
|
||||
public function fireEvent($input) {
|
||||
if (is_string($input)) {
|
||||
// If the input is a string
|
||||
$eventClass = $input;
|
||||
$eventName = $input;
|
||||
if(!class_exists($eventClass)){
|
||||
// Check if the file even exists
|
||||
$file = "Core/Events/event.".$eventName.".php";
|
||||
if(file_exists($file)){
|
||||
// Load the file
|
||||
require_once($file);
|
||||
}else{
|
||||
// No event arguments? Looks like a notify-event
|
||||
if(func_num_args() == 1){
|
||||
// Load notify-event-class
|
||||
$eventClass = '\FuzeWorks\NotifierEvent';
|
||||
}else{
|
||||
// No notify-event: we tried all we could
|
||||
throw new Exception("Event ".$eventName." could not be found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$event = new $eventClass($this);
|
||||
} elseif (is_object($input)) {
|
||||
$eventName = get_class($input);
|
||||
$eventName = explode('\\', $eventName);
|
||||
$eventName = end($eventName);
|
||||
$event = $input;
|
||||
} else {
|
||||
// INVALID EVENT
|
||||
return false;
|
||||
}
|
||||
|
||||
if (func_num_args() > 1)
|
||||
call_user_func_array(array($event, 'init'), array_slice(func_get_args(), 1));
|
||||
|
||||
return $event;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -31,6 +31,9 @@ class Core {
|
|||
// Load core functionality
|
||||
$this->loadStartupFiles();
|
||||
|
||||
// Load Composer
|
||||
$this->loadComposer();
|
||||
|
||||
$this->mods->modules->buildRegister();
|
||||
$this->mods->events->buildEventRegister();
|
||||
|
||||
|
@ -43,39 +46,74 @@ class Core {
|
|||
}
|
||||
}
|
||||
|
||||
public function loadStartupFiles() {
|
||||
public function loadStartupFiles($config = array()) {
|
||||
if ($this->loaded)
|
||||
return;
|
||||
|
||||
// Load core abstracts
|
||||
require_once("Core/System/class.abstract.bus.php");
|
||||
require_once("Core/System/class.abstract.event.php");
|
||||
require_once("Core/System/class.abstract.module.php");
|
||||
require_once("Core/System/class.abstract.model.php");
|
||||
require_once("Core/System/class.abstract.controller.php");
|
||||
require_once("Core/System/class.abstract.eventPriority.php");
|
||||
require_once("Core/System/class.catcher.php");
|
||||
require_once("Core/System/class.exceptions.php");
|
||||
require_once("Core/System/class.abstract.event.php");
|
||||
|
||||
// Load the core classes
|
||||
require_once("Core/System/class.config.php");
|
||||
require_once("Core/System/class.logger.php");
|
||||
require_once("Core/System/class.models.php");
|
||||
require_once("Core/System/class.layout.php");
|
||||
require_once("Core/System/class.events.php");
|
||||
require_once("Core/System/class.router.php");
|
||||
require_once("Core/System/class.modules.php");
|
||||
|
||||
// Create the module holder
|
||||
|
||||
|
||||
// Load the modules
|
||||
$this->mods->events = new Events ($this);
|
||||
$this->mods->config = new Config ($this);
|
||||
$this->mods->logger = new Logger ($this);
|
||||
$this->mods->models = new Models ($this);
|
||||
$this->mods->layout = new Layout ($this);
|
||||
$this->mods->router = new Router ($this);
|
||||
$this->mods->modules = new Modules ($this);
|
||||
$core_mods = $this->mods->config->core;
|
||||
|
||||
// Events
|
||||
if ($core_mods->enable_events) {
|
||||
require_once("Core/System/class.abstract.eventPriority.php");
|
||||
require_once("Core/System/class.events.php");
|
||||
$this->mods->events = new Events ($this);
|
||||
} else {
|
||||
$this->mods->events = new EventsCatcher ($this);
|
||||
}
|
||||
|
||||
// Logger
|
||||
if ($core_mods->enable_logger) {
|
||||
require_once("Core/System/class.logger.php");
|
||||
$this->mods->logger = new Logger ($this);
|
||||
} else {
|
||||
$this->mods->logger = new Catcher ($this);
|
||||
}
|
||||
|
||||
// Models
|
||||
if ($core_mods->enable_models) {
|
||||
require_once("Core/System/class.abstract.model.php");
|
||||
require_once("Core/System/class.models.php");
|
||||
$this->mods->models = new Models ($this);
|
||||
} else {
|
||||
$this->mods->models = new Catcher ($this);
|
||||
}
|
||||
|
||||
// Layout
|
||||
if ($core_mods->enable_layout) {
|
||||
require_once("Core/System/class.layout.php");
|
||||
$this->mods->layout = new Layout ($this);
|
||||
} else {
|
||||
$this->mods->layout = new Catcher ($this);
|
||||
}
|
||||
|
||||
// Router
|
||||
if ($core_mods->enable_router) {
|
||||
require_once("Core/System/class.abstract.controller.php");
|
||||
require_once("Core/System/class.router.php");
|
||||
$this->mods->router = new Router ($this);
|
||||
} else {
|
||||
$this->mods->router = new Catcher ($this);
|
||||
}
|
||||
|
||||
// Modules
|
||||
if ($core_mods->enable_modules) {
|
||||
require_once("Core/System/class.abstract.module.php");
|
||||
require_once("Core/System/class.modules.php");
|
||||
$this->mods->modules = new Modules ($this);
|
||||
} else {
|
||||
$this->mods->modules = new Catcher ($this);
|
||||
}
|
||||
|
||||
$this->loaded = true;
|
||||
}
|
||||
|
@ -93,6 +131,17 @@ class Core {
|
|||
return $this->mods->modules->addModule($moduleInfo_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load composer if it is present
|
||||
* @access private
|
||||
* @param String directory of composer autoload file (optional)
|
||||
*/
|
||||
private function loadComposer($file = "vendor/autoload.php") {
|
||||
if (file_exists($file)) {
|
||||
require($file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -173,7 +173,15 @@ class Events extends Bus{
|
|||
// Event Preparation:
|
||||
public function buildEventRegister() {
|
||||
$event_register = array();
|
||||
foreach ($this->modules->register as $key => $value) {
|
||||
// Check wether there is data or not
|
||||
$data = $this->modules->register;
|
||||
if (is_null($data)) {
|
||||
$this->register = array();
|
||||
return true;
|
||||
}
|
||||
|
||||
// If there is, handle it
|
||||
foreach ($data as $key => $value) {
|
||||
if (isset($value['events'])) {
|
||||
if (!empty($value['events'])) {
|
||||
for ($i=0; $i < count($value['events']); $i++) {
|
||||
|
@ -188,6 +196,7 @@ class Events extends Bus{
|
|||
}
|
||||
|
||||
$this->register = $event_register;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -102,6 +102,14 @@ class Modules extends Bus{
|
|||
$CLASS->setModuleName($name);
|
||||
}
|
||||
if (method_exists($CLASS, 'setModuleConfig')) {
|
||||
// Append the config file to the module CFG (accessable through $this->cfg)
|
||||
if (file_exists($cfg->directory . "/" . "config.".strtolower($cfg->module_name).".php")) {
|
||||
$data = (object) include($cfg->directory . "/" . "config.".strtolower($cfg->module_name).".php");
|
||||
foreach ($data as $key => $value) {
|
||||
$cfg->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$CLASS->setModuleConfig($cfg);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,9 @@ class Main extends Module {
|
|||
}
|
||||
|
||||
public function getPrefix() {
|
||||
if (!$this->is_active()) {
|
||||
$this->connect();
|
||||
}
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ class Model extends Bus {
|
|||
public function query($query, $binds = null){
|
||||
|
||||
if($this->config->database->debug)
|
||||
$this->logger->log("Query: ".$query, "Database Model");
|
||||
$this->logger->log("Manuel Query: ".$query, "Database Model");
|
||||
|
||||
try{
|
||||
|
||||
|
|
36
build.xml
36
build.xml
|
@ -1,36 +0,0 @@
|
|||
<project name="FuzeWorks" default="build" basedir=".">
|
||||
<target name="clean">
|
||||
<delete dir="${basedir}/build" />
|
||||
</target>
|
||||
|
||||
<target name="prepare">
|
||||
<mkdir dir="${basedir}/build/logs" />
|
||||
<mkdir dir="${basedir}/build/clover" />
|
||||
<mkdir dir="${basedir}/build/phpdoc" />
|
||||
</target>
|
||||
|
||||
<target name="phpunit">
|
||||
<exec dir="${basedir}" executable="php" failonerror="true">
|
||||
<arg value="phpunit.phar"/>
|
||||
<arg line="--configuration phpunit.xml
|
||||
--log-junit build/logs/phpunit.xml
|
||||
--coverage-clover build/logs/clover.xml
|
||||
--coverage-html build/clover" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="phpdoc">
|
||||
<exec dir="${basedir}" executable="php" failonerror="yes">
|
||||
<arg value="apigen.phar"/>
|
||||
<arg line="generate --source . --destination 'build/phpdoc' --exclude 'tests/*','build/*','Core/System/Smarty/*' "/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="zip">
|
||||
<exec dir="${basedir}" executable="git" failonerror="true">
|
||||
<arg line="archive -o ${basedir}/build/fuzeworks-core.zip HEAD" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="clean,prepare,phpunit,phpdoc,zip" />
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.7.*"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue