Merge branch 'master' into 'master'

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

Fixes and completes the MV rewrite. Besides that it fixes #26 from the pragmatic rewrites.

See merge request !12
This commit is contained in:
Abel Hoogeveen 2015-04-29 13:50:01 +02:00
commit ed8aff38e7
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){
if($directory === null){
$directory = FUZEPATH . "/Application/Models";
}
// Model load event
$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';
if (isset($this->model_types[$name])) {

View File

@ -5,9 +5,10 @@ class Router extends Bus {
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);
@ -90,9 +91,6 @@ class Router extends Bus {
$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();
}
/**
@ -100,6 +98,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."'");

View File

@ -12,5 +12,6 @@ $core->init();
$core->loadMod('router');
$core->mods->router->setPath( (isset($_GET['path']) ? $_GET['path'] : null) );
$core->mods->router->route();
$core->mods->router->loadController();
?>