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 <?php
namespace Controller;
use \FuzeWorks\Bus;
class Standard extends Bus { class Standard extends Bus {
public function __construct(&$core) { public function __construct(&$core) {
parent::__construct($core); parent::__construct($core);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,15 @@
<?php <?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 * 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 * Set the type of this model. Eg, use techfuze/databasemodel and Databasemodel to get a SQL connected model
* @access protected * @access protected
* @param String Module_name, the name of the module where the model can be found * @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) { protected function setType($module_name, $model_type) {
$this->core->loadMod($module_name); $mod = $this->core->loadMod($module_name);
$this->parentClass = new $class_name($this->core); $this->parentClass = $mod->giveModel($model_type);
} }
/** /**

View File

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

View File

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

View File

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

View File

@ -3,7 +3,10 @@
* @author FuzeNetwork * @author FuzeNetwork
* @package files * @package files
*/ */
namespace FuzeWorks;
use \Exception;
/** /**
* @name Events * @name Events
*/ */
@ -84,10 +87,10 @@ class Events extends Bus{
// No event arguments? Looks like an notify-event // No event arguments? Looks like an notify-event
if(func_num_args() == 1){ if(func_num_args() == 1){
// Load notify-event-class // Load notify-event-class
$eventClass = 'NotifierEvent'; $eventClass = '\FuzeWorks\NotifierEvent';
}else{ }else{
// No notify-event: we tried all we could // 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 <?php
namespace FuzeWorks;
use \Exception;
class Layout extends Bus { class Layout extends Bus {
private $Smarty = array(); private $Smarty = array();

View File

@ -1,5 +1,8 @@
<?php <?php
namespace FuzeWorks;
use \Exception;
class Logger extends Bus{ class Logger extends Bus{
public $infoErrors = array(); 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==============================================================*/ /* =========================================LOGGING METHODS==============================================================*/

View File

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

View File

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

View File

@ -1,6 +1,11 @@
<?php <?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 $fields = array();
public $primary = 'id'; public $primary = 'id';
@ -8,7 +13,12 @@ class DatabaseModel extends Bus{
public function __construct(&$core){ public function __construct(&$core){
parent::__construct($core); parent::__construct($core);
$this->core->loadMod('database'); }
public function onLoad() {}
public function giveModel($type) {
return new DatabaseModel($this->core);
} }
public function select(){ public function select(){

View File

@ -1,11 +1,12 @@
<?php <?php
return array( return array(
'module_class' => 'DatabaseModel', 'module_class' => 'Module\DatabaseModel',
'module_file' => 'class.model.php', 'module_file' => 'class.model.php',
'module_name' => 'databasemodel', 'module_name' => 'databasemodel',
'abstract' => true, 'abstract' => false,
'dependencies' => array('database'),
'name' => 'DatabaseModel', 'name' => 'DatabaseModel',
'description' => 'Abstract type for easy database queries', 'description' => 'Abstract type for easy database queries',
@ -15,4 +16,6 @@ return array(
'date_created' => '26-02-2015', 'date_created' => '26-02-2015',
'date_updated' => '26-02-2015', 'date_updated' => '26-02-2015',
'enabled' => true,
); );

View File

@ -1,6 +1,8 @@
<?php <?php
class Router extends Bus { use \FuzeWorks\Module;
class Router extends Module {
public $controller = null; public $controller = null;
public $controllerName = null; public $controllerName = null;
@ -120,7 +122,7 @@ class Router extends Bus {
if (!class_exists(ucfirst($this->controllerName))) if (!class_exists(ucfirst($this->controllerName)))
require_once($file); require_once($file);
$this->controllerClass = ucfirst($this->controllerName); $this->controllerClass = "\Controller\\" . ucfirst($this->controllerName);
$this->controller = new $this->controllerClass($this->core); $this->controller = new $this->controllerClass($this->core);
if (method_exists($this->controller, $this->function) || method_exists($this->controller, '__call')) { if (method_exists($this->controller, $this->function) || method_exists($this->controller, '__call')) {

View File

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

View File

@ -17,4 +17,6 @@ return array(
'date_created' => '29-04-2015', 'date_created' => '29-04-2015',
'date_updated' => '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"); require_once( dirname(__FILE__) . "/Core/System/class.core.php");
// Load it // Load it
$core = new Core(); $core = new \FuzeWorks\Core();
$core->init(); $core->init();
$core->loadMod('router'); $core->loadMod('router');
$core->mods->router->setPath( (isset($_GET['path']) ? $_GET['path'] : null) ); $core->mods->router->setPath( (isset($_GET['path']) ? $_GET['path'] : null) );