Moved Modules to a new directory, makes more sense. Also started adding events for the renewed sections, see #19 and #18

This commit is contained in:
Abel Hoogeveen 2015-03-20 10:20:30 +01:00
parent 91740236e7
commit 9b3bf5fc20
10 changed files with 68 additions and 15 deletions

View File

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

View File

@ -92,6 +92,9 @@ class Core {
$CLASS->onLoad(); $CLASS->onLoad();
return $this->mods->{strtolower($data['moduleLinkName'])} = &$CLASS; return $this->mods->{strtolower($data['moduleLinkName'])} = &$CLASS;
} else {
$c = &$this->mods->{strtolower($data['moduleLinkName'])};
return $c;
} }
} }
@ -104,7 +107,7 @@ class Core {
} }
// The basic module path // The basic module path
$path = FUZEPATH . "/Core/Mods/"; $path = FUZEPATH . "Modules/";
// Chech if the requested module is set // Chech if the requested module is set
if (isset($this->register[$name])) { if (isset($this->register[$name])) {
@ -185,7 +188,7 @@ class Core {
public function buildModRegister() { public function buildModRegister() {
$this->mods->logger->newLevel("Building Mod Register", 'Core'); $this->mods->logger->newLevel("Building Mod Register", 'Core');
$dir = FUZEPATH . "Core/Mods/"; $dir = FUZEPATH . "Modules/";
$mods = array_values(array_diff(scandir($dir), array('..', '.'))); $mods = array_values(array_diff(scandir($dir), array('..', '.')));
$register = array(); $register = array();
for ($i=0; $i < count($mods); $i++) { for ($i=0; $i < count($mods); $i++) {
@ -199,6 +202,7 @@ class Core {
// Append directory // Append directory
$cfg->directory = $mod_dir; $cfg->directory = $mod_dir;
$register[$name] = (array) $cfg; $register[$name] = (array) $cfg;
$this->mods->logger->log("Found module: '".$name."'");
} else { } else {
// Get the name // Get the name
$name = $mods[$i]; $name = $mods[$i];
@ -212,6 +216,7 @@ class Core {
$cfg->versions = array(); $cfg->versions = array();
$cfg->directory = $mod_dir; $cfg->directory = $mod_dir;
$register[$name] = (array)$cfg; $register[$name] = (array)$cfg;
$this->mods->logger->log("Found module: '".$name."'");
} }
} }

View File

@ -155,7 +155,7 @@ class Events extends Bus{
// Event Preparation: // Event Preparation:
public function buildEventRegister() { public function buildEventRegister() {
$this->logger->newLevel("Building Event Register", 'Events'); $this->logger->newLevel("Building Event Register", 'Events');
$dir = FUZEPATH . "/Core/Mods/"; $dir = FUZEPATH . "/Modules/";
$mods = $this->config->modregister->register; $mods = $this->config->modregister->register;
foreach ($mods as $key => $value) { foreach ($mods as $key => $value) {
try { try {

View File

@ -72,11 +72,15 @@ class Layout extends Bus {
return $this->title; return $this->title;
} }
public function view($view = "default", $dir = null) { public function view($view = "default") {
// Chech if Smarty is loaded // Chech if Smarty is loaded
if (!$this->loaded) if (!$this->loaded)
$this->load(); $this->load();
$event = $this->events->fireEvent('layoutLoadEvent', $view);
$directory = ($event->directory === null ? FUZEPATH . "/Application/Views" : $event->directory);
$view = ($event->layout === null ? $view : $event->layout);
// Set the file name and location // Set the file name and location
$vw = explode('/', $view); $vw = explode('/', $view);
if (count($vw) == 1) { if (count($vw) == 1) {
@ -98,8 +102,7 @@ class Layout extends Bus {
} }
// Set the directory // Set the directory
$dir = (!isset($dir) ? FUZEPATH . "/Application/" . '/Views' : $dir); $this->Smarty['main']->setTemplateDir($directory);
$this->Smarty['main']->setTemplateDir($dir);
// Set the title // Set the title
$this->Smarty['main']->assign('title', $this->title); $this->Smarty['main']->assign('title', $this->title);
@ -107,7 +110,7 @@ class Layout extends Bus {
// Get the viewdir // Get the viewdir
// @TODO: Fix this for custom directories // @TODO: Fix this for custom directories
$one = FUZEPATH; $one = FUZEPATH;
$two = $dir . "/"; $two = $directory . "/";
$count_one = strlen($one); $count_one = strlen($one);
$count_two = strlen($two); $count_two = strlen($two);
$length_three = $count_two - $count_one; $length_three = $count_two - $count_one;
@ -122,26 +125,26 @@ class Layout extends Bus {
}catch (\SmartyException $e){ }catch (\SmartyException $e){
// Throw error on failure // Throw error on failure
$this->logger->logError('Could not load view '.$dir.'/'.$vw.' :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__); $this->logger->logError('Could not load view '.$directory.'/'.$vw.' :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__);
throw new Exception\Layout('Could not load view '.$dir.'/'.$vw); throw new Exception\Layout('Could not load view '.$directory.'/'.$vw);
} }
} }
public function get($view = "default", $dir = "") { public function get($view = "default", $directory = "") {
// Chech if Smarty is loaded // Chech if Smarty is loaded
if (!$this->loaded) if (!$this->loaded)
$this->load(); $this->load();
// Set the directory // Set the directory
$dir = ($dir == "" ? FUZEPATH . "/Application/" . '/Views' : $dir); $directory = ($directory == "" ? FUZEPATH . "/Application/" . '/Views' : $directory);
$this->Smarty['main']->setTemplateDir($dir); $this->Smarty['main']->setTemplateDir($directory);
// Set the title // Set the title
$this->Smarty['main']->assign('title', $this->title); $this->Smarty['main']->assign('title', $this->title);
// Get the viewdir // Get the viewdir
$one = FUZEPATH; $one = FUZEPATH;
$two = $dir . "/"; $two = $directory . "/";
$count_one = strlen($one); $count_one = strlen($one);
$count_two = strlen($two); $count_two = strlen($two);
$length_three = $count_two - $count_one; $length_three = $count_two - $count_one;
@ -155,8 +158,8 @@ class Layout extends Bus {
}catch (\SmartyException $e){ }catch (\SmartyException $e){
// Throw error on failure // Throw error on failure
$this->logger->logError('Could not load view '.$dir.'/view.'.$view.'.tpl :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__); $this->logger->logError('Could not load view '.$directory.'/view.'.$view.'.tpl :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__);
throw new Exception\Layout('Could not load view '.$dir.'/view.'.$view.'.tpl'); throw new Exception\Layout('Could not load view '.$directory.'/view.'.$view.'.tpl');
} }
} }
} }

View File

@ -30,6 +30,8 @@ class Sections extends Module {
// Register Events // Register Events
$this->events->addListener(array($this, 'eventRegisterBuild'), 'eventRegisterBuildEvent', EventPriority::NORMAL); $this->events->addListener(array($this, 'eventRegisterBuild'), 'eventRegisterBuildEvent', EventPriority::NORMAL);
$this->events->addListener(array($this, 'routerEvent'), 'routerRouteEvent', EventPriority::NORMAL); $this->events->addListener(array($this, 'routerEvent'), 'routerRouteEvent', EventPriority::NORMAL);
$this->events->addListener(array($this, 'layoutLoadEvent'), 'layoutLoadEvent', EventPriority::NORMAL);
$this->events->addListener(array($this, 'modelLoadevent'), 'modelLoadEvent', EventPriority::NORMAL);
} }
/** /**
@ -40,6 +42,36 @@ class Sections extends Module {
*/ */
public function eventRegisterBuild($event) { public function eventRegisterBuild($event) {
$event->addEvent('sections', 'routerRouteEvent'); $event->addEvent('sections', 'routerRouteEvent');
$event->addEvent('sections', 'layoutLoadEvent');
$event->addEvent('sections', 'modelLoadEvent');
return $event;
}
/**
* Redirects layouts to the new section
* @access public
* @param layoutLoadEvent Event
* @return layoutLoadEvent Event
*/
public function layoutLoadEvent($event) {
$layout_name = $event->layout;
if ($this->currentSection !== null) {
$event->directory = $this->view_path;
}
return $event;
}
/**
* Redirects models to the new section
* @access public
* @param layoutLoadEvent Event
* @return layoutLoadEvent Event
*/
public function modelLoadEvent($event) {
$model_name = $event->model;
if ($this->currentSection !== null) {
$event->directory = $this->model_path;
}
return $event; return $event;
} }