Merge branch 'master' into 'master'
Events for Views and Models Implemented events to load the correct view and model Also did some bugfixes See merge request !9
This commit is contained in:
commit
7809a4efd5
13
Core/Events/event.layoutLoadEvent.php
Normal file
13
Core/Events/event.layoutLoadEvent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class LayoutLoadEvent extends Event {
|
||||
|
||||
public $directory;
|
||||
public $layout;
|
||||
|
||||
public function init($layout){
|
||||
$this->layout = $layout;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -92,6 +92,9 @@ class Core {
|
||||
$CLASS->onLoad();
|
||||
|
||||
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
|
||||
$path = FUZEPATH . "/Core/Mods/";
|
||||
$path = FUZEPATH . "Modules/";
|
||||
|
||||
// Chech if the requested module is set
|
||||
if (isset($this->register[$name])) {
|
||||
@ -185,7 +188,7 @@ class Core {
|
||||
|
||||
public function buildModRegister() {
|
||||
$this->mods->logger->newLevel("Building Mod Register", 'Core');
|
||||
$dir = FUZEPATH . "Core/Mods/";
|
||||
$dir = FUZEPATH . "Modules/";
|
||||
$mods = array_values(array_diff(scandir($dir), array('..', '.')));
|
||||
$register = array();
|
||||
for ($i=0; $i < count($mods); $i++) {
|
||||
@ -199,6 +202,7 @@ class Core {
|
||||
// Append directory
|
||||
$cfg->directory = $mod_dir;
|
||||
$register[$name] = (array) $cfg;
|
||||
$this->mods->logger->log("Found module: '".$name."'");
|
||||
} else {
|
||||
// Get the name
|
||||
$name = $mods[$i];
|
||||
@ -212,6 +216,7 @@ class Core {
|
||||
$cfg->versions = array();
|
||||
$cfg->directory = $mod_dir;
|
||||
$register[$name] = (array)$cfg;
|
||||
$this->mods->logger->log("Found module: '".$name."'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ class Events extends Bus{
|
||||
// Event Preparation:
|
||||
public function buildEventRegister() {
|
||||
$this->logger->newLevel("Building Event Register", 'Events');
|
||||
$dir = FUZEPATH . "/Core/Mods/";
|
||||
$dir = FUZEPATH . "/Modules/";
|
||||
$mods = $this->config->modregister->register;
|
||||
foreach ($mods as $key => $value) {
|
||||
try {
|
||||
|
@ -72,11 +72,15 @@ class Layout extends Bus {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function view($view = "default", $dir = null) {
|
||||
public function view($view = "default") {
|
||||
// Chech if Smarty is loaded
|
||||
if (!$this->loaded)
|
||||
$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
|
||||
$vw = explode('/', $view);
|
||||
if (count($vw) == 1) {
|
||||
@ -98,8 +102,7 @@ class Layout extends Bus {
|
||||
}
|
||||
|
||||
// Set the directory
|
||||
$dir = (!isset($dir) ? FUZEPATH . "/Application/" . '/Views' : $dir);
|
||||
$this->Smarty['main']->setTemplateDir($dir);
|
||||
$this->Smarty['main']->setTemplateDir($directory);
|
||||
|
||||
// Set the title
|
||||
$this->Smarty['main']->assign('title', $this->title);
|
||||
@ -107,7 +110,7 @@ class Layout extends Bus {
|
||||
// Get the viewdir
|
||||
// @TODO: Fix this for custom directories
|
||||
$one = FUZEPATH;
|
||||
$two = $dir . "/";
|
||||
$two = $directory . "/";
|
||||
$count_one = strlen($one);
|
||||
$count_two = strlen($two);
|
||||
$length_three = $count_two - $count_one;
|
||||
@ -122,26 +125,26 @@ class Layout extends Bus {
|
||||
}catch (\SmartyException $e){
|
||||
|
||||
// Throw error on failure
|
||||
$this->logger->logError('Could not load view '.$dir.'/'.$vw.' :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__);
|
||||
throw new Exception\Layout('Could not load view '.$dir.'/'.$vw);
|
||||
$this->logger->logError('Could not load view '.$directory.'/'.$vw.' :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__);
|
||||
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
|
||||
if (!$this->loaded)
|
||||
$this->load();
|
||||
|
||||
// Set the directory
|
||||
$dir = ($dir == "" ? FUZEPATH . "/Application/" . '/Views' : $dir);
|
||||
$this->Smarty['main']->setTemplateDir($dir);
|
||||
$directory = ($directory == "" ? FUZEPATH . "/Application/" . '/Views' : $directory);
|
||||
$this->Smarty['main']->setTemplateDir($directory);
|
||||
|
||||
// Set the title
|
||||
$this->Smarty['main']->assign('title', $this->title);
|
||||
|
||||
// Get the viewdir
|
||||
$one = FUZEPATH;
|
||||
$two = $dir . "/";
|
||||
$two = $directory . "/";
|
||||
$count_one = strlen($one);
|
||||
$count_two = strlen($two);
|
||||
$length_three = $count_two - $count_one;
|
||||
@ -155,8 +158,8 @@ class Layout extends Bus {
|
||||
}catch (\SmartyException $e){
|
||||
|
||||
// Throw error on failure
|
||||
$this->logger->logError('Could not load view '.$dir.'/view.'.$view.'.tpl :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__);
|
||||
throw new Exception\Layout('Could not load view '.$dir.'/view.'.$view.'.tpl');
|
||||
$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 '.$directory.'/view.'.$view.'.tpl');
|
||||
}
|
||||
}
|
||||
}
|
@ -30,6 +30,8 @@ class Sections extends Module {
|
||||
// Register Events
|
||||
$this->events->addListener(array($this, 'eventRegisterBuild'), 'eventRegisterBuildEvent', 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,38 @@ class Sections extends Module {
|
||||
*/
|
||||
public function eventRegisterBuild($event) {
|
||||
$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) {
|
||||
$section = $this->getSection($this->currentSection);
|
||||
$event->directory = $section['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) {
|
||||
$section = $this->getSection($this->currentSection);
|
||||
$event->directory = $section['model_path'];
|
||||
}
|
||||
return $event;
|
||||
}
|
||||
|
||||
@ -54,14 +88,28 @@ class Sections extends Module {
|
||||
* @param String View_path, where to find the views for this section
|
||||
*/
|
||||
public function addSection($name, $module_section = false, $module_name = null, $controller_path = null, $model_path = null, $view_path = null) {
|
||||
$data = array(
|
||||
'name' => $name,
|
||||
'module_section' => $module_section,
|
||||
'module_name' => $module_name,
|
||||
'controller_path' => FUZEPATH . $controller_path,
|
||||
'model_path' => FUZEPATH . $model_path,
|
||||
'view_path' => FUZEPATH . $view_path,
|
||||
);
|
||||
if ($module_section) {
|
||||
$m = $this->core->loadMod($module_name);
|
||||
$m_dir = $m->getModulePath();
|
||||
$data = array(
|
||||
'name' => $name,
|
||||
'module_section' => $module_section,
|
||||
'module_name' => $module_name,
|
||||
'controller_path' => $m_dir . '/Controller/',
|
||||
'model_path' => $m_dir . '/Models/',
|
||||
'view_path' => $m_dir . '/Views/',
|
||||
);
|
||||
} else {
|
||||
$data = array(
|
||||
'name' => $name,
|
||||
'module_section' => $module_section,
|
||||
'module_name' => $module_name,
|
||||
'controller_path' => FUZEPATH . $controller_path,
|
||||
'model_path' => FUZEPATH . $model_path,
|
||||
'view_path' => FUZEPATH . $view_path,
|
||||
);
|
||||
}
|
||||
|
||||
$this->config->set('sections', $name, $data, $this->getModulePath());
|
||||
}
|
||||
|
||||
@ -122,6 +170,18 @@ class Sections extends Module {
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a section file
|
||||
* @access public
|
||||
* @param String section name
|
||||
* @return Array Section
|
||||
*/
|
||||
public function getSection($name) {
|
||||
if (isset($this->cfg->$name)) {
|
||||
return $this->cfg->$name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves section information from the config file
|
||||
* @access public
|
Loading…
Reference in New Issue
Block a user