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();
|
$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."'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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,38 @@ 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) {
|
||||||
|
$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;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,14 +88,28 @@ class Sections extends Module {
|
||||||
* @param String View_path, where to find the views for this section
|
* @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) {
|
public function addSection($name, $module_section = false, $module_name = null, $controller_path = null, $model_path = null, $view_path = null) {
|
||||||
$data = array(
|
if ($module_section) {
|
||||||
'name' => $name,
|
$m = $this->core->loadMod($module_name);
|
||||||
'module_section' => $module_section,
|
$m_dir = $m->getModulePath();
|
||||||
'module_name' => $module_name,
|
$data = array(
|
||||||
'controller_path' => FUZEPATH . $controller_path,
|
'name' => $name,
|
||||||
'model_path' => FUZEPATH . $model_path,
|
'module_section' => $module_section,
|
||||||
'view_path' => FUZEPATH . $view_path,
|
'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());
|
$this->config->set('sections', $name, $data, $this->getModulePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +170,18 @@ class Sections extends Module {
|
||||||
return $event;
|
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
|
* Retrieves section information from the config file
|
||||||
* @access public
|
* @access public
|
Loading…
Reference in New Issue
Block a user