Did the MVC Rewrite. Each component now has events. Fixes #9 , #10 , #20

This commit is contained in:
Abel Hoogeveen 2015-04-29 13:46:33 +02:00
parent 54c81f769a
commit 156f4a3460
5 changed files with 57 additions and 9 deletions

View File

@ -0,0 +1,20 @@
<?php
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;
}
}
?>

View File

@ -0,0 +1,13 @@
<?php
class ModelLoadEvent extends Event {
public $directory;
public $model;
public function init($model){
$this->model = $model;
}
}
?>

View File

@ -14,9 +14,10 @@ class Models extends Bus{
} }
public function loadModel($name, $directory = null){ public function loadModel($name, $directory = null){
if($directory === null){ // Model load event
$directory = FUZEPATH . "/Application/Models"; $event = $this->events->fireEvent('modelLoadEvent', $name);
} $directory = ($event->directory === null ? FUZEPATH . "/Application/Models" : $event->directory);
$name = ($event->model === null ? $name : $event->model);
$file = $directory.'/model.'.$name.'.php'; $file = $directory.'/model.'.$name.'.php';
if (isset($this->model_types[$name])) { if (isset($this->model_types[$name])) {

View File

@ -5,9 +5,10 @@ class Router extends Bus {
public $controller = null; public $controller = null;
public $controllerName = null; public $controllerName = null;
public $function = null; public $function = null;
private $route = array(); public $route = array();
private $parameters = array(); public $parameters = array();
private $path; public $directory;
public $path;
public function __construct(&$core) { public function __construct(&$core) {
parent::__construct($core); parent::__construct($core);
@ -90,9 +91,6 @@ class Router extends Bus {
$this->function = ($event->function === null || empty($event->function) ? $this->config->main->default_function : $event->function); $this->function = ($event->function === null || empty($event->function) ? $this->config->main->default_function : $event->function);
$this->parameters = $event->parameters; $this->parameters = $event->parameters;
$this->directory = ($event->directory === null || empty($event->directory) ? FUZEPATH . "/Application/Controller/" : $event->directory); $this->directory = ($event->directory === null || empty($event->directory) ? FUZEPATH . "/Application/Controller/" : $event->directory);
// Load the controller
$this->loadController();
} }
/** /**
@ -100,6 +98,21 @@ class Router extends Bus {
* @access public * @access public
*/ */
public function loadController() { 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"; $file = $this->directory . "controller.".strtolower($this->controllerName).".php";
$this->logger->log("Loading controller from file: '".$file."'"); $this->logger->log("Loading controller from file: '".$file."'");

View File

@ -12,5 +12,6 @@ $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) );
$core->mods->router->route(); $core->mods->router->route();
$core->mods->router->loadController();
?> ?>