Added new namespaces as described in Issue #37. The following namespaces are used:

\FuzeWorks for Core classes
\Controller for controller classes
\Model for model classes
\Module for modules

Also did the following changes:
- DatabaseModel now loads the database module as a dependency
- DatabaseModel is no longer abstract because of ModelServer
- Implemented a new mechanism for model types in the name of a ModelServer. This interface requires a Model Type Server to return a Model parent class based on a given type
- Added a backtrace to the logger class for easy and fast debugging

And that was it for this commit
This commit is contained in:
Abel Hoogeveen 2015-04-29 17:18:33 +02:00
parent 7a5ac7cfad
commit c5318a2e99
24 changed files with 112 additions and 19 deletions

View File

@ -1,5 +1,8 @@
<?php
namespace Controller;
use \FuzeWorks\Bus;
class Standard extends Bus {
public function __construct(&$core) {
parent::__construct($core);

View File

@ -1,5 +1,8 @@
<?php
namespace Model;
use \FuzeWorks\Model;
class Example extends Model{
public function __construct(&$core){

View File

@ -1,5 +1,7 @@
<?php
use \FuzeWorks\Event;
class ControllerLoadEvent extends Event {
public $route;

View File

@ -1,5 +1,7 @@
<?php
use \FuzeWorks\Event;
class LayoutLoadEvent extends Event {
public $directory;

View File

@ -1,5 +1,7 @@
<?php
use \FuzeWorks\Event;
class ModelLoadEvent extends Event {
public $directory;

View File

@ -1,5 +1,7 @@
<?php
use \FuzeWorks\Event;
class RouterRouteEvent extends Event {
public $controller;

View File

@ -1,5 +1,7 @@
<?php
namespace FuzeWorks;
abstract class Bus {
protected $core;
protected $mods;

View File

@ -1,5 +1,7 @@
<?php
namespace FuzeWorks;
class Event {
private $cancelled = false;

View File

@ -1,5 +1,7 @@
<?php
namespace FuzeWorks;
/**
* Class EventPriority
*

View File

@ -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);
}
/**

View File

@ -1,5 +1,7 @@
<?php
namespace FuzeWorks;
/**
* Class Module
*

View File

@ -1,5 +1,8 @@
<?php
namespace FuzeWorks;
use \Exception;
/**
* Config Module
*

View File

@ -1,5 +1,9 @@
<?php
namespace FuzeWorks;
use \stdClass;
use \Exception;
if (!defined('FUZESYSPATH')) {
define('STARTTIME', microtime(true));
define( 'FUZESYSPATH', dirname(__FILE__) . '/' );
@ -131,11 +135,15 @@ class Core {
$CLASS->setModulePath($cfg->directory);
}
if (method_exists($CLASS, 'setModuleLinkName')) {
$CLASS->setModuleLinkName($cfg->name);
$CLASS->setModuleLinkName(strtolower($cfg->module_name));
}
if (method_exists($CLASS, 'setModuleName')) {
$CLASS->setModuleName($name);
}
if (!method_exists($CLASS, 'onLoad')) {
throw new Exception("Module '".$name."' does not have an onLoad() method! Invalid module", 1);
}
$CLASS->onLoad();
// Add to the loaded modules

View File

@ -3,7 +3,10 @@
* @author FuzeNetwork
* @package files
*/
namespace FuzeWorks;
use \Exception;
/**
* @name Events
*/
@ -84,10 +87,10 @@ class Events extends Bus{
// No event arguments? Looks like an notify-event
if(func_num_args() == 1){
// Load notify-event-class
$eventClass = 'NotifierEvent';
$eventClass = '\FuzeWorks\NotifierEvent';
}else{
// No notify-event: we tried all we could
throw new \Exception("Event ".$eventName." could not be found!");
throw new Exception("Event ".$eventName." could not be found!");
}
}
}

View File

@ -1,5 +1,8 @@
<?php
namespace FuzeWorks;
use \Exception;
class Layout extends Bus {
private $Smarty = array();

View File

@ -1,5 +1,8 @@
<?php
namespace FuzeWorks;
use \Exception;
class Logger extends Bus{
public $infoErrors = array();
@ -113,6 +116,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 "\t" . implode("<br/>", $result);
}
/* =========================================LOGGING METHODS==============================================================*/

View File

@ -3,6 +3,8 @@
* @author FuzeNetwork
*/
namespace FuzeWorks;
class Models extends Bus{
private $models_array = array();
@ -25,7 +27,7 @@ class Models extends Bus{
$this->models_array[$name] = $this->model_types[$name];
} elseif (file_exists($file)){
require_once($file);
$model = ucfirst($name);
$model = "\Model\\" . ucfirst($name);
$this->logger->logInfo('Loading Model: '.$model, $model);
$this->models_array[$name] = new $model($this->core);
} else{

View File

@ -1,6 +1,10 @@
<?php
class Database extends Bus {
use \FuzeWorks\Module;
use \Exception;
use \PDO;
class Database extends Module {
private $DBH;
public $prefix;

View File

@ -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(){

View File

@ -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('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,
);

View File

@ -1,6 +1,8 @@
<?php
class Router extends Bus {
use \FuzeWorks\Module;
class Router extends Module {
public $controller = null;
public $controllerName = null;
@ -120,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')) {

View File

@ -1,8 +1,8 @@
<?php
namespace Module\Sections;
use \Module;
use \EventPriority;
use \FuzeWorks\Module;
use \FuzeWorks\EventPriority;
/**
* Sections module, see usage documentation

View File

@ -17,4 +17,6 @@ return array(
'date_created' => '29-04-2015',
'date_updated' => '29-04-2015',
'enabled' => true,
);

View File

@ -7,7 +7,7 @@ if (!defined('FUZEPATH')) {
require_once( dirname(__FILE__) . "/Core/System/class.core.php");
// Load it
$core = new Core();
$core = new \FuzeWorks\Core();
$core->init();
$core->loadMod('router');
$core->mods->router->setPath( (isset($_GET['path']) ? $_GET['path'] : null) );