Updated entire project to PSR2 code standard. Some classes still need to be moved around.
This commit is contained in:
parent
edf1ce2fa3
commit
9f4742b063
|
@ -21,3 +21,5 @@ build/
|
|||
Modules/admin/themes/adminlte2.1/plugins/
|
||||
Modules/admin/themes/adminlte2.1/dist/
|
||||
Modules/admin/themes/adminlte2.1/bootstrap/
|
||||
doc
|
||||
nbproject
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php return array (
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'contact_email' => '',
|
||||
'contact_name' => '',
|
||||
'contact_adress' => '',
|
||||
|
@ -6,5 +8,5 @@
|
|||
'contact_postal_code' => '',
|
||||
'contact_region' => '',
|
||||
'contact_country' => '',
|
||||
'contact_city' => ''
|
||||
) ;
|
||||
'contact_city' => '',
|
||||
);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php return array (
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'enable_composer' => true,
|
||||
'composer_autoloader' => ''
|
||||
) ;
|
||||
'composer_autoloader' => '',
|
||||
);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php return array (
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'type' => '',
|
||||
'host' => '',
|
||||
'database' => '',
|
||||
|
@ -6,4 +8,4 @@
|
|||
'password' => '',
|
||||
'prefix' => '',
|
||||
'debug' => false,
|
||||
) ;
|
||||
);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php return array (
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'debug' => false,
|
||||
'error_reporting' => true,
|
||||
) ;
|
||||
);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php return array (
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'SITE_URL' => '',
|
||||
'SITE_DOMAIN' => '',
|
||||
'SERVER_NAME' => '',
|
||||
|
@ -6,4 +8,4 @@
|
|||
'administrator_mail' => '',
|
||||
'default_controller' => 'standard',
|
||||
'default_function' => 'index',
|
||||
) ;
|
||||
);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
return array(
|
||||
|
||||
// '/^alias(|\-(?P<function>.*?))$/' => array(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,17 +20,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Application\Controller;
|
||||
use \FuzeWorks\ControllerAbstract;
|
||||
use \FuzeWorks\Layout;
|
||||
|
||||
use FuzeWorks\ControllerAbstract;
|
||||
use FuzeWorks\Layout;
|
||||
|
||||
/**
|
||||
* The default controller of FuzeWorks.
|
||||
|
@ -38,23 +41,20 @@ use \FuzeWorks\Layout;
|
|||
* This controller gets loaded when the '/' path is provided, eg. the home page.
|
||||
* By default, the index function gets loaded.
|
||||
*
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Standard extends ControllerAbstract {
|
||||
|
||||
class Standard extends ControllerAbstract
|
||||
{
|
||||
/**
|
||||
* The default function of FuzeWorks.
|
||||
*
|
||||
* This code gets loaded for the Home page
|
||||
*
|
||||
* @param array $path The path provided by the HTTP Server
|
||||
* @return void
|
||||
*/
|
||||
public function index($path = null) {
|
||||
public function index($path = null)
|
||||
{
|
||||
Layout::view('home');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,33 +20,35 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Application\Model;
|
||||
use \FuzeWorks\Model;
|
||||
|
||||
use FuzeWorks\Model;
|
||||
|
||||
/**
|
||||
* Example model to show how to use models
|
||||
* Example model to show how to use models.
|
||||
*
|
||||
* This model connects to an example table if present in the database
|
||||
* @package net.techfuze.fuzeworks.application.model
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Example extends Model{
|
||||
|
||||
public function __construct(&$core){
|
||||
class Example extends Model
|
||||
{
|
||||
public function __construct(&$core)
|
||||
{
|
||||
parent::__construct($core);
|
||||
|
||||
$this->setType('core/databaseutils', 'Model');
|
||||
$this->table = 'example';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,31 +20,34 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Application\Model;
|
||||
use \FuzeWorks\Model;
|
||||
|
||||
use FuzeWorks\Model;
|
||||
|
||||
/**
|
||||
* SQLTable model
|
||||
* SQLTable model.
|
||||
*
|
||||
* This model connects to the querybuilder and is used to quickly interact with SQL tables.
|
||||
*
|
||||
* Start building a query AND DON'T FORGET TO USE setTable() before executing the query
|
||||
* @package net.techfuze.fuzeworks.application.model
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Sqltable extends Model{
|
||||
|
||||
public function __construct(){
|
||||
|
||||
class Sqltable extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setType('core/databaseutils', 'Model');
|
||||
$this->fields = '*';
|
||||
$this->table = 'table';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,11 +20,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
?>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,11 +20,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
?>
|
||||
|
@ -65,11 +67,17 @@
|
|||
This website is currently under development.
|
||||
</p>
|
||||
<p>
|
||||
<?php if ($vars['adminMail'] == '') { ?>
|
||||
<?php if ($vars['adminMail'] == '') {
|
||||
?>
|
||||
For further information, please contact the website administrator</a>
|
||||
<?php } else { ?>
|
||||
For further information, please contact <a href='mailto:<?php echo($vars['adminMail']); ?>'><?php echo($vars['adminMail']); ?></a>
|
||||
<?php } ?>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
For further information, please contact <a href='mailto:<?php echo $vars['adminMail'];
|
||||
?>'><?php echo $vars['adminMail'];
|
||||
?></a>
|
||||
<?php
|
||||
} ?>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,37 +20,39 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Application;
|
||||
use \FuzeWorks\Bus;
|
||||
|
||||
use FuzeWorks\Bus;
|
||||
|
||||
/**
|
||||
* Class init
|
||||
* Class init.
|
||||
*
|
||||
* This class will be loaded before the a controller is loaded. Handy to do some we-need-to-do-this-all-the-time-things like setting locales or importing functions.
|
||||
* Can also be used to authenticate users and provide all views with sessionData.
|
||||
* Will only be loaded if the default callable is used.
|
||||
* @package net.techfuze.fuzeworks.application
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Init extends Bus {
|
||||
|
||||
class Init extends Bus
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param \FuzeWorks\Core $core Pointer to core class
|
||||
*/
|
||||
public function __construct(&$core){
|
||||
public function __construct(&$core)
|
||||
{
|
||||
parent::__construct($core);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,58 +20,63 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
use \FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets loaded when a view is loaded.
|
||||
*
|
||||
* Use this to cancel the loading of a view, or change the file or engine of a view
|
||||
*
|
||||
* @package net.techfuze.fuzeworks.core.event
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class LayoutLoadViewEvent extends Event {
|
||||
|
||||
class LayoutLoadViewEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The directory of the view to be loaded
|
||||
* The directory of the view to be loaded.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $directory;
|
||||
|
||||
/**
|
||||
* The file of the view to be loaded
|
||||
* The file of the view to be loaded.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $file;
|
||||
|
||||
/**
|
||||
* The engine the file will be loaded with
|
||||
* The engine the file will be loaded with.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $engine;
|
||||
|
||||
/**
|
||||
* The assigned variables to the template
|
||||
* The assigned variables to the template.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $assigned_variables;
|
||||
|
||||
public function init($file, $directory, $engine, $assigned_variables){
|
||||
public function init($file, $directory, $engine, $assigned_variables)
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->directory = $directory;
|
||||
$this->engine = $engine;
|
||||
$this->assigned_variables = $assigned_variables;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,44 +20,47 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
use \FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets loaded when a model is loaded.
|
||||
*
|
||||
* Use this to cancel the loading of a model, or change the model to be loaded
|
||||
*
|
||||
* @package net.techfuze.fuzeworks.core.event
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class ModelLoadEvent extends Event {
|
||||
|
||||
class ModelLoadEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The directory the model gets loaded from
|
||||
* The directory the model gets loaded from.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $directory = null;
|
||||
|
||||
/**
|
||||
* The name of the model to be loaded
|
||||
* The name of the model to be loaded.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $model = null;
|
||||
|
||||
public function init($model, $directory){
|
||||
public function init($model, $directory)
|
||||
{
|
||||
$this->model = $model;
|
||||
$this->directory = $directory;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,28 +20,30 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
use \FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Class routerLoadCallableEvent
|
||||
* Class routerLoadCallableEvent.
|
||||
*
|
||||
* Called when a callable is about to be loaded
|
||||
*
|
||||
* @package net.techfuze.fuzeworks.core.event
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class routerLoadCallableEvent extends Event{
|
||||
|
||||
class routerLoadCallableEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var callable The callable
|
||||
*/
|
||||
|
@ -53,13 +55,14 @@ class routerLoadCallableEvent extends Event{
|
|||
public $matches = array();
|
||||
|
||||
/**
|
||||
* The route which was matched
|
||||
* The route which was matched.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $route = null;
|
||||
|
||||
public function init($callable, $matches, $route){
|
||||
|
||||
public function init($callable, $matches, $route)
|
||||
{
|
||||
$this->callable = $callable;
|
||||
$this->matches = $matches;
|
||||
$this->route = $route;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,48 +20,51 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
use \FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Class routerRouteEvent
|
||||
* Class routerRouteEvent.
|
||||
*
|
||||
* Fired after the router has extracted the path, and is about to find out what route matches the path.
|
||||
*
|
||||
* This Event is usefull for adding routes.
|
||||
*
|
||||
* @package net.techfuze.fuzeworks.core.event
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class routerRouteEvent extends Event{
|
||||
|
||||
class routerRouteEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var array The routing table
|
||||
*/
|
||||
public $routes;
|
||||
|
||||
/**
|
||||
* @var boolean Whether the callable will be loaded directly after or not
|
||||
* @var bool Whether the callable will be loaded directly after or not
|
||||
*/
|
||||
public $loadCallable;
|
||||
|
||||
/**
|
||||
* The current path input to FuzeWorks
|
||||
* The current path input to FuzeWorks.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $path;
|
||||
|
||||
public function init($routes, $loadCallable, $path){
|
||||
|
||||
public function init($routes, $loadCallable, $path)
|
||||
{
|
||||
$this->routes = $routes;
|
||||
$this->loadCallable = $loadCallable;
|
||||
$this->path = $path;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,38 +20,39 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
use \FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Class routerSetPathEvent
|
||||
* Class routerSetPathEvent.
|
||||
*
|
||||
* Fired when the router's path is changing
|
||||
*
|
||||
* @package net.techfuze.fuzeworks.core.event
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class routerSetPathEvent extends Event{
|
||||
|
||||
class routerSetPathEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The path to be set to the router
|
||||
* The path to be set to the router.
|
||||
*
|
||||
* @var string The new path
|
||||
*/
|
||||
public $path;
|
||||
|
||||
public function init($path){
|
||||
|
||||
public function init($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,22 +20,26 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Abstract class ControllerAbstract
|
||||
* Abstract class ControllerAbstract.
|
||||
*
|
||||
* At this point does nothing, can be extended in the future to allow special controller functions
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
abstract class ControllerAbstract {}
|
||||
abstract class ControllerAbstract
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,42 +20,46 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Class Event
|
||||
* Class Event.
|
||||
*
|
||||
* A simple class for events. The only current purpose is to be able to cancel events, but it can be easily extended.
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Event {
|
||||
|
||||
class Event
|
||||
{
|
||||
private $cancelled = false;
|
||||
|
||||
/**
|
||||
* @return boolean True if the event is cancelled, false if the event is not cancelled
|
||||
* @return bool True if the event is cancelled, false if the event is not cancelled
|
||||
*/
|
||||
public function isCancelled() {
|
||||
public function isCancelled()
|
||||
{
|
||||
return $this->cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $cancelled True if the event is cancelled, false if the event is not cancelled
|
||||
* @param bool $cancelled True if the event is cancelled, false if the event is not cancelled
|
||||
*/
|
||||
public function setCancelled($cancelled) {
|
||||
if ($cancelled == true){
|
||||
public function setCancelled($cancelled)
|
||||
{
|
||||
if ($cancelled == true) {
|
||||
$this->cancelled = true;
|
||||
} else{
|
||||
} else {
|
||||
$this->cancelled = false;
|
||||
}
|
||||
}
|
||||
|
@ -64,11 +68,11 @@ class Event {
|
|||
namespace FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Simple event which will notify components of an event, but does not contain any data
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Simple event which will notify components of an event, but does not contain any data.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class NotifierEvent extends \FuzeWorks\Event {}
|
||||
|
||||
?>
|
||||
class NotifierEvent extends \FuzeWorks\Event
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,18 +20,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Class EventPriority
|
||||
* Class EventPriority.
|
||||
*
|
||||
* The EventPriority is an "enum" which gives priorities an integer value, the higher the integer value, the lower the
|
||||
* priority. The available priorities are, from highest to lowest:
|
||||
|
@ -42,14 +44,12 @@ namespace FuzeWorks;
|
|||
* EventPriority::NORMAL
|
||||
* EventPriority::LOW
|
||||
* EventPriority::LOWEST
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
|
||||
abstract class EventPriority
|
||||
{
|
||||
|
||||
const LOWEST = 5;
|
||||
const LOW = 4;
|
||||
const NORMAL = 3;
|
||||
|
@ -58,26 +58,27 @@ abstract class EventPriority
|
|||
const MONITOR = 0;
|
||||
|
||||
/**
|
||||
* Returns the string of the priority based on the integer
|
||||
* Returns the string of the priority based on the integer.
|
||||
*
|
||||
* @param $intPriorty
|
||||
*
|
||||
* @return bool|string A bool when the integer isn't a priority. If the integer is a priority, the name is returned
|
||||
*/
|
||||
static function getPriority($intPriorty){
|
||||
|
||||
switch($intPriorty){
|
||||
|
||||
public static function getPriority($intPriorty)
|
||||
{
|
||||
switch ($intPriorty) {
|
||||
case 5:
|
||||
return "EventPriority::LOWEST";
|
||||
return 'EventPriority::LOWEST';
|
||||
case 4:
|
||||
return "EventPriority::LOW";
|
||||
return 'EventPriority::LOW';
|
||||
case 3:
|
||||
return "EventPriority::NORMAL";
|
||||
return 'EventPriority::NORMAL';
|
||||
case 2:
|
||||
return "EventPriority::HIGH";
|
||||
return 'EventPriority::HIGH';
|
||||
case 1:
|
||||
return "EventPriority::HIGHEST";
|
||||
return 'EventPriority::HIGHEST';
|
||||
case 0:
|
||||
return "EventPriority::MONITOR";
|
||||
return 'EventPriority::MONITOR';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -85,21 +86,23 @@ abstract class EventPriority
|
|||
|
||||
/**
|
||||
* Returns the highest priority
|
||||
* This function is needed for the firing of events in the right order,
|
||||
* This function is needed for the firing of events in the right order,.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
static function getHighestPriority(){
|
||||
|
||||
return EventPriority::MONITOR;
|
||||
public static function getHighestPriority()
|
||||
{
|
||||
return self::MONITOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the lowest priority
|
||||
* This function is needed for the firing of events in the right order,
|
||||
* This function is needed for the firing of events in the right order,.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
static function getLowestPriority(){
|
||||
|
||||
return EventPriority::LOWEST;
|
||||
public static function getLowestPriority()
|
||||
{
|
||||
return self::LOWEST;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,11 +20,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
|
@ -32,72 +34,79 @@ namespace FuzeWorks;
|
|||
|
||||
/**
|
||||
* Interface for a Module that gives abstract model types
|
||||
* A model server must contain the methods from this interface in order to correctly serve models
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* A model server must contain the methods from this interface in order to correctly serve models.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
interface ModelServer {
|
||||
interface ModelServer
|
||||
{
|
||||
public function giveModel($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract class Model
|
||||
* Abstract class Model.
|
||||
*
|
||||
* Abstract for a model data representation, loads the correct parent type
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
abstract class Model {
|
||||
|
||||
abstract class Model
|
||||
{
|
||||
/**
|
||||
* The parent class holder object
|
||||
* Requests get redirected to this class
|
||||
* @access private
|
||||
* Requests get redirected to this class.
|
||||
*
|
||||
* @var Parent Object
|
||||
*/
|
||||
private $parentClass;
|
||||
|
||||
/**
|
||||
* Set the type of this model. Eg, use techfuze/databasemodel and Databasemodel to get a SQL connected model
|
||||
* @access protected
|
||||
* @param String Module_name, the name of the module where the model can be found
|
||||
* @param String Model_type, model type to return
|
||||
* Set the type of this model. Eg, use techfuze/databasemodel and Databasemodel to get a SQL connected model.
|
||||
*
|
||||
* @param string Module_name, the name of the module where the model can be found
|
||||
* @param string Model_type, model type to return
|
||||
*/
|
||||
protected function setType($module_name, $model_type) {
|
||||
protected function setType($module_name, $model_type)
|
||||
{
|
||||
$mod = Modules::get($module_name);
|
||||
$this->parentClass = $mod->giveModel($model_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value from the model class
|
||||
* @access public
|
||||
* Retrieves a value from the model class.
|
||||
*
|
||||
* @param Any key
|
||||
*
|
||||
* @return Any value from the model class
|
||||
*/
|
||||
public function __get($name) {
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->parentClass->$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value in the model class
|
||||
* @access public
|
||||
* Sets a value in the model class.
|
||||
*
|
||||
* @param Any key
|
||||
* @param Any value
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->parentClass->$name = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a function in the model class
|
||||
* @access public
|
||||
* @param String function_name
|
||||
* @param Array values
|
||||
* Calls a function in the model class.
|
||||
*
|
||||
* @param string function_name
|
||||
* @param array values
|
||||
*
|
||||
* @return Function return
|
||||
*/
|
||||
public function __call($name, $params) {
|
||||
public function __call($name, $params)
|
||||
{
|
||||
return call_user_func_array(array($this->parentClass, $name), $params);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,26 +20,28 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Trait Module
|
||||
* Trait Module.
|
||||
*
|
||||
* Contains all the methods modules should have
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
trait Module {
|
||||
|
||||
trait Module
|
||||
{
|
||||
/**
|
||||
* @var null|string Relative path to the module
|
||||
*/
|
||||
|
@ -51,7 +53,7 @@ trait Module {
|
|||
protected static $moduleName = 'placeholder';
|
||||
|
||||
/**
|
||||
* @var String name used in the mod array
|
||||
* @var string name used in the mod array
|
||||
*/
|
||||
protected static $linkName = 'placeholder';
|
||||
|
||||
|
@ -66,87 +68,96 @@ trait Module {
|
|||
protected static $advertisements = array();
|
||||
|
||||
/**
|
||||
* Returns the name of the module
|
||||
* Returns the name of the module.
|
||||
*
|
||||
* @return string Returns the name of the module
|
||||
*/
|
||||
public static function getModuleName(){
|
||||
|
||||
public static function getModuleName()
|
||||
{
|
||||
return self::$moduleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the module
|
||||
* Returns the path to the module.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public static function getModulePath(){
|
||||
|
||||
public static function getModulePath()
|
||||
{
|
||||
return self::$modulePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the config of the module (moduleInfo.php)
|
||||
* @access public
|
||||
* Returns the config of the module (moduleInfo.php).
|
||||
*
|
||||
* @return stdClass module config
|
||||
*/
|
||||
public static function getModuleConfig() {
|
||||
public static function getModuleConfig()
|
||||
{
|
||||
return self::$cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the path to the location of the module
|
||||
* Changes the path to the location of the module.
|
||||
*
|
||||
* This function can only be executed once, because when the path has been set this function won't save changes anymore.
|
||||
* This prevents modules or other systems to mess with modules and their stability.
|
||||
*
|
||||
* @param string $modulePath
|
||||
*/
|
||||
public static function setModulePath($modulePath = null){
|
||||
public static function setModulePath($modulePath = null)
|
||||
{
|
||||
// Only allow one change of this variable from outside
|
||||
if(self::$modulePath === null)
|
||||
if (self::$modulePath === null) {
|
||||
self::$modulePath = $modulePath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the link name of the module. The link name is the address in the module array so that the module can self reference.
|
||||
* @access public
|
||||
* @param String link name
|
||||
*
|
||||
* @param string link name
|
||||
*/
|
||||
public static function setModuleLinkName($linkName) {
|
||||
public static function setModuleLinkName($linkName)
|
||||
{
|
||||
self::$linkName = $linkName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name that is required to load itself, eg 'exampleauthor/examplemodulename' or 'techfuze/cms'
|
||||
* @access public
|
||||
* @param String module name
|
||||
* The name that is required to load itself, eg 'exampleauthor/examplemodulename' or 'techfuze/cms'.
|
||||
*
|
||||
* @param string module name
|
||||
*/
|
||||
public static function setModuleName($modName) {
|
||||
public static function setModuleName($modName)
|
||||
{
|
||||
self::$moduleName = $modName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the moduleInfo.php to the module for direct interaction
|
||||
* @access public
|
||||
* Add the moduleInfo.php to the module for direct interaction.
|
||||
*
|
||||
* @param stdClass module config
|
||||
*/
|
||||
public static function setModuleConfig($config) {
|
||||
public static function setModuleConfig($config)
|
||||
{
|
||||
self::$cfg = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value in the modules moduleInfo.php
|
||||
* @access protected
|
||||
* @param Mixed config Key
|
||||
* @param Mixed config value
|
||||
* Set a value in the modules moduleInfo.php.
|
||||
*
|
||||
* @param mixed config Key
|
||||
* @param mixed config value
|
||||
*/
|
||||
public static function setConfigValue($key, $value) {
|
||||
$file = self::getModulePath() . "moduleInfo.php";
|
||||
public static function setConfigValue($key, $value)
|
||||
{
|
||||
$file = self::getModulePath().'moduleInfo.php';
|
||||
self::$cfg->$key = $value;
|
||||
|
||||
// Check if the module path is set yet
|
||||
if (self::getModulePath() == null) {
|
||||
Logger::logWarning("Could not write module config. ModulePath is not set", get_class($this));
|
||||
Logger::logWarning('Could not write module config. ModulePath is not set', get_class($this));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -157,29 +168,36 @@ trait Module {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the advertisements send by other modules
|
||||
* Set the advertisements send by other modules.
|
||||
*
|
||||
* @param array $advertisements Advertisement data
|
||||
*/
|
||||
public static function setAdvertisements($advertiseName, $advertiseData) {
|
||||
public static function setAdvertisements($advertiseName, $advertiseData)
|
||||
{
|
||||
self::$advertisements[$advertiseName] = $advertiseData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the advertisements with a specific name
|
||||
* @param String $advertiseName AdvertisementName
|
||||
* Get the advertisements with a specific name.
|
||||
*
|
||||
* @param string $advertiseName AdvertisementName
|
||||
*
|
||||
* @return array AdvertisementData
|
||||
*/
|
||||
public static function getAdvertisements($advertiseName) {
|
||||
public static function getAdvertisements($advertiseName)
|
||||
{
|
||||
return self::$advertisements[$advertiseName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a value from the module configuration
|
||||
* @access public
|
||||
* @param Mixed config Key
|
||||
* @return Mixed config value
|
||||
* Return a value from the module configuration.
|
||||
*
|
||||
* @param mixed config Key
|
||||
*
|
||||
* @return mixed config value
|
||||
*/
|
||||
public static function getConfigValue($key) {
|
||||
public static function getConfigValue($key)
|
||||
{
|
||||
return self::$cfg->$key;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,55 +20,61 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
use \PDOException;
|
||||
use \FuzeWorks\ORM\ConfigFileORM;
|
||||
use \FuzeWorks\ORM\ConfigDatabaseORM;
|
||||
|
||||
use PDOException;
|
||||
use FuzeWorks\ORM\ConfigFileORM;
|
||||
use FuzeWorks\ORM\ConfigDatabaseORM;
|
||||
|
||||
/**
|
||||
* Config Class
|
||||
* Config Class.
|
||||
*
|
||||
* This class gives access to the config files. It allows you to open configurations and edit them.
|
||||
* This class is extensible, but not yet from the outside
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Config {
|
||||
|
||||
class Config
|
||||
{
|
||||
/**
|
||||
* whether or not the database is active at the moment
|
||||
* @access public
|
||||
* @var Boolean true on active database
|
||||
* whether or not the database is active at the moment.
|
||||
*
|
||||
* @var bool true on active database
|
||||
*/
|
||||
public static $dbActive = false;
|
||||
|
||||
/**
|
||||
* All loaded Config files
|
||||
* @var Array of ConfigORM
|
||||
* All loaded Config files.
|
||||
*
|
||||
* @var array of ConfigORM
|
||||
*/
|
||||
private static $cfg = array();
|
||||
|
||||
/**
|
||||
* Loads a config file and returns it as an object
|
||||
* @access public
|
||||
* @param String config file name
|
||||
* @param String directory, default is Application/Config
|
||||
* Loads a config file and returns it as an object.
|
||||
*
|
||||
* @param string config file name
|
||||
* @param string directory, default is Application/Config
|
||||
*
|
||||
* @throws \Exception on file not found
|
||||
*
|
||||
* @return \FuzeWorks\ORM\ConfigORM of config
|
||||
*/
|
||||
public static function loadConfigFile($name, $directory = null) {
|
||||
$dir = (isset($directory) ? $directory : "Application/Config/");
|
||||
$file = $dir . 'config.' . strtolower($name).".php";
|
||||
public static function loadConfigFile($name, $directory = null)
|
||||
{
|
||||
$dir = (isset($directory) ? $directory : 'Application/Config/');
|
||||
$file = $dir.'config.'.strtolower($name).'.php';
|
||||
|
||||
// If already loaded, return a reference to the ORM
|
||||
if (isset(self::$cfg[$name])) {
|
||||
|
@ -86,7 +92,7 @@ class Config {
|
|||
if (self::$dbActive) {
|
||||
// Open your stream
|
||||
$dborm = new ConfigDatabaseORM($module, $name);
|
||||
// Lookup for the success
|
||||
// Lookup for success
|
||||
if ($dborm->success) {
|
||||
// And see
|
||||
return $cfg = self::$cfg[$name] = $dborm;
|
||||
|
@ -102,38 +108,43 @@ class Config {
|
|||
}
|
||||
|
||||
/**
|
||||
* Magic config getter
|
||||
* @access public
|
||||
* @param String config file name
|
||||
* Magic config getter.
|
||||
*
|
||||
* @param string config file name
|
||||
*
|
||||
* @return \FuzeWorks\ORM\ConfigORM of config
|
||||
*/
|
||||
public static function get($name) {
|
||||
public static function get($name)
|
||||
{
|
||||
return self::loadConfigFile($name);
|
||||
}
|
||||
}
|
||||
|
||||
namespace FuzeWorks\ORM;
|
||||
use \Iterator;
|
||||
|
||||
use Iterator;
|
||||
|
||||
/**
|
||||
* Abstract ConfigORM class.
|
||||
*
|
||||
* This class implements the iterator, so a config file can be accessed using foreach.
|
||||
* A file can also be returned using toArray(), so it will be converted to an array
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
abstract class ConfigORM implements Iterator {
|
||||
|
||||
abstract class ConfigORM implements Iterator
|
||||
{
|
||||
/**
|
||||
* The original state of a config file. Can be reverted to using revert()
|
||||
* The original state of a config file. Can be reverted to using revert().
|
||||
*
|
||||
* @var StdObject Config file
|
||||
*/
|
||||
protected $originalCfg;
|
||||
|
||||
/**
|
||||
* The current state of a config file.
|
||||
*
|
||||
* @var StdObject Config file
|
||||
*/
|
||||
protected $cfg;
|
||||
|
@ -141,124 +152,148 @@ abstract class ConfigORM implements Iterator {
|
|||
/**
|
||||
* Revert to the original conditions of the config file.
|
||||
*/
|
||||
public function revert() {
|
||||
public function revert()
|
||||
{
|
||||
$this->cfg = $this->originalCfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a requested key is set in the config file
|
||||
* @param String $name Parameter name
|
||||
* @return boolean true on isset, false on not
|
||||
* Checks if a requested key is set in the config file.
|
||||
*
|
||||
* @param string $name Parameter name
|
||||
*
|
||||
* @return bool true on isset, false on not
|
||||
*/
|
||||
public function __isset($name) {
|
||||
public function __isset($name)
|
||||
{
|
||||
return isset($this->cfg[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a value from a config file
|
||||
* @param String $name Key of the requested entry
|
||||
* @return Mixed Value of the requested entry
|
||||
* Return a value from a config file.
|
||||
*
|
||||
* @param string $name Key of the requested entry
|
||||
*
|
||||
* @return mixed Value of the requested entry
|
||||
*/
|
||||
public function __get($name) {
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->cfg[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an entry in the config file
|
||||
* @param String $name Key of the entry
|
||||
* @param Mixed $value Value of the entry
|
||||
* Sets an entry in the config file.
|
||||
*
|
||||
* @param string $name Key of the entry
|
||||
* @param mixed $value Value of the entry
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->cfg[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset a value in a config file
|
||||
* @param String Key of the entry
|
||||
* Unset a value in a config file.
|
||||
*
|
||||
* @param string Key of the entry
|
||||
*/
|
||||
public function __unset($name) {
|
||||
public function __unset($name)
|
||||
{
|
||||
unset($this->cfg[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator method
|
||||
* Iterator method.
|
||||
*/
|
||||
public function rewind() {
|
||||
public function rewind()
|
||||
{
|
||||
return reset($this->cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator method
|
||||
* Iterator method.
|
||||
*/
|
||||
public function current() {
|
||||
public function current()
|
||||
{
|
||||
return current($this->cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator method
|
||||
* Iterator method.
|
||||
*/
|
||||
public function key() {
|
||||
public function key()
|
||||
{
|
||||
return key($this->cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator method
|
||||
* Iterator method.
|
||||
*/
|
||||
public function next() {
|
||||
public function next()
|
||||
{
|
||||
return next($this->cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator method
|
||||
* Iterator method.
|
||||
*/
|
||||
public function valid() {
|
||||
public function valid()
|
||||
{
|
||||
return key($this->cfg) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the config file as an array
|
||||
* @return Array Config file
|
||||
* Returns the config file as an array.
|
||||
*
|
||||
* @return array Config file
|
||||
*/
|
||||
public function toArray() {
|
||||
public function toArray()
|
||||
{
|
||||
return $this->cfg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ORM class for config files in a database
|
||||
* ORM class for config files in a database.
|
||||
*
|
||||
* Handles entries in the database of FuzeWorks and is able to dynamically update them when requested
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class ConfigDatabaseORM extends ConfigORM {
|
||||
|
||||
class ConfigDatabaseORM extends ConfigORM
|
||||
{
|
||||
/**
|
||||
* The current connection to the database
|
||||
* The current connection to the database.
|
||||
*
|
||||
* @var \FuzeWorks\Database Database Connection
|
||||
*/
|
||||
private $dbh;
|
||||
|
||||
/**
|
||||
* whether the database connection has been successfully established
|
||||
* @var boolean true on success
|
||||
* whether the database connection has been successfully established.
|
||||
*
|
||||
* @var bool true on success
|
||||
*/
|
||||
public $success = false;
|
||||
|
||||
/**
|
||||
* The current filename
|
||||
* @var String filename
|
||||
* The current filename.
|
||||
*
|
||||
* @var string filename
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* Sets up the class and the connection to the database
|
||||
* Sets up the class and the connection to the database.
|
||||
*
|
||||
* @param \FuzeWorks\Database $db The Database connection
|
||||
* @param String $filename The current filename
|
||||
* @param string $filename The current filename
|
||||
*
|
||||
* @throws ConfigException on fatal error
|
||||
*/
|
||||
public function __construct($db, $filename) {
|
||||
public function __construct($db, $filename)
|
||||
{
|
||||
$this->dbh = $db;
|
||||
$this->cfg = $this->openDb($filename);
|
||||
$this->originalCfg = $this->cfg;
|
||||
|
@ -266,39 +301,46 @@ class ConfigDatabaseORM extends ConfigORM {
|
|||
}
|
||||
|
||||
/**
|
||||
* Opens up a database connection with the requested filename
|
||||
* @param String $name Name of the file
|
||||
* @return Array Content of the file
|
||||
* Opens up a database connection with the requested filename.
|
||||
*
|
||||
* @param string $name Name of the file
|
||||
*
|
||||
* @return array Content of the file
|
||||
*
|
||||
* @throws ConfigException on fatal error
|
||||
*/
|
||||
private function openDb($name) {
|
||||
private function openDb($name)
|
||||
{
|
||||
$prefix = $this->dbh->getPrefix();
|
||||
try{
|
||||
$stmnt = $this->dbh->prepare("SELECT * FROM ".$prefix."config WHERE `file` = ?");
|
||||
try {
|
||||
$stmnt = $this->dbh->prepare('SELECT * FROM '.$prefix.'config WHERE `file` = ?');
|
||||
$stmnt->execute(array($name));
|
||||
} catch (PDOException $e){
|
||||
} catch (PDOException $e) {
|
||||
throw new ConfigException('Could not execute SQL-query due PDO-exception '.$e->getMessage());
|
||||
}
|
||||
|
||||
// Fetch results
|
||||
$result = $stmnt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$return = array();
|
||||
for ($i=0; $i < count($result); $i++) {
|
||||
for ($i = 0; $i < count($result); ++$i) {
|
||||
$return[ $result[$i]['key'] ] = $result[$i]['value'];
|
||||
}
|
||||
|
||||
// Return if found in DB
|
||||
if (!empty($return)) {
|
||||
$this->success = true;
|
||||
|
||||
return (array) $return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write config updates to the database
|
||||
* Write config updates to the database.
|
||||
*
|
||||
* @throws ConfigException on fatal error
|
||||
*/
|
||||
private function writeDb() {
|
||||
private function writeDb()
|
||||
{
|
||||
// First arrays of all the fields that need to change
|
||||
$changed_fields = array();
|
||||
$removed_fields = array();
|
||||
|
@ -327,108 +369,117 @@ class ConfigDatabaseORM extends ConfigORM {
|
|||
// First for the removed values
|
||||
$prefix = $this->dbh->getPrefix();
|
||||
try {
|
||||
$stmnt = $this->dbh->prepare("DELETE FROM ".$prefix."config WHERE `file` = :file AND `key` = :key");
|
||||
$stmnt = $this->dbh->prepare('DELETE FROM '.$prefix.'config WHERE `file` = :file AND `key` = :key');
|
||||
foreach ($removed_fields as $key => $value) {
|
||||
$stmnt->execute(array('file' => $this->file, 'key' => $key));
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
throw new ConfigException("Could not change config due to PDOException: " . $e->getMessage(), 1);
|
||||
throw new ConfigException('Could not change config due to PDOException: '.$e->getMessage(), 1);
|
||||
}
|
||||
|
||||
// Then for the changed values
|
||||
try {
|
||||
$stmnt = $this->dbh->prepare("UPDATE ".$prefix."config SET `value` = :value WHERE `file` = :file AND `key` = :key");
|
||||
$stmnt = $this->dbh->prepare('UPDATE '.$prefix.'config SET `value` = :value WHERE `file` = :file AND `key` = :key');
|
||||
foreach ($changed_fields as $key => $value) {
|
||||
$stmnt->execute(array('file' => $this->file, 'key' => $key, 'value' => $value));
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
throw new ConfigException("Could not change config due to PDOException: " . $e->getMessage(), 1);
|
||||
throw new ConfigException('Could not change config due to PDOException: '.$e->getMessage(), 1);
|
||||
}
|
||||
|
||||
// And finally for the new values
|
||||
try {
|
||||
$stmnt = $this->dbh->prepare("INSERT INTO ".$prefix."config (`file`,`key`,`value`) VALUES (:file,:key,:value)");
|
||||
$stmnt = $this->dbh->prepare('INSERT INTO '.$prefix.'config (`file`,`key`,`value`) VALUES (:file,:key,:value)');
|
||||
foreach ($new_fields as $key => $value) {
|
||||
$stmnt->execute(array('file' => $this->file, 'key' => $key, 'value' => $value));
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
throw new ConfigException("Could not change config due to PDOException: " . $e->getMessage(), 1);
|
||||
throw new ConfigException('Could not change config due to PDOException: '.$e->getMessage(), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Write updates of the config file to the database
|
||||
* Write updates of the config file to the database.
|
||||
*
|
||||
* @throws ConfigException on fatal error
|
||||
*/
|
||||
public function commit() {
|
||||
public function commit()
|
||||
{
|
||||
$this->writeDb();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* ORM class for config files in PHP files
|
||||
* ORM class for config files in PHP files.
|
||||
*
|
||||
* Handles entries in the config directory of FuzeWorks and is able to dynamically update them when requested
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class ConfigFileORM extends ConfigORM {
|
||||
|
||||
class ConfigFileORM extends ConfigORM
|
||||
{
|
||||
/**
|
||||
* The current filename
|
||||
* @var String filename
|
||||
* The current filename.
|
||||
*
|
||||
* @var string filename
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* Sets up the class and the connection to the PHP file
|
||||
* @param String $filename The current filename
|
||||
* Sets up the class and the connection to the PHP file.
|
||||
*
|
||||
* @param string $filename The current filename
|
||||
*
|
||||
* @throws ConfigException on fatal error
|
||||
*/
|
||||
public function __construct($file) {
|
||||
public function __construct($file)
|
||||
{
|
||||
if (file_exists($file)) {
|
||||
$this->file = $file;
|
||||
$this->openFile($file);
|
||||
$this->originalCfg = $this->cfg;
|
||||
} else {
|
||||
throw new ConfigException("Could not load config file. Config file does not exist", 1);
|
||||
throw new ConfigException('Could not load config file. Config file does not exist', 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the file and returns the data
|
||||
* @param String $file Name of the config file
|
||||
* @return Array Content of the file
|
||||
* Opens the file and returns the data.
|
||||
*
|
||||
* @param string $file Name of the config file
|
||||
*
|
||||
* @return array Content of the file
|
||||
*/
|
||||
private function openFile($file) {
|
||||
$this->cfg = (array) require($file);
|
||||
private function openFile($file)
|
||||
{
|
||||
$this->cfg = (array) include $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the config file and writes it to the database
|
||||
* Updates the config file and writes it to the database.
|
||||
*
|
||||
* @throws ConfigException on fatal error
|
||||
*/
|
||||
private function writeFile() {
|
||||
private function writeFile()
|
||||
{
|
||||
// Implement writing here
|
||||
if (is_writable($this->file)) {
|
||||
$config = var_export($this->cfg, true);
|
||||
file_put_contents($this->file, "<?php return $config ;");
|
||||
|
||||
return true;
|
||||
}
|
||||
throw new ConfigException("Could not write config file. $file is not writable", 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the config file and writes it
|
||||
* Updates the config file and writes it.
|
||||
*
|
||||
* @throws ConfigException on fatal error
|
||||
*/
|
||||
public function commit() {
|
||||
public function commit()
|
||||
{
|
||||
$this->writeFile();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,33 +20,34 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
use \stdClass;
|
||||
|
||||
/**
|
||||
* FuzeWorks Core
|
||||
* FuzeWorks Core.
|
||||
*
|
||||
* Holds all the modules and starts the framework. Allows for starting and managing modules
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Core {
|
||||
|
||||
class Core
|
||||
{
|
||||
/**
|
||||
* The current version of the framework
|
||||
* @access public
|
||||
* @var String Framework version
|
||||
* The current version of the framework.
|
||||
*
|
||||
* @var string Framework version
|
||||
*/
|
||||
public static $version = "0.0.1";
|
||||
public static $version = '0.0.1';
|
||||
|
||||
/**
|
||||
* @var bool Whether the files has been loaded
|
||||
|
@ -54,19 +55,21 @@ class Core {
|
|||
private static $loaded = false;
|
||||
|
||||
/**
|
||||
* Working directory of the Framework
|
||||
* Working directory of the Framework.
|
||||
*
|
||||
* This is required to make the shutdown function working under Apache webservers
|
||||
* @var String $cwd
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $cwd;
|
||||
|
||||
/**
|
||||
* Initializes the core
|
||||
* Initializes the core.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function init() {
|
||||
public static function init()
|
||||
{
|
||||
// Defines the time the framework starts. Used for timing functions in the framework
|
||||
if (!defined('STARTTIME')) {
|
||||
define('STARTTIME', microtime(true));
|
||||
|
@ -74,7 +77,7 @@ class Core {
|
|||
|
||||
// Load basics
|
||||
ignore_user_abort(true);
|
||||
register_shutdown_function(array('\FuzeWorks\Core', "shutdown"));
|
||||
register_shutdown_function(array('\FuzeWorks\Core', 'shutdown'));
|
||||
|
||||
// Load core functionality
|
||||
self::loadStartupFiles();
|
||||
|
@ -110,26 +113,28 @@ class Core {
|
|||
/**
|
||||
* Load all the files of the FuzeWorks Framework.
|
||||
*/
|
||||
private static function loadStartupFiles() {
|
||||
if (self::$loaded)
|
||||
private static function loadStartupFiles()
|
||||
{
|
||||
if (self::$loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load core abstracts
|
||||
require_once("Core/System/class.exceptions.php");
|
||||
require_once("Core/System/class.abstract.event.php");
|
||||
include_once 'Core/System/class.exceptions.php';
|
||||
include_once 'Core/System/class.abstract.event.php';
|
||||
|
||||
// Load the core classes
|
||||
require_once("Core/System/class.config.php");
|
||||
require_once("Core/System/class.abstract.eventPriority.php");
|
||||
require_once("Core/System/class.events.php");
|
||||
require_once("Core/System/class.logger.php");
|
||||
require_once("Core/System/class.abstract.model.php");
|
||||
require_once("Core/System/class.models.php");
|
||||
require_once("Core/System/class.layout.php");
|
||||
require_once("Core/System/class.abstract.controllerabstract.php");
|
||||
require_once("Core/System/class.router.php");
|
||||
require_once("Core/System/class.abstract.module.php");
|
||||
require_once("Core/System/class.modules.php");
|
||||
include_once 'Core/System/class.config.php';
|
||||
include_once 'Core/System/class.abstract.eventPriority.php';
|
||||
include_once 'Core/System/class.events.php';
|
||||
include_once 'Core/System/class.logger.php';
|
||||
include_once 'Core/System/class.abstract.model.php';
|
||||
include_once 'Core/System/class.models.php';
|
||||
include_once 'Core/System/class.layout.php';
|
||||
include_once 'Core/System/class.abstract.controllerabstract.php';
|
||||
include_once 'Core/System/class.router.php';
|
||||
include_once 'Core/System/class.abstract.module.php';
|
||||
include_once 'Core/System/class.modules.php';
|
||||
|
||||
// Create the module holder
|
||||
new Config();
|
||||
|
@ -147,10 +152,9 @@ class Core {
|
|||
* Stop FuzeWorks and run all shutdown functions.
|
||||
*
|
||||
* Afterwards run the Logger shutdown function in order to possibly display the log
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public static function shutdown() {
|
||||
public static function shutdown()
|
||||
{
|
||||
// Fix Apache bug where CWD is changed upon shutdown
|
||||
chdir(self::$cwd);
|
||||
|
||||
|
@ -162,23 +166,22 @@ class Core {
|
|||
}
|
||||
|
||||
/**
|
||||
* Load composer if it is present
|
||||
* @access private
|
||||
* @param String directory of composer autoload file (optional)
|
||||
* @return boolean true on success, false on failure
|
||||
* Load composer if it is present.
|
||||
*
|
||||
* @param string directory of composer autoload file (optional)
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
private static function loadComposer($file = "vendor/autoload.php") {
|
||||
private static function loadComposer($file = 'vendor/autoload.php')
|
||||
{
|
||||
if (file_exists($file)) {
|
||||
require($file);
|
||||
include $file;
|
||||
Logger::log('Loaded Composer');
|
||||
|
||||
return true;
|
||||
}
|
||||
Logger::log('Failed to load Composer. File \''.$file.'\' not found');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,18 +20,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Class Events
|
||||
* Class Events.
|
||||
*
|
||||
* FuzeWorks is built in a way that almost every core-event can be manipulated by modules. This class provides various ways to hook into the core (or other modules)
|
||||
* and manipulate the outcome of the functions. Modules and core actions can 'fire' an event and modules can 'hook' into that event. Let's take a look at the example below:
|
||||
|
@ -48,109 +50,124 @@ namespace FuzeWorks;
|
|||
*
|
||||
* $event->title = date('H:i:s ').$event->title;
|
||||
*
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Events {
|
||||
|
||||
class Events
|
||||
{
|
||||
/**
|
||||
* Array of classes that can handle events
|
||||
* Array of classes that can handle events.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $listeners = array();
|
||||
|
||||
/**
|
||||
* Whether the event system is enabled or not
|
||||
* Whether the event system is enabled or not.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $enabled = true;
|
||||
|
||||
/**
|
||||
* A register with all the events and associated modules which should be loaded upon eventFire
|
||||
* A register with all the events and associated modules which should be loaded upon eventFire.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $register;
|
||||
|
||||
/**
|
||||
* Adds a function as listener
|
||||
* Adds a function as listener.
|
||||
*
|
||||
* @param mixed callback The callback when the events get fired, see {@link http://php.net/manual/en/language.types.callable.php PHP.net}
|
||||
* @param String $eventName The name of the event
|
||||
* @param string $eventName The name of the event
|
||||
* @param int $priority The priority, even though integers are valid, please use EventPriority (for example EventPriority::Lowest)
|
||||
*
|
||||
* @see EventPriority
|
||||
*
|
||||
* @throws EventException
|
||||
*/
|
||||
public static function addListener($callback, $eventName, $priority = EventPriority::NORMAL){
|
||||
if(EventPriority::getPriority($priority) == false)
|
||||
throw new Exception("Unknown priority " . $priority);
|
||||
public static function addListener($callback, $eventName, $priority = EventPriority::NORMAL)
|
||||
{
|
||||
if (EventPriority::getPriority($priority) == false) {
|
||||
throw new Exception('Unknown priority '.$priority);
|
||||
}
|
||||
|
||||
if(!isset(self::$listeners[$eventName]))
|
||||
if (!isset(self::$listeners[$eventName])) {
|
||||
self::$listeners[$eventName] = array();
|
||||
}
|
||||
|
||||
if(!isset(self::$listeners[$eventName][$priority]))
|
||||
if (!isset(self::$listeners[$eventName][$priority])) {
|
||||
self::$listeners[$eventName][$priority] = array();
|
||||
}
|
||||
|
||||
self::$listeners[$eventName][$priority][] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a function as listener
|
||||
* Removes a function as listener.
|
||||
*
|
||||
* @param mixed callback The callback when the events get fired, see {@link http://php.net/manual/en/language.types.callable.php PHP.net}
|
||||
* @param String $eventName The name of the event
|
||||
* @param string $eventName The name of the event
|
||||
* @param int $priority The priority, even though integers are valid, please use EventPriority (for example EventPriority::Lowest)
|
||||
*
|
||||
* @see EventPriority
|
||||
*
|
||||
* @throws EventException
|
||||
*/
|
||||
public static function removeListener($callback, $eventName, $priority = EventPriority::NORMAL){
|
||||
if(EventPriority::getPriority($priority) == false)
|
||||
throw new Exception("Unknown priority " . $priority);
|
||||
public static function removeListener($callback, $eventName, $priority = EventPriority::NORMAL)
|
||||
{
|
||||
if (EventPriority::getPriority($priority) == false) {
|
||||
throw new Exception('Unknown priority '.$priority);
|
||||
}
|
||||
|
||||
if(!isset(self::$listeners[$eventName]))
|
||||
if (!isset(self::$listeners[$eventName])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!isset(self::$listeners[$eventName][$priority]))
|
||||
if (!isset(self::$listeners[$eventName][$priority])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(self::$listeners[$eventName][$priority] as $i => $_callback){
|
||||
|
||||
if($_callback == $callback) {
|
||||
foreach (self::$listeners[$eventName][$priority] as $i => $_callback) {
|
||||
if ($_callback == $callback) {
|
||||
unset(self::$listeners[$eventName][$priority][$i]);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires an Event
|
||||
* Fires an Event.
|
||||
*
|
||||
* The Event gets created, passed around and then returned to the issuer.
|
||||
* @param Mixed $input Object for direct event, string for system event or notifierEvent
|
||||
*
|
||||
* @param mixed $input Object for direct event, string for system event or notifierEvent
|
||||
*
|
||||
* @return \FuzeWorks\Event The Event
|
||||
*/
|
||||
public static function fireEvent($input) {
|
||||
public static function fireEvent($input)
|
||||
{
|
||||
if (is_string($input)) {
|
||||
// If the input is a string
|
||||
$eventClass = $input;
|
||||
$eventName = $input;
|
||||
if(!class_exists($eventClass)){
|
||||
if (!class_exists($eventClass)) {
|
||||
// Check if the file even exists
|
||||
$file = "Core/Events/event.".$eventName.".php";
|
||||
if(file_exists($file)){
|
||||
$file = 'Core/Events/event.'.$eventName.'.php';
|
||||
if (file_exists($file)) {
|
||||
// Load the file
|
||||
$eventClass = "\FuzeWorks\Event\\" . $eventClass;
|
||||
require_once($file);
|
||||
}else{
|
||||
$eventClass = "\FuzeWorks\Event\\".$eventClass;
|
||||
include_once $file;
|
||||
} else {
|
||||
// No event arguments? Looks like a notify-event
|
||||
if(func_num_args() == 1){
|
||||
if (func_num_args() == 1) {
|
||||
// Load notify-event-class
|
||||
$eventClass = '\FuzeWorks\Event\NotifierEvent';
|
||||
}else{
|
||||
} else {
|
||||
// No notify-event: we tried all we could
|
||||
throw new Exception("Event ".$eventName." could not be found!");
|
||||
throw new Exception('Event '.$eventName.' could not be found!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,42 +186,45 @@ class Events {
|
|||
Logger::newLevel("Firing Event: '".$eventName."'");
|
||||
Logger::log('Initializing Event');
|
||||
|
||||
if (func_num_args() > 1)
|
||||
if (func_num_args() > 1) {
|
||||
call_user_func_array(array($event, 'init'), array_slice(func_get_args(), 1));
|
||||
}
|
||||
|
||||
// Do not run if the event system is disabled
|
||||
if (!self::$enabled) {
|
||||
Logger::log("Event system is disabled");
|
||||
Logger::log('Event system is disabled');
|
||||
Logger::stopLevel();
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
Logger::log("Checking for Listeners");
|
||||
Logger::log('Checking for Listeners');
|
||||
|
||||
// Read the event register for listeners
|
||||
$register = self::$register;
|
||||
if (isset($register[$eventName])) {
|
||||
for ($i=0; $i < count($register[$eventName]); $i++) {
|
||||
for ($i = 0; $i < count($register[$eventName]); ++$i) {
|
||||
Modules::get($register[$eventName][$i]);
|
||||
}
|
||||
}
|
||||
|
||||
//There are listeners for this event
|
||||
if(isset(self::$listeners[$eventName])) {
|
||||
if (isset(self::$listeners[$eventName])) {
|
||||
//Loop from the highest priority to the lowest
|
||||
for ($priority = EventPriority::getHighestPriority(); $priority <= EventPriority::getLowestPriority(); $priority++) {
|
||||
for ($priority = EventPriority::getHighestPriority(); $priority <= EventPriority::getLowestPriority(); ++$priority) {
|
||||
//Check for listeners in this priority
|
||||
if (isset(self::$listeners[$eventName][$priority])) {
|
||||
$listeners = self::$listeners[$eventName][$priority];
|
||||
Logger::newLevel('Found listeners with priority ' . EventPriority::getPriority($priority));
|
||||
Logger::newLevel('Found listeners with priority '.EventPriority::getPriority($priority));
|
||||
//Fire the event to each listener
|
||||
foreach ($listeners as $callback) {
|
||||
if (is_callable($callback)) {
|
||||
Logger::newLevel('Firing function');
|
||||
} elseif(!is_string($callback[0]))
|
||||
Logger::newLevel('Firing ' . get_class($callback[0]) . '->' . $callback[1]);
|
||||
else
|
||||
Logger::newLevel('Firing ' . join('->', $callback));
|
||||
} elseif (!is_string($callback[0])) {
|
||||
Logger::newLevel('Firing '.get_class($callback[0]).'->'.$callback[1]);
|
||||
} else {
|
||||
Logger::newLevel('Firing '.implode('->', $callback));
|
||||
}
|
||||
try {
|
||||
call_user_func($callback, $event);
|
||||
} catch (ModuleException $e) {
|
||||
|
@ -219,25 +239,25 @@ class Events {
|
|||
}
|
||||
|
||||
Logger::stopLevel();
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the event system
|
||||
* Enables the event system.
|
||||
*/
|
||||
public static function enable() {
|
||||
Logger::log("Enabled the Event system");
|
||||
public static function enable()
|
||||
{
|
||||
Logger::log('Enabled the Event system');
|
||||
self::$enabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the event system
|
||||
* Disables the event system.
|
||||
*/
|
||||
public static function disable() {
|
||||
Logger::log("Disabled the Event system");
|
||||
public static function disable()
|
||||
{
|
||||
Logger::log('Disabled the Event system');
|
||||
self::$enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,92 +20,114 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Class Exception
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Class Exception.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Exception extends \Exception{}
|
||||
class Exception extends \Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Class LayoutException
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Class LayoutException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class LayoutException extends Exception{}
|
||||
class LayoutException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Class ConfigException
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Class ConfigException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class ConfigException extends Exception{}
|
||||
class ConfigException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Class ModelException
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Class ModelException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class ModelException extends Exception{}
|
||||
class ModelException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Class LoggerException
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Class LoggerException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class LoggerException extends Exception{}
|
||||
class LoggerException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Class RouterException
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Class RouterException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class RouterException extends Exception{}
|
||||
class RouterException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Class CoreException
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Class CoreException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class CoreException extends Exception{}
|
||||
class CoreException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Class EventException
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Class EventException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class EventException extends Exception{}
|
||||
class EventException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Class DatabaseException
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Class DatabaseException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class DatabaseException extends Exception{}
|
||||
class DatabaseException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Class ModuleException
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Class ModuleException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class ModuleException extends Exception{}
|
||||
class ModuleException extends Exception
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,67 +20,77 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
use \FuzeWorks\TemplateEngine\JSONEngine;
|
||||
use \FuzeWorks\TemplateEngine\PHPEngine;
|
||||
use \FuzeWorks\TemplateEngine\SmartyEngine;
|
||||
use \FuzeWorks\TemplateEngine\TemplateEngine;
|
||||
|
||||
use FuzeWorks\TemplateEngine\JSONEngine;
|
||||
use FuzeWorks\TemplateEngine\PHPEngine;
|
||||
use FuzeWorks\TemplateEngine\SmartyEngine;
|
||||
use FuzeWorks\TemplateEngine\TemplateEngine;
|
||||
|
||||
/**
|
||||
* Layout and Template Manager for FuzeWorks.
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Layout {
|
||||
|
||||
class Layout
|
||||
{
|
||||
/**
|
||||
* The file to be loaded by the layout manager
|
||||
* The file to be loaded by the layout manager.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public static $file = null;
|
||||
|
||||
/**
|
||||
* The directory of the file to be loaded by the layout manager
|
||||
* The directory of the file to be loaded by the layout manager.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $directory = 'Application/Views';
|
||||
|
||||
/**
|
||||
* All assigned currently assigned to the template
|
||||
* @var Array Associative Assigned Variable Array
|
||||
* All assigned currently assigned to the template.
|
||||
*
|
||||
* @var array Associative Assigned Variable Array
|
||||
*/
|
||||
private static $assigned_variables = array();
|
||||
|
||||
/**
|
||||
* All engines that can be used for templates
|
||||
* All engines that can be used for templates.
|
||||
*
|
||||
* @var array of engines
|
||||
*/
|
||||
private static $engines = array();
|
||||
|
||||
/**
|
||||
* All file extensions that can be used and are bound to a template engine
|
||||
* All file extensions that can be used and are bound to a template engine.
|
||||
*
|
||||
* @var array of names of engines
|
||||
*/
|
||||
private static $file_extensions = array();
|
||||
|
||||
/**
|
||||
* whether the template engines are already called.
|
||||
* @var boolean True if loaded
|
||||
*
|
||||
* @var bool True if loaded
|
||||
*/
|
||||
private static $engines_loaded = false;
|
||||
|
||||
/**
|
||||
* The currently selected template engine
|
||||
* @var String name of engine
|
||||
* The currently selected template engine.
|
||||
*
|
||||
* @var string name of engine
|
||||
*/
|
||||
private static $current_engine;
|
||||
|
||||
|
@ -91,18 +101,20 @@ class Layout {
|
|||
* PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php file.
|
||||
* You can also provide no particular engine, and the manager will decide what template to load.
|
||||
* Remember that doing so will result in a LayoutException when multiple compatible files are found.
|
||||
* @param String $file File to load
|
||||
*
|
||||
* @param string $file File to load
|
||||
* @param string $directory Directory to load it from
|
||||
* @return void
|
||||
*
|
||||
* @throws LayoutException On error
|
||||
*/
|
||||
public static function view($file, $directory = null) {
|
||||
public static function view($file, $directory = null)
|
||||
{
|
||||
$directory = (is_null($directory) ? self::$directory : $directory);
|
||||
echo self::get($file, $directory);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a template file using a string and a directory.
|
||||
*
|
||||
|
@ -110,12 +122,16 @@ class Layout {
|
|||
* PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php file.
|
||||
* You can also provide no particular engine, and the manager will decide what template to load.
|
||||
* Remember that doing so will result in a LayoutException when multiple compatible files are found.
|
||||
* @param String $file File to load
|
||||
*
|
||||
* @param string $file File to load
|
||||
* @param string $directory Directory to load it from
|
||||
* @return String The output of the template
|
||||
*
|
||||
* @return string The output of the template
|
||||
*
|
||||
* @throws LayoutException On error
|
||||
*/
|
||||
public static function get($file, $directory = null) {
|
||||
public static function get($file, $directory = null)
|
||||
{
|
||||
$directory = (is_null($directory) ? self::$directory : $directory);
|
||||
Logger::newLevel("Loading template file '".$file."' in '".$directory."'");
|
||||
|
||||
|
@ -130,7 +146,7 @@ class Layout {
|
|||
}
|
||||
|
||||
// Then assign some basic variables for the template
|
||||
self::$assigned_variables['viewDir'] = Config::get('main')->SITE_URL . preg_replace('#/+#','/', substr(self::$directory . "/", -strlen(self::$directory . "/") ) );
|
||||
self::$assigned_variables['viewDir'] = Config::get('main')->SITE_URL.preg_replace('#/+#', '/', substr(self::$directory.'/', -strlen(self::$directory.'/')));
|
||||
self::$assigned_variables['siteURL'] = Config::get('main')->SITE_URL;
|
||||
self::$assigned_variables['siteLogo'] = Config::get('main')->SITE_LOGO_URL;
|
||||
self::$assigned_variables['serverName'] = Config::get('main')->SERVER_NAME;
|
||||
|
@ -140,7 +156,7 @@ class Layout {
|
|||
|
||||
// Select an engine if one is not already selected
|
||||
if (is_null(self::$current_engine)) {
|
||||
self::$current_engine = self::getEngineFromExtension( self::getExtensionFromFile(self::$file) );
|
||||
self::$current_engine = self::getEngineFromExtension(self::getExtensionFromFile(self::$file));
|
||||
}
|
||||
|
||||
self::$current_engine->setDirectory(self::$directory);
|
||||
|
@ -149,8 +165,7 @@ class Layout {
|
|||
$event = Events::fireEvent('layoutLoadViewEvent', self::$file, self::$directory, self::$current_engine, self::$assigned_variables);
|
||||
|
||||
// The event has been cancelled
|
||||
if($event->isCancelled()){
|
||||
|
||||
if ($event->isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -161,31 +176,38 @@ class Layout {
|
|||
Logger::stopLevel();
|
||||
|
||||
// And finally run it
|
||||
if (file_exists($event->file))
|
||||
if (file_exists($event->file)) {
|
||||
return self::$current_engine->get($event->file, self::$assigned_variables);
|
||||
}
|
||||
|
||||
throw new LayoutException("The requested file was not found", 1);
|
||||
throw new LayoutException('The requested file was not found', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a Template Engine from a File Extension
|
||||
* @param String $extension File extention to look for
|
||||
* @return Object Template Engine
|
||||
* Retrieve a Template Engine from a File Extension.
|
||||
*
|
||||
* @param string $extension File extention to look for
|
||||
*
|
||||
* @return object Template Engine
|
||||
*/
|
||||
public static function getEngineFromExtension($extension) {
|
||||
public static function getEngineFromExtension($extension)
|
||||
{
|
||||
if (isset(self::$file_extensions[strtolower($extension)])) {
|
||||
return self::$engines[ self::$file_extensions[strtolower($extension)]];
|
||||
}
|
||||
|
||||
throw new LayoutException("Could not get Template Engine. No engine has corresponding file extension", 1);
|
||||
throw new LayoutException('Could not get Template Engine. No engine has corresponding file extension', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the extension from a file string
|
||||
* @param String $fileString The path to the file
|
||||
* @return String Extension of the file
|
||||
* Retrieve the extension from a file string.
|
||||
*
|
||||
* @param string $fileString The path to the file
|
||||
*
|
||||
* @return string Extension of the file
|
||||
*/
|
||||
public static function getExtensionFromFile($fileString) {
|
||||
public static function getExtensionFromFile($fileString)
|
||||
{
|
||||
return substr($fileString, strrpos($fileString, '.') + 1);
|
||||
}
|
||||
|
||||
|
@ -193,17 +215,21 @@ class Layout {
|
|||
* Converts a view string to a file using the directory and the used extensions.
|
||||
*
|
||||
* It will detect whether the file exists and choose a file according to the provided extensions
|
||||
* @param String $string The string used by a controller. eg: 'dashboard/home'
|
||||
* @param String $directory The directory to search in for the template
|
||||
*
|
||||
* @param string $string The string used by a controller. eg: 'dashboard/home'
|
||||
* @param string $directory The directory to search in for the template
|
||||
* @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc.
|
||||
* @return String Filepath of the template
|
||||
*
|
||||
* @return string Filepath of the template
|
||||
*
|
||||
* @throws LayoutException On error
|
||||
*/
|
||||
public static function getFileFromString($string, $directory, $extensions = array()) {
|
||||
$directory = preg_replace('#/+#','/',(!is_null($directory) ? $directory : self::$directory) . "/");
|
||||
public static function getFileFromString($string, $directory, $extensions = array())
|
||||
{
|
||||
$directory = preg_replace('#/+#', '/', (!is_null($directory) ? $directory : self::$directory).'/');
|
||||
|
||||
if (!file_exists($directory)) {
|
||||
throw new LayoutException("Could not get file. Directory does not exist", 1);
|
||||
throw new LayoutException('Could not get file. Directory does not exist', 1);
|
||||
}
|
||||
|
||||
// Set the file name and location
|
||||
|
@ -230,20 +256,20 @@ class Layout {
|
|||
$fileSelected = false;
|
||||
$selectedFile = null;
|
||||
foreach ($extensions as $extension) {
|
||||
$file = $directory . $viewSelector .".". strtolower($extension);
|
||||
$file = preg_replace('#/+#','/',$file);
|
||||
$file = $directory.$viewSelector.'.'.strtolower($extension);
|
||||
$file = preg_replace('#/+#', '/', $file);
|
||||
if (file_exists($file) && !$fileSelected) {
|
||||
$selectedFile = $file;
|
||||
$fileSelected = true;
|
||||
Logger::log("Found matching file: '". $file . "'");
|
||||
Logger::log("Found matching file: '".$file."'");
|
||||
} elseif (file_exists($file) && $fileSelected) {
|
||||
throw new LayoutException("Could not select template. Multiple valid extensions detected. Can not choose.", 1);
|
||||
throw new LayoutException('Could not select template. Multiple valid extensions detected. Can not choose.', 1);
|
||||
}
|
||||
}
|
||||
|
||||
// And choose what to output
|
||||
if (!$fileSelected) {
|
||||
throw new LayoutException("Could not select template. No matching file found.");
|
||||
throw new LayoutException('Could not select template. No matching file found.');
|
||||
}
|
||||
|
||||
return $selectedFile;
|
||||
|
@ -254,112 +280,142 @@ class Layout {
|
|||
* It also sets the file variable of this class.
|
||||
*
|
||||
* It will detect whether the file exists and choose a file according to the provided extensions
|
||||
* @param String $string The string used by a controller. eg: 'dashboard/home'
|
||||
* @param String $directory The directory to search in for the template
|
||||
*
|
||||
* @param string $string The string used by a controller. eg: 'dashboard/home'
|
||||
* @param string $directory The directory to search in for the template
|
||||
* @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc.
|
||||
* @return String Filepath of the template
|
||||
*
|
||||
* @return string Filepath of the template
|
||||
*
|
||||
* @throws LayoutException On error
|
||||
*/
|
||||
public static function setFileFromString($string, $directory, $extensions = array()) {
|
||||
public static function setFileFromString($string, $directory, $extensions = array())
|
||||
{
|
||||
self::$file = self::getFileFromString($string, $directory, $extensions);
|
||||
self::$directory = preg_replace('#/+#','/',(!is_null($directory) ? $directory : self::$directory) . "/");
|
||||
self::$directory = preg_replace('#/+#', '/', (!is_null($directory) ? $directory : self::$directory).'/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current file to be loaded
|
||||
* Get the current file to be loaded.
|
||||
*
|
||||
* @return null|string Path to the file
|
||||
*/
|
||||
public static function getFile() {
|
||||
public static function getFile()
|
||||
{
|
||||
return self::$file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the file to be loaded
|
||||
* Set the file to be loaded.
|
||||
*
|
||||
* @param string $file Path to the file
|
||||
*/
|
||||
public static function setFile($file) {
|
||||
public static function setFile($file)
|
||||
{
|
||||
self::$file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the directory of the file to be loaded
|
||||
* Get the directory of the file to be loaded.
|
||||
*
|
||||
* @return null|string Path to the directory
|
||||
*/
|
||||
public static function getDirectory() {
|
||||
public static function getDirectory()
|
||||
{
|
||||
return self::$directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directory of the file to be loaded
|
||||
* Set the directory of the file to be loaded.
|
||||
*
|
||||
* @param string $directory Path to the directory
|
||||
*/
|
||||
public static function setDirectory($directory) {
|
||||
public static function setDirectory($directory)
|
||||
{
|
||||
self::$directory = $directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a variable for the template
|
||||
* @param String $key Key of the variable
|
||||
* @param Mixed $value Value of the variable
|
||||
* Assign a variable for the template.
|
||||
*
|
||||
* @param string $key Key of the variable
|
||||
* @param mixed $value Value of the variable
|
||||
*/
|
||||
public static function assign($key, $value) {
|
||||
public static function assign($key, $value)
|
||||
{
|
||||
self::$assigned_variables[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title of the template
|
||||
* @param String $title title of the template
|
||||
* Set the title of the template.
|
||||
*
|
||||
* @param string $title title of the template
|
||||
*/
|
||||
public static function setTitle($title) {
|
||||
public static function setTitle($title)
|
||||
{
|
||||
self::$assigned_variables['title'] = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the template
|
||||
* @return String title of the template
|
||||
* Get the title of the template.
|
||||
*
|
||||
* @return string title of the template
|
||||
*/
|
||||
public static function getTitle() {
|
||||
public static function getTitle()
|
||||
{
|
||||
return self::$assigned_variables['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the engine for the next layout
|
||||
* @param String $name Name of the template engine
|
||||
* @return boolean true on success
|
||||
* Set the engine for the next layout.
|
||||
*
|
||||
* @param string $name Name of the template engine
|
||||
*
|
||||
* @return bool true on success
|
||||
*
|
||||
* @throws \FuzeWorks\LayoutException on error
|
||||
*/
|
||||
public static function setEngine($name) {
|
||||
public static function setEngine($name)
|
||||
{
|
||||
self::loadTemplateEngines();
|
||||
if (isset(self::$engines[$name])) {
|
||||
self::$current_engine = self::$engines[$name];
|
||||
Logger::log('Set the Template Engine to ' . $name);
|
||||
Logger::log('Set the Template Engine to '.$name);
|
||||
|
||||
return true;
|
||||
}
|
||||
throw new LayoutException("Could not set engine. Engine does not exist", 1);
|
||||
throw new LayoutException('Could not set engine. Engine does not exist', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a loaded template engine
|
||||
* @param String $name Name of the template engine
|
||||
* @return Object Object that implements \FuzeWorks\TemplateEngine
|
||||
* Get a loaded template engine.
|
||||
*
|
||||
* @param string $name Name of the template engine
|
||||
*
|
||||
* @return object Object that implements \FuzeWorks\TemplateEngine
|
||||
*/
|
||||
public static function getEngine($name) {
|
||||
public static function getEngine($name)
|
||||
{
|
||||
self::loadTemplateEngines();
|
||||
if (isset(self::$engines[$name])) {
|
||||
return self::$engines[$name];
|
||||
}
|
||||
throw new LayoutException("Could not return engine. Engine does not exist", 1);
|
||||
throw new LayoutException('Could not return engine. Engine does not exist', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new template engine
|
||||
* @param Object $engineClass Object that implements the \FuzeWorks\TemplateEngine
|
||||
* @param String $engineName Name of the template engine
|
||||
* @param Array $engineFileExtensions File extensions this template engine should be used for
|
||||
* @return boolean true on success
|
||||
* Register a new template engine.
|
||||
*
|
||||
* @param object $engineClass Object that implements the \FuzeWorks\TemplateEngine
|
||||
* @param string $engineName Name of the template engine
|
||||
* @param array $engineFileExtensions File extensions this template engine should be used for
|
||||
*
|
||||
* @return bool true on success
|
||||
*
|
||||
* @throws \FuzeWorks\LayoutException On error
|
||||
*/
|
||||
public static function registerEngine($engineClass, $engineName, $engineFileExtensions = array()) {
|
||||
public static function registerEngine($engineClass, $engineName, $engineFileExtensions = array())
|
||||
{
|
||||
// First check if the engine already exists
|
||||
if (isset(self::$engines[$engineName])) {
|
||||
throw new LayoutException("Could not register engine. Engine '".$engineName."' already registered", 1);
|
||||
|
@ -372,13 +428,13 @@ class Layout {
|
|||
|
||||
// Then define for what file extensions this Template Engine will work
|
||||
if (!is_array($engineFileExtensions)) {
|
||||
throw new LayoutException("Could not register engine. File extensions must be an array", 1);
|
||||
throw new LayoutException('Could not register engine. File extensions must be an array', 1);
|
||||
}
|
||||
|
||||
// Then install them
|
||||
foreach ($engineFileExtensions as $extension) {
|
||||
if (isset(self::$file_extensions[strtolower($extension)])) {
|
||||
throw new LayoutException("Could not register engine. File extension already bound to engine", 1);
|
||||
throw new LayoutException('Could not register engine. File extension already bound to engine', 1);
|
||||
}
|
||||
|
||||
// And add it
|
||||
|
@ -386,7 +442,8 @@ class Layout {
|
|||
}
|
||||
|
||||
// And log it
|
||||
Logger::log('Registered Template Engine: ' . $engineName);
|
||||
Logger::log('Registered Template Engine: '.$engineName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -394,9 +451,10 @@ class Layout {
|
|||
}
|
||||
|
||||
/**
|
||||
* Load the template engines by sending a layoutLoadEngineEvent
|
||||
* Load the template engines by sending a layoutLoadEngineEvent.
|
||||
*/
|
||||
public static function loadTemplateEngines() {
|
||||
public static function loadTemplateEngines()
|
||||
{
|
||||
if (!self::$engines_loaded) {
|
||||
Events::fireEvent('layoutLoadEngineEvent');
|
||||
|
||||
|
@ -409,12 +467,15 @@ class Layout {
|
|||
}
|
||||
|
||||
/**
|
||||
* Calls a function in the current Template engine
|
||||
* @param String $name Name of the function to be called
|
||||
* Calls a function in the current Template engine.
|
||||
*
|
||||
* @param string $name Name of the function to be called
|
||||
* @param Paramaters $params Parameters to be used
|
||||
* @return Mixed Function output
|
||||
*
|
||||
* @return mixed Function output
|
||||
*/
|
||||
public static function __callStatic($name, $params) {
|
||||
public static function __callStatic($name, $params)
|
||||
{
|
||||
// First load the template engines
|
||||
self::loadTemplateEngines();
|
||||
|
||||
|
@ -422,50 +483,57 @@ class Layout {
|
|||
// Call user func array here
|
||||
return call_user_func_array(array(self::$current_engine, $name), $params);
|
||||
}
|
||||
throw new LayoutException("Could not access Engine. Engine not loaded", 1);
|
||||
throw new LayoutException('Could not access Engine. Engine not loaded', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the layout manager to its default state
|
||||
* Resets the layout manager to its default state.
|
||||
*/
|
||||
public static function reset() {
|
||||
public static function reset()
|
||||
{
|
||||
if (!is_null(self::$current_engine)) {
|
||||
self::$current_engine->reset();
|
||||
}
|
||||
self::$current_engine = null;
|
||||
self::$assigned_variables = array();
|
||||
Logger::log("Reset the layout manager to its default state");
|
||||
Logger::log('Reset the layout manager to its default state');
|
||||
}
|
||||
}
|
||||
|
||||
namespace FuzeWorks\TemplateEngine;
|
||||
use \FuzeWorks\LayoutException;
|
||||
use \Smarty;
|
||||
|
||||
use FuzeWorks\LayoutException;
|
||||
use Smarty;
|
||||
|
||||
/**
|
||||
* Interface that all Template Engines must follow
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Interface that all Template Engines must follow.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
interface TemplateEngine {
|
||||
interface TemplateEngine
|
||||
{
|
||||
/**
|
||||
* Set the directory of the current template
|
||||
* @param String $directory Template Directory
|
||||
* Set the directory of the current template.
|
||||
*
|
||||
* @param string $directory Template Directory
|
||||
*/
|
||||
public function setDirectory($directory);
|
||||
|
||||
/**
|
||||
* Handle and retrieve a template file
|
||||
* @param String $file Template File
|
||||
* @param Array $assigned_variables All the variables used in this view
|
||||
* @return String Output of the template
|
||||
* Handle and retrieve a template file.
|
||||
*
|
||||
* @param string $file Template File
|
||||
* @param array $assigned_variables All the variables used in this view
|
||||
*
|
||||
* @return string Output of the template
|
||||
*/
|
||||
public function get($file, $assigned_variables);
|
||||
|
||||
/**
|
||||
* Retrieve the file extensions that this template engine uses
|
||||
* @return Array All used extensions. eg: array('php')
|
||||
* Retrieve the file extensions that this template engine uses.
|
||||
*
|
||||
* @return array All used extensions. eg: array('php')
|
||||
*/
|
||||
public function getFileExtensions();
|
||||
|
||||
|
@ -476,30 +544,34 @@ interface TemplateEngine {
|
|||
}
|
||||
|
||||
/**
|
||||
* Simple Template Engine that allows for PHP templates
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Simple Template Engine that allows for PHP templates.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class PHPEngine implements TemplateEngine {
|
||||
|
||||
class PHPEngine implements TemplateEngine
|
||||
{
|
||||
/**
|
||||
* The currently used directory by the template
|
||||
* @var String
|
||||
* The currently used directory by the template.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
* All the currently assigned variables
|
||||
* All the currently assigned variables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $assigned_variables = array();
|
||||
|
||||
public function setDirectory($directory) {
|
||||
public function setDirectory($directory)
|
||||
{
|
||||
$this->directory = $directory;
|
||||
}
|
||||
|
||||
public function get($file, $assigned_variables) {
|
||||
public function get($file, $assigned_variables)
|
||||
{
|
||||
// First set all the variables
|
||||
$this->assigned_variables = $assigned_variables;
|
||||
$vars = $this->assigned_variables;
|
||||
|
@ -508,52 +580,60 @@ class PHPEngine implements TemplateEngine {
|
|||
// Then run the file
|
||||
if (!is_null($file)) {
|
||||
ob_start();
|
||||
require($file);
|
||||
include $file;
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
public function getFileExtensions() {
|
||||
public function getFileExtensions()
|
||||
{
|
||||
return array('php');
|
||||
}
|
||||
|
||||
public function reset() {
|
||||
public function reset()
|
||||
{
|
||||
$this->directory = null;
|
||||
$this->assigned_variables = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the Smarty Template Engine
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Wrapper for the Smarty Template Engine.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class SmartyEngine implements TemplateEngine {
|
||||
|
||||
class SmartyEngine implements TemplateEngine
|
||||
{
|
||||
/**
|
||||
* The currently used directory by the template
|
||||
* @var String
|
||||
* The currently used directory by the template.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
* All the currently assigned variables
|
||||
* All the currently assigned variables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $assigned_variables = array();
|
||||
|
||||
/**
|
||||
* Instance of the Smarty Template Engine
|
||||
* Instance of the Smarty Template Engine.
|
||||
*
|
||||
* @var \Smarty
|
||||
*/
|
||||
protected $smartyInstance;
|
||||
|
||||
public function setDirectory($directory) {
|
||||
public function setDirectory($directory)
|
||||
{
|
||||
$this->directory = $directory;
|
||||
}
|
||||
|
||||
public function get($file, $assigned_variables) {
|
||||
public function get($file, $assigned_variables)
|
||||
{
|
||||
// First set all the variables
|
||||
$this->assigned_variables = $assigned_variables;
|
||||
|
||||
|
@ -573,35 +653,42 @@ class SmartyEngine implements TemplateEngine {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads a Smarty instance if it is not already loaded
|
||||
* Loads a Smarty instance if it is not already loaded.
|
||||
*/
|
||||
private function loadSmarty() {
|
||||
private function loadSmarty()
|
||||
{
|
||||
if (is_null($this->smartyInstance)) {
|
||||
$this->smartyInstance = new Smarty();
|
||||
|
||||
// Then prepare all variables
|
||||
$this->smartyInstance->setCompileDir("Core/Cache/Compile");
|
||||
$this->smartyInstance->setCacheDir("Core/Cache/");
|
||||
$this->smartyInstance->setCompileDir('Core/Cache/Compile');
|
||||
$this->smartyInstance->setCacheDir('Core/Cache/');
|
||||
}
|
||||
}
|
||||
|
||||
public function getFileExtensions() {
|
||||
public function getFileExtensions()
|
||||
{
|
||||
return array('tpl');
|
||||
}
|
||||
|
||||
public function reset() {
|
||||
public function reset()
|
||||
{
|
||||
$this->smartyInstance = null;
|
||||
$this->directory = null;
|
||||
$this->assigned_variables = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a value from Smarty
|
||||
* @param String $name Variable name
|
||||
* @return Mixed Variable Value
|
||||
* Retrieve a value from Smarty.
|
||||
*
|
||||
* @param string $name Variable name
|
||||
*
|
||||
* @return mixed Variable Value
|
||||
*
|
||||
* @throws \FuzeWorks\LayoutException on error
|
||||
*/
|
||||
public function __get($name) {
|
||||
public function __get($name)
|
||||
{
|
||||
// First load Smarty
|
||||
$this->loadSmarty();
|
||||
|
||||
|
@ -609,12 +696,15 @@ class SmartyEngine implements TemplateEngine {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set a variable in Smarty
|
||||
* @param String $name Variable Name
|
||||
* @param Mixed $value Variable Value
|
||||
* Set a variable in Smarty.
|
||||
*
|
||||
* @param string $name Variable Name
|
||||
* @param mixed $value Variable Value
|
||||
*
|
||||
* @throws \FuzeWorks\LayoutException on error
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
public function __set($name, $value)
|
||||
{
|
||||
// First load Smarty
|
||||
$this->loadSmarty();
|
||||
|
||||
|
@ -622,51 +712,61 @@ class SmartyEngine implements TemplateEngine {
|
|||
}
|
||||
|
||||
/**
|
||||
* Calls a function in Smarty
|
||||
* @param String $name Name of the function to be called
|
||||
* Calls a function in Smarty.
|
||||
*
|
||||
* @param string $name Name of the function to be called
|
||||
* @param Paramaters $params Parameters to be used
|
||||
* @return Mixed Function output
|
||||
*
|
||||
* @return mixed Function output
|
||||
*/
|
||||
public function __call($name, $params) {
|
||||
public function __call($name, $params)
|
||||
{
|
||||
// First load Smarty
|
||||
$this->loadSmarty();
|
||||
|
||||
return call_user_func_array(array($this->smartyInstance, $name), $params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Template Engine that exports all assigned variables as JSON
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Template Engine that exports all assigned variables as JSON.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class JSONEngine implements TemplateEngine {
|
||||
|
||||
class JSONEngine implements TemplateEngine
|
||||
{
|
||||
/**
|
||||
* All the currently assigned variables
|
||||
* All the currently assigned variables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $assigned_variables = array();
|
||||
|
||||
/**
|
||||
* Whether the JSON data should be parsed or left as is
|
||||
* @var boolean true if to be parsed
|
||||
* Whether the JSON data should be parsed or left as is.
|
||||
*
|
||||
* @var bool true if to be parsed
|
||||
*/
|
||||
protected static $string_return = true;
|
||||
|
||||
/**
|
||||
* Whether the JSON data should be parsed or left as is
|
||||
* Whether the JSON data should be parsed or left as is.
|
||||
*
|
||||
* @param true if to be parsed
|
||||
*/
|
||||
public static function returnAsString($boolean = true) {
|
||||
public static function returnAsString($boolean = true)
|
||||
{
|
||||
self::$string_return = $boolean;
|
||||
}
|
||||
|
||||
public function setDirectory($directory) {
|
||||
public function setDirectory($directory)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get($file, $assigned_variables) {
|
||||
public function get($file, $assigned_variables)
|
||||
{
|
||||
// First set all the variables
|
||||
$this->assigned_variables = $assigned_variables;
|
||||
|
||||
|
@ -684,24 +784,26 @@ class JSONEngine implements TemplateEngine {
|
|||
$json['data'] = $this->assigned_variables;
|
||||
|
||||
// And return it
|
||||
if (self::$string_return)
|
||||
if (self::$string_return) {
|
||||
return json_encode($json);
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
public function getFileExtensions() {
|
||||
public function getFileExtensions()
|
||||
{
|
||||
return array('json');
|
||||
}
|
||||
|
||||
public function reset() {
|
||||
public function reset()
|
||||
{
|
||||
$this->assigned_variables = array();
|
||||
$this->string_return = true;
|
||||
}
|
||||
|
||||
public function test($param1, $param2, $param3) {
|
||||
public function test($param1, $param2, $param3)
|
||||
{
|
||||
return array($param1, $param2, $param3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,60 +20,68 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Logger Class
|
||||
* Logger Class.
|
||||
*
|
||||
* The main tool to handle errors and exceptions. Provides some tools for debugging and tracking where errors take place
|
||||
* All fatal errors get catched by this class and get displayed if configured to do so.
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Logger {
|
||||
|
||||
class Logger
|
||||
{
|
||||
/**
|
||||
* Log entries which display information entries
|
||||
* Log entries which display information entries.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $infoErrors = array();
|
||||
|
||||
/**
|
||||
* Log entries which display critical error entries
|
||||
* Log entries which display critical error entries.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $criticalErrors = array();
|
||||
|
||||
/**
|
||||
* Log entries which display warning entries
|
||||
* Log entries which display warning entries.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $warningErrors = array();
|
||||
|
||||
/**
|
||||
* All log entries, unsorted
|
||||
* All log entries, unsorted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $Logs = array();
|
||||
|
||||
/**
|
||||
* whether to output the log after FuzeWorks has run
|
||||
* @var boolean
|
||||
* whether to output the log after FuzeWorks has run.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private static $print_to_screen = false;
|
||||
|
||||
/**
|
||||
* whether to output the log after FuzeWorks has run, regardless of conditions
|
||||
* @var boolean
|
||||
* whether to output the log after FuzeWorks has run, regardless of conditions.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $debug = false;
|
||||
|
||||
|
@ -82,15 +90,16 @@ class Logger {
|
|||
*
|
||||
* Registers the error and exception handler, when required to do so by configuration
|
||||
*/
|
||||
public static function init() {
|
||||
public static function init()
|
||||
{
|
||||
// Register the error handler
|
||||
if (Config::get('error')->error_reporting == true) {
|
||||
set_error_handler(array('\FuzeWorks\Logger', "errorHandler"), E_ALL);
|
||||
set_Exception_handler(array('\FuzeWorks\Logger', "exceptionHandler"));
|
||||
set_error_handler(array('\FuzeWorks\Logger', 'errorHandler'), E_ALL);
|
||||
set_Exception_handler(array('\FuzeWorks\Logger', 'exceptionHandler'));
|
||||
error_reporting(false);
|
||||
}
|
||||
self::$debug = Config::get('error')->debug;
|
||||
self::newLevel("Logger Initiated");
|
||||
self::newLevel('Logger Initiated');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,15 +107,16 @@ class Logger {
|
|||
*
|
||||
* Logs a fatal error and outputs the log when configured or requested to do so
|
||||
*/
|
||||
public static function shutdown() {
|
||||
public static function shutdown()
|
||||
{
|
||||
// Load last error if thrown
|
||||
$errfile = "Unknown file";
|
||||
$errstr = "shutdown";
|
||||
$errfile = 'Unknown file';
|
||||
$errstr = 'shutdown';
|
||||
$errno = E_CORE_ERROR;
|
||||
$errline = 0;
|
||||
|
||||
$error = error_get_last();
|
||||
if ($error !== NULL) {
|
||||
if ($error !== null) {
|
||||
$errno = $error['type'];
|
||||
$errfile = $error['file'];
|
||||
$errline = $error['line'];
|
||||
|
@ -121,30 +131,30 @@ class Logger {
|
|||
self::stopLevel();
|
||||
|
||||
if (self::$debug == true || self::$print_to_screen) {
|
||||
self::log("Parsing debug log");
|
||||
self::log('Parsing debug log');
|
||||
echo self::logToScreen();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* System that redirects the errors to the appropriate logging method
|
||||
* @access public
|
||||
* System that redirects the errors to the appropriate logging method.
|
||||
*
|
||||
* @param int $type Error-type, Pre defined PHP Constant
|
||||
* @param string error. The error itself
|
||||
* @param string File. The absolute path of the file
|
||||
* @param int Line. The line on which the error occured.
|
||||
* @param array context. Some of the error's relevant variables
|
||||
* @return void
|
||||
*/
|
||||
public static function errorHandler($type = E_USER_NOTICE, $error = "Undefined Error", $errFile = null, $errLine = null, $context = null) {
|
||||
public static function errorHandler($type = E_USER_NOTICE, $error = 'Undefined Error', $errFile = null, $errLine = null, $context = null)
|
||||
{
|
||||
// Check type
|
||||
$thisType = self::getType($type);
|
||||
$LOG = array('type' => (!is_null($thisType) ? $thisType : "ERROR"),
|
||||
'message' => (!is_null($error) ? $error : ""),
|
||||
'logFile' => (!is_null($errFile) ? $errFile : ""),
|
||||
'logLine' => (!is_null($errLine) ? $errLine : ""),
|
||||
'context' => (!is_null($context) ? $context : ""),
|
||||
'runtime' => round(self::getRelativeTime(), 4));
|
||||
$LOG = array('type' => (!is_null($thisType) ? $thisType : 'ERROR'),
|
||||
'message' => (!is_null($error) ? $error : ''),
|
||||
'logFile' => (!is_null($errFile) ? $errFile : ''),
|
||||
'logLine' => (!is_null($errLine) ? $errLine : ''),
|
||||
'context' => (!is_null($context) ? $context : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4), );
|
||||
self::$Logs[] = $LOG;
|
||||
}
|
||||
|
||||
|
@ -153,9 +163,7 @@ class Logger {
|
|||
* Will be triggered when an uncaught exception occures. This function shows the error-message, and shuts down the script.
|
||||
* Please note that most of the user-defined exceptions will be caught in the router, and handled with the error-controller.
|
||||
*
|
||||
* @access public
|
||||
* @param Exception $exception The occured exception.
|
||||
* @return void
|
||||
*/
|
||||
public static function exceptionHandler($exception)
|
||||
{
|
||||
|
@ -165,14 +173,16 @@ class Logger {
|
|||
$line = $exception->getLine();
|
||||
$context = $exception->getTraceAsString();
|
||||
|
||||
self::logError("Exception thrown: " . $message . " | " . $code, null, $file, $line);
|
||||
self::logError('Exception thrown: '.$message.' | '.$code, null, $file, $line);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the entire log to the screen. Used for debugging problems with your code.
|
||||
* @return String Output of the log
|
||||
*
|
||||
* @return string Output of the log
|
||||
*/
|
||||
public static function logToScreen() {
|
||||
public static function logToScreen()
|
||||
{
|
||||
// Send a screenLogEvent, allows for new screen log designs
|
||||
$event = Events::fireEvent('screenLogEvent');
|
||||
if ($event->isCancelled()) {
|
||||
|
@ -182,25 +192,24 @@ class Logger {
|
|||
// Otherwise just load it
|
||||
$string = '<h3>FuzeWorks debug log</h3>';
|
||||
$layer = 0;
|
||||
for($i = 0; $i < count(self::$Logs); $i++){
|
||||
|
||||
for ($i = 0; $i < count(self::$Logs); ++$i) {
|
||||
$log = self::$Logs[$i];
|
||||
if($log['type'] == 'LEVEL_START'){
|
||||
$layer++;
|
||||
$color = 255-($layer*25);
|
||||
if ($log['type'] == 'LEVEL_START') {
|
||||
++$layer;
|
||||
$color = 255 - ($layer * 25);
|
||||
$string .= '<div style="background: rgb(188 , 232 ,'.$color.');border: 1px black solid;margin: 5px 0;padding: 5px 20px;">';
|
||||
$string .= '<div style="font-weight: bold; font-size: 11pt;">'.$log['message'].'<span style="float: right">'.(!empty($log['runtime']) ? "(".round($log['runtime']*1000, 4).'ms)' : "").'</span></div>';
|
||||
} elseif ($log['type'] == "LEVEL_STOP") {
|
||||
$layer--;
|
||||
$string .= "</div>";
|
||||
} elseif ($log['type'] == "ERROR") {
|
||||
$string .= '<div style="'.($layer == 0 ? 'padding-left: 21px;' : "").'font-size: 11pt; background-color:#f56954;">['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '<u>['.$log['context'].']</u>' : "").' '.$log["message"].'
|
||||
<span style="float: right">'.(!empty($log['logFile']) ? $log['logFile'] : "")." : ".(!empty($log['logLine']) ? $log['logLine'] : "").'('.round($log['runtime']*1000, 4).' ms)</span></div>';
|
||||
} elseif ($log['type'] == "WARNING") {
|
||||
$string .= '<div style="'.($layer == 0 ? 'padding-left: 21px;' : "").'font-size: 11pt; background-color:#f39c12;">['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '<u>['.$log['context'].']</u>' : "").' '.$log["message"].'
|
||||
<span style="float: right">'.(!empty($log['logFile']) ? $log['logFile'] : "")." : ".(!empty($log['logLine']) ? $log['logLine'] : "").'('.round($log['runtime']*1000, 4).' ms)</span></div>';
|
||||
} elseif ($log['type'] == "INFO") {
|
||||
$string .= '<div style="'.($layer == 0 ? 'padding-left: 21px;' : "").'font-size: 11pt;">'.(!empty($log['context']) ? '<u>['.$log['context'].']</u>' : "").' '.$log["message"].'<span style="float: right">('.round($log['runtime']*1000, 4).' ms)</span></div>';
|
||||
$string .= '<div style="font-weight: bold; font-size: 11pt;">'.$log['message'].'<span style="float: right">'.(!empty($log['runtime']) ? '('.round($log['runtime'] * 1000, 4).'ms)' : '').'</span></div>';
|
||||
} elseif ($log['type'] == 'LEVEL_STOP') {
|
||||
--$layer;
|
||||
$string .= '</div>';
|
||||
} elseif ($log['type'] == 'ERROR') {
|
||||
$string .= '<div style="'.($layer == 0 ? 'padding-left: 21px;' : '').'font-size: 11pt; background-color:#f56954;">['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '<u>['.$log['context'].']</u>' : '').' '.$log['message'].'
|
||||
<span style="float: right">'.(!empty($log['logFile']) ? $log['logFile'] : '').' : '.(!empty($log['logLine']) ? $log['logLine'] : '').'('.round($log['runtime'] * 1000, 4).' ms)</span></div>';
|
||||
} elseif ($log['type'] == 'WARNING') {
|
||||
$string .= '<div style="'.($layer == 0 ? 'padding-left: 21px;' : '').'font-size: 11pt; background-color:#f39c12;">['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '<u>['.$log['context'].']</u>' : '').' '.$log['message'].'
|
||||
<span style="float: right">'.(!empty($log['logFile']) ? $log['logFile'] : '').' : '.(!empty($log['logLine']) ? $log['logLine'] : '').'('.round($log['runtime'] * 1000, 4).' ms)</span></div>';
|
||||
} elseif ($log['type'] == 'INFO') {
|
||||
$string .= '<div style="'.($layer == 0 ? 'padding-left: 21px;' : '').'font-size: 11pt;">'.(!empty($log['context']) ? '<u>['.$log['context'].']</u>' : '').' '.$log['message'].'<span style="float: right">('.round($log['runtime'] * 1000, 4).' ms)</span></div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,10 +217,12 @@ class Logger {
|
|||
}
|
||||
|
||||
/**
|
||||
* Backtrace a problem to the source using the trace of an Exception
|
||||
* Backtrace a problem to the source using the trace of an Exception.
|
||||
*
|
||||
* @return string HTML backtrace
|
||||
*/
|
||||
public static function backtrace() {
|
||||
public static function backtrace()
|
||||
{
|
||||
$e = new Exception();
|
||||
$trace = explode("\n", $e->getTraceAsString());
|
||||
// reverse array to make steps line up chronologically
|
||||
|
@ -221,122 +232,127 @@ class Logger {
|
|||
$length = count($trace);
|
||||
$result = array();
|
||||
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
{
|
||||
$result[] = ($i + 1) . ')' . substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering
|
||||
for ($i = 0; $i < $length; ++$i) {
|
||||
$result[] = ($i + 1).')'.substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering
|
||||
}
|
||||
|
||||
return "<b>BACKTRACE: <br/>\t" . implode("<br/>", $result)."</b>";
|
||||
return "<b>BACKTRACE: <br/>\t".implode('<br/>', $result).'</b>';
|
||||
}
|
||||
|
||||
/* =========================================LOGGING METHODS==============================================================*/
|
||||
|
||||
/**
|
||||
* Create a information log entry
|
||||
* @param String $msg The information to be logged
|
||||
* @param String $mod The name of the module
|
||||
* @param String $file The file where the log occured
|
||||
* @param integer $line The line where the log occured
|
||||
* @return void
|
||||
* Create a information log entry.
|
||||
*
|
||||
* @param string $msg The information to be logged
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
*/
|
||||
public static function log($msg, $mod = null, $file = 0, $line = 0) {
|
||||
public static function log($msg, $mod = null, $file = 0, $line = 0)
|
||||
{
|
||||
self::logInfo($msg, $mod, $file, $line);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a information log entry
|
||||
* @param String $msg The information to be logged
|
||||
* @param String $mod The name of the module
|
||||
* @param String $file The file where the log occured
|
||||
* @param integer $line The line where the log occured
|
||||
* @return void
|
||||
* Create a information log entry.
|
||||
*
|
||||
* @param string $msg The information to be logged
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
*/
|
||||
public static function logInfo($msg, $mod = null, $file = 0, $line = 0) {
|
||||
public static function logInfo($msg, $mod = null, $file = 0, $line = 0)
|
||||
{
|
||||
$LOG = array('type' => 'INFO',
|
||||
'message' => (!is_null($msg) ? $msg : ""),
|
||||
'logFile' => (!is_null($file) ? $file : ""),
|
||||
'logLine' => (!is_null($line) ? $line : ""),
|
||||
'context' => (!is_null($mod) ? $mod : ""),
|
||||
'runtime' => round(self::getRelativeTime(), 4));
|
||||
'message' => (!is_null($msg) ? $msg : ''),
|
||||
'logFile' => (!is_null($file) ? $file : ''),
|
||||
'logLine' => (!is_null($line) ? $line : ''),
|
||||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4), );
|
||||
|
||||
self::$infoErrors[] = $LOG;
|
||||
self::$Logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a error log entry
|
||||
* @param String $msg The information to be logged
|
||||
* @param String $mod The name of the module
|
||||
* @param String $file The file where the log occured
|
||||
* @param integer $line The line where the log occured
|
||||
* @return void
|
||||
* Create a error log entry.
|
||||
*
|
||||
* @param string $msg The information to be logged
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
*/
|
||||
public static function logError($msg, $mod = null, $file = 0, $line = 0) {
|
||||
public static function logError($msg, $mod = null, $file = 0, $line = 0)
|
||||
{
|
||||
$LOG = array('type' => 'ERROR',
|
||||
'message' => (!is_null($msg) ? $msg : ""),
|
||||
'logFile' => (!is_null($file) ? $file : ""),
|
||||
'logLine' => (!is_null($line) ? $line : ""),
|
||||
'context' => (!is_null($mod) ? $mod : ""),
|
||||
'runtime' => round(self::getRelativeTime(), 4));
|
||||
'message' => (!is_null($msg) ? $msg : ''),
|
||||
'logFile' => (!is_null($file) ? $file : ''),
|
||||
'logLine' => (!is_null($line) ? $line : ''),
|
||||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4), );
|
||||
|
||||
self::$criticalErrors[] = $LOG;
|
||||
self::$Logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a warning log entry
|
||||
* @param String $msg The information to be logged
|
||||
* @param String $mod The name of the module
|
||||
* @param String $file The file where the log occured
|
||||
* @param integer $line The line where the log occured
|
||||
* @return void
|
||||
* Create a warning log entry.
|
||||
*
|
||||
* @param string $msg The information to be logged
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
*/
|
||||
public static function logWarning($msg, $mod = null, $file = 0, $line = 0) {
|
||||
public static function logWarning($msg, $mod = null, $file = 0, $line = 0)
|
||||
{
|
||||
$LOG = array('type' => 'WARNING',
|
||||
'message' => (!is_null($msg) ? $msg : ""),
|
||||
'logFile' => (!is_null($file) ? $file : ""),
|
||||
'logLine' => (!is_null($line) ? $line : ""),
|
||||
'context' => (!is_null($mod) ? $mod : ""),
|
||||
'runtime' => round(self::getRelativeTime(), 4));
|
||||
'message' => (!is_null($msg) ? $msg : ''),
|
||||
'logFile' => (!is_null($file) ? $file : ''),
|
||||
'logLine' => (!is_null($line) ? $line : ''),
|
||||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4), );
|
||||
|
||||
self::$warningErrors[] = $LOG;
|
||||
self::$Logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Level log entry. Used to categorise logs
|
||||
* @param String $msg The name of the new level
|
||||
* @param String $mod The name of the module
|
||||
* @param String $file The file where the log occured
|
||||
* @param integer $line The line where the log occured
|
||||
* @return void
|
||||
* Create a new Level log entry. Used to categorise logs.
|
||||
*
|
||||
* @param string $msg The name of the new level
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
*/
|
||||
public static function newLevel($msg, $mod = null, $file = null, $line = null) {
|
||||
public static function newLevel($msg, $mod = null, $file = null, $line = null)
|
||||
{
|
||||
$LOG = array('type' => 'LEVEL_START',
|
||||
'message' => (!is_null($msg) ? $msg : ""),
|
||||
'logFile' => (!is_null($file) ? $file : ""),
|
||||
'logLine' => (!is_null($line) ? $line : ""),
|
||||
'context' => (!is_null($mod) ? $mod : ""),
|
||||
'runtime' => round(self::getRelativeTime(), 4));
|
||||
'message' => (!is_null($msg) ? $msg : ''),
|
||||
'logFile' => (!is_null($file) ? $file : ''),
|
||||
'logLine' => (!is_null($line) ? $line : ''),
|
||||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4), );
|
||||
|
||||
self::$Logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a stop Level log entry. Used to close log categories
|
||||
* @param String $msg The name of the new level
|
||||
* @param String $mod The name of the module
|
||||
* @param String $file The file where the log occured
|
||||
* @param integer $line The line where the log occured
|
||||
* @return void
|
||||
* Create a stop Level log entry. Used to close log categories.
|
||||
*
|
||||
* @param string $msg The name of the new level
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
*/
|
||||
public static function stopLevel($msg = null, $mod = null, $file = null, $line = null) {
|
||||
public static function stopLevel($msg = null, $mod = null, $file = null, $line = null)
|
||||
{
|
||||
$LOG = array('type' => 'LEVEL_STOP',
|
||||
'message' => (!is_null($msg) ? $msg : ""),
|
||||
'logFile' => (!is_null($file) ? $file : ""),
|
||||
'logLine' => (!is_null($line) ? $line : ""),
|
||||
'context' => (!is_null($mod) ? $mod : ""),
|
||||
'runtime' => round(self::getRelativeTime(), 4));
|
||||
'message' => (!is_null($msg) ? $msg : ''),
|
||||
'logFile' => (!is_null($file) ? $file : ''),
|
||||
'logLine' => (!is_null($line) ? $line : ''),
|
||||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4), );
|
||||
|
||||
self::$Logs[] = $LOG;
|
||||
}
|
||||
|
@ -347,45 +363,43 @@ class Logger {
|
|||
* Returns a string representation of an error
|
||||
* Turns a PHP error-constant (or integer) into a string representation.
|
||||
*
|
||||
* @access public
|
||||
* @param int $type PHP-constant errortype (e.g. E_NOTICE).
|
||||
*
|
||||
* @return string String representation
|
||||
*/
|
||||
public static function getType($type) {
|
||||
|
||||
switch ($type)
|
||||
public static function getType($type)
|
||||
{
|
||||
|
||||
switch ($type) {
|
||||
case E_ERROR:
|
||||
return "ERROR";
|
||||
return 'ERROR';
|
||||
case E_WARNING:
|
||||
return "WARNING";
|
||||
return 'WARNING';
|
||||
case E_PARSE:
|
||||
return "ERROR";
|
||||
return 'ERROR';
|
||||
case E_NOTICE:
|
||||
return "WARNING";
|
||||
return 'WARNING';
|
||||
case E_CORE_ERROR:
|
||||
return "ERROR";
|
||||
return 'ERROR';
|
||||
case E_CORE_WARNING:
|
||||
return "WARNING";
|
||||
return 'WARNING';
|
||||
case E_COMPILE_ERROR:
|
||||
return "ERROR";
|
||||
return 'ERROR';
|
||||
case E_COMPILE_WARNING:
|
||||
return "WARNING";
|
||||
return 'WARNING';
|
||||
case E_USER_ERROR:
|
||||
return "ERROR";
|
||||
return 'ERROR';
|
||||
case E_USER_WARNING:
|
||||
return "WARNING";
|
||||
return 'WARNING';
|
||||
case E_USER_NOTICE:
|
||||
return "WARNING";
|
||||
return 'WARNING';
|
||||
case E_USER_DEPRECATED:
|
||||
return "WARNING";
|
||||
return 'WARNING';
|
||||
case E_STRICT:
|
||||
return "ERROR";
|
||||
return 'ERROR';
|
||||
case E_RECOVERABLE_ERROR:
|
||||
return "ERROR";
|
||||
return 'ERROR';
|
||||
case E_DEPRECATED:
|
||||
return "WARNING";
|
||||
return 'WARNING';
|
||||
}
|
||||
|
||||
return $type = 'Unknown error: '.$type;
|
||||
|
@ -393,11 +407,12 @@ class Logger {
|
|||
|
||||
/**
|
||||
* Calls an HTTP error, sends it as a header, and loads a template if required to do so.
|
||||
* @param integer $errno HTTP error code
|
||||
* @param boolean $view true to view error on website
|
||||
*
|
||||
* @param int $errno HTTP error code
|
||||
* @param bool $view true to view error on website
|
||||
*/
|
||||
public static function http_error($errno = 500, $view = true){
|
||||
|
||||
public static function http_error($errno = 500, $view = true)
|
||||
{
|
||||
$http_codes = array(
|
||||
|
||||
400 => 'Bad Request',
|
||||
|
@ -432,7 +447,7 @@ class Logger {
|
|||
506 => 'Variant Also Negotiates',
|
||||
509 => 'Bandwidth Limit Exceeded',
|
||||
510 => 'Not Extended',
|
||||
511 => 'Network Authentication Required'
|
||||
511 => 'Network Authentication Required',
|
||||
);
|
||||
|
||||
self::logError('HTTP-error '.$errno.' called');
|
||||
|
@ -440,35 +455,36 @@ class Logger {
|
|||
header('HTTP/1.1 '.$errno.' '.$http_codes[$errno]);
|
||||
|
||||
// Do we want the error-view with it?
|
||||
if($view == false)
|
||||
if ($view == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the view
|
||||
$view = 'errors/'.$errno;
|
||||
self::log('Loading view '.$view);
|
||||
|
||||
// Try and load the view, if impossible, load HTTP code instead.
|
||||
try{
|
||||
try {
|
||||
Layout::view($view);
|
||||
} catch(LayoutException $exception){
|
||||
} catch (LayoutException $exception) {
|
||||
// No error page could be found, just echo the result
|
||||
echo "<h1>$errno</h1><h3>".$http_codes[$errno]."</h3>";
|
||||
echo "<h1>$errno</h1><h3>".$http_codes[$errno].'</h3>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable error to screen logging
|
||||
* @access public
|
||||
* Enable error to screen logging.
|
||||
*/
|
||||
public static function enable() {
|
||||
public static function enable()
|
||||
{
|
||||
self::$print_to_screen = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable error to screen logging
|
||||
* @access public
|
||||
* Disable error to screen logging.
|
||||
*/
|
||||
public static function disable() {
|
||||
public static function disable()
|
||||
{
|
||||
self::$print_to_screen = false;
|
||||
}
|
||||
|
||||
|
@ -476,14 +492,14 @@ class Logger {
|
|||
* Get the relative time since the framework started.
|
||||
*
|
||||
* Used for debugging timings in FuzeWorks
|
||||
*
|
||||
* @return int Time passed since FuzeWorks init
|
||||
*/
|
||||
private static function getRelativeTime() {
|
||||
private static function getRelativeTime()
|
||||
{
|
||||
$startTime = STARTTIME;
|
||||
$time = microtime(true) - $startTime;
|
||||
|
||||
return $time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,71 +20,82 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Models Class
|
||||
* Models Class.
|
||||
*
|
||||
* Simple loader class for MVC Models. Typically loads models from Application/Models unless otherwise specified.
|
||||
* If a model is not found, it will load a DatabaseModel type which will analyze the database and can directly be used.
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Models {
|
||||
|
||||
class Models
|
||||
{
|
||||
/**
|
||||
* Array of all the loaded models
|
||||
* Array of all the loaded models.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $models_array = array();
|
||||
|
||||
/**
|
||||
* Array of all the existing model types (classes)
|
||||
* Array of all the existing model types (classes).
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $model_types = array();
|
||||
|
||||
/**
|
||||
* Load a model.
|
||||
* @param String $name Name of the model
|
||||
* @param String $directory Optional directory of the model
|
||||
* @return Object The Model object.
|
||||
*
|
||||
* @param string $name Name of the model
|
||||
* @param string $directory Optional directory of the model
|
||||
*
|
||||
* @return object The Model object.
|
||||
*/
|
||||
public static function loadModel($name, $directory = null){
|
||||
public static function loadModel($name, $directory = null)
|
||||
{
|
||||
// Model load event
|
||||
$event = Events::fireEvent('modelLoadEvent', $name, $directory);
|
||||
$directory = ($event->directory === null ? "Application/Models" : $event->directory);
|
||||
$directory = ($event->directory === null ? 'Application/Models' : $event->directory);
|
||||
$name = ($event->model === null ? $name : $event->model);
|
||||
|
||||
$file = $directory.'/model.'.$name.'.php';
|
||||
if (isset(self::$model_types[$name])) {
|
||||
Logger::log('Loading Model: '.get_class(self::$model_types[$name]), get_class(self::$model_types[$name]));
|
||||
self::$models_array[$name] = self::$model_types[$name];
|
||||
} elseif (file_exists($file)){
|
||||
require_once($file);
|
||||
$model = "\Application\Model\\" . ucfirst($name);
|
||||
} elseif (file_exists($file)) {
|
||||
include_once $file;
|
||||
$model = "\Application\Model\\".ucfirst($name);
|
||||
Logger::log('Loading Model: '.$model, $model);
|
||||
|
||||
return self::$models_array[$name] = new $model();
|
||||
} else{
|
||||
} else {
|
||||
throw new ModelException("The requested model: \''.$name.'\' could not be found", 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a model
|
||||
* @param String $name Name of the model
|
||||
* @return Object The Model object
|
||||
* Retrieve a model.
|
||||
*
|
||||
* @param string $name Name of the model
|
||||
*
|
||||
* @return object The Model object
|
||||
*/
|
||||
public static function get($name){
|
||||
public static function get($name)
|
||||
{
|
||||
// Get the name
|
||||
$name = strtolower($name);
|
||||
|
||||
|
@ -98,5 +109,3 @@ class Models {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,69 +20,79 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
use \stdClass;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Modules Class
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* Modules Class.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Modules {
|
||||
|
||||
class Modules
|
||||
{
|
||||
/**
|
||||
* A register of all the existing module headers.
|
||||
*
|
||||
* The module headers contain information required to loading the module
|
||||
* @var Array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $register;
|
||||
|
||||
/**
|
||||
* A register which holds all the module advertisements by key
|
||||
* A register which holds all the module advertisements by key.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $advertiseRegister = array();
|
||||
|
||||
/**
|
||||
* An array of all the loaded modules
|
||||
* An array of all the loaded modules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array();
|
||||
|
||||
/**
|
||||
* An array with the names of all modules that are loaded, and should not be loaded again
|
||||
* @access private
|
||||
* @var Array of module names
|
||||
* An array with the names of all modules that are loaded, and should not be loaded again.
|
||||
*
|
||||
* @var array of module names
|
||||
*/
|
||||
private static $loaded_modules = array();
|
||||
|
||||
/**
|
||||
* An array which holds the routes to module to load them quickly
|
||||
* @access private
|
||||
* An array which holds the routes to module to load them quickly.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $module_routes = array();
|
||||
|
||||
/**
|
||||
* Retrieves a module and returns it.
|
||||
* If a module is already loaded, it returns a reference to the loaded version
|
||||
* @param String $name Name of the module
|
||||
* If a module is already loaded, it returns a reference to the loaded version.
|
||||
*
|
||||
* @param string $name Name of the module
|
||||
*
|
||||
* @return \FuzeWorks\Module Module The module
|
||||
*
|
||||
* @throws \FuzeWorks\ModuleException
|
||||
*/
|
||||
public static function get($name) {
|
||||
public static function get($name)
|
||||
{
|
||||
// Where the modules are
|
||||
$path = "Modules/";
|
||||
$path = 'Modules/';
|
||||
|
||||
// Check if the requested module is registered
|
||||
if (isset(self::$register[$name])) {
|
||||
|
@ -91,37 +101,40 @@ class Modules {
|
|||
$cfg = (object) self::$register[$name];
|
||||
|
||||
// Check if the module is disabled
|
||||
if (isset($cfg->meta))
|
||||
if (isset($cfg->meta)) {
|
||||
throw new ModuleException("Could not load module. Module '".$name."' is not enabled", 1);
|
||||
}
|
||||
|
||||
// Check if the module is already loaded. If so, only return a reference, if not, load the module
|
||||
if (in_array(strtolower($name), self::$loaded_modules)) {
|
||||
// return the link
|
||||
$c = self::$modules[strtolower($cfg->module_name)];
|
||||
|
||||
return $c;
|
||||
} else {
|
||||
// Load the module
|
||||
$file = $cfg->directory ."/". $cfg->module_file;
|
||||
$file = $cfg->directory.'/'.$cfg->module_file;
|
||||
|
||||
// Load the dependencies before the module loads
|
||||
$deps = (isset($cfg->dependencies) ? $cfg->dependencies : array());
|
||||
for ($i=0; $i < count($deps); $i++) {
|
||||
for ($i = 0; $i < count($deps); ++$i) {
|
||||
self::get($deps[$i]);
|
||||
}
|
||||
|
||||
// Check if the file exists
|
||||
if (file_exists($file)) {
|
||||
// And load it
|
||||
require_once($file);
|
||||
include_once $file;
|
||||
$class_name = $cfg->module_class;
|
||||
$msg = "Loading Module '".ucfirst((isset($cfg->name) ? $cfg->name : $cfg->module_name)) . "'";
|
||||
$msg .= (isset($cfg->version) ? "; version: ".$cfg->version : "");
|
||||
$msg .= (isset($cfg->author) ? "; made by ".$cfg->author : "");
|
||||
$msg .= (isset($cfg->website) ? "; from ".$cfg->website: "");
|
||||
$msg = "Loading Module '".ucfirst((isset($cfg->name) ? $cfg->name : $cfg->module_name))."'";
|
||||
$msg .= (isset($cfg->version) ? '; version: '.$cfg->version : '');
|
||||
$msg .= (isset($cfg->author) ? '; made by '.$cfg->author : '');
|
||||
$msg .= (isset($cfg->website) ? '; from '.$cfg->website : '');
|
||||
Logger::log($msg);
|
||||
} else {
|
||||
// Throw Exception if the file does not exist
|
||||
throw new ModuleException("Could not load module. Module '".$name."' class file was not found.", 1);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -129,6 +142,7 @@ class Modules {
|
|||
if (isset($cfg->abstract)) {
|
||||
if ($cfg->abstract) {
|
||||
$CLASS = new stdClass();
|
||||
|
||||
return self::$modules[strtolower($cfg->module_name)] = &$CLASS;
|
||||
}
|
||||
}
|
||||
|
@ -142,11 +156,13 @@ class Modules {
|
|||
$CLASS::setModulePath($cfg->directory);
|
||||
}
|
||||
|
||||
if (method_exists($CLASS, 'setModuleLinkName'))
|
||||
if (method_exists($CLASS, 'setModuleLinkName')) {
|
||||
$CLASS::setModuleLinkName(strtolower($cfg->module_name));
|
||||
}
|
||||
|
||||
if (method_exists($CLASS, 'setModuleName'))
|
||||
if (method_exists($CLASS, 'setModuleName')) {
|
||||
$CLASS::setModuleName($name);
|
||||
}
|
||||
|
||||
// Send all advertisements
|
||||
if (isset($cfg->listenFor)) {
|
||||
|
@ -165,8 +181,8 @@ class Modules {
|
|||
// Send the moduleConfig if possible
|
||||
if (method_exists($CLASS, 'setModuleConfig')) {
|
||||
// Append the config file to the module CFG (accessable through $this->cfg)
|
||||
if (file_exists($cfg->directory . "/" . "config.".strtolower($cfg->module_name).".php")) {
|
||||
$data = (object) include($cfg->directory . "/" . "config.".strtolower($cfg->module_name).".php");
|
||||
if (file_exists($cfg->directory.'/'.'config.'.strtolower($cfg->module_name).'.php')) {
|
||||
$data = (object) include $cfg->directory.'/'.'config.'.strtolower($cfg->module_name).'.php';
|
||||
foreach ($data as $key => $value) {
|
||||
$cfg->$key = $value;
|
||||
}
|
||||
|
@ -176,8 +192,9 @@ class Modules {
|
|||
}
|
||||
|
||||
// And finally check if it can be loaded
|
||||
if (!method_exists($CLASS, 'onLoad'))
|
||||
if (!method_exists($CLASS, 'onLoad')) {
|
||||
throw new ModuleException("Could not load module. Module '".$name."' does not have an onLoad() method", 1);
|
||||
}
|
||||
|
||||
// Prepare onLoad call
|
||||
$args = func_get_args();
|
||||
|
@ -201,14 +218,16 @@ class Modules {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the value of a module config or moduleInfo.php
|
||||
* @param String $file File to edit
|
||||
* @param String $key Key to edit
|
||||
* @param Mixed $value Value to set
|
||||
* Set the value of a module config or moduleInfo.php.
|
||||
*
|
||||
* @param string $file File to edit
|
||||
* @param string $key Key to edit
|
||||
* @param mixed $value Value to set
|
||||
*/
|
||||
private static function setModuleValue($file, $key, $value) {
|
||||
private static function setModuleValue($file, $key, $value)
|
||||
{
|
||||
if (file_exists($file) && is_writable($file)) {
|
||||
$cfg = require($file);
|
||||
$cfg = include $file;
|
||||
$cfg[$key] = $value;
|
||||
$config = var_export($cfg, true);
|
||||
file_put_contents($file, "<?php return $config ;");
|
||||
|
@ -216,26 +235,29 @@ class Modules {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add a module using a moduleInfo.php file
|
||||
* Add a module using a moduleInfo.php file.
|
||||
*
|
||||
* @param string Path to moduleInfo.php file
|
||||
*
|
||||
* @param String Path to moduleInfo.php file
|
||||
* @throws FuzeWorks\ModuleException
|
||||
*/
|
||||
public static function addModule($moduleInfo_file) {
|
||||
public static function addModule($moduleInfo_file)
|
||||
{
|
||||
$file = $moduleInfo_file;
|
||||
$directory = dirname($file);
|
||||
if (file_exists($file)) {
|
||||
$cfg = (object) require($file);
|
||||
$cfg = (object) include $file;
|
||||
$cfg->directory = $directory;
|
||||
|
||||
// Define the module name
|
||||
$name = "";
|
||||
$name .= (!empty($cfg->author) ? strtolower($cfg->author)."/" : "");
|
||||
$name = '';
|
||||
$name .= (!empty($cfg->author) ? strtolower($cfg->author).'/' : '');
|
||||
$name .= strtolower($cfg->module_name);
|
||||
|
||||
Logger::log("Adding module: '".$name."'");
|
||||
if (isset(self::$register[$name])) {
|
||||
Logger::logError("Module '".$name."' can not be added. Module is already loaded");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -251,7 +273,7 @@ class Modules {
|
|||
$cfg2->module_name = $cfg->module_name;
|
||||
$cfg2->directory = $cfg->directory;
|
||||
$cfg2->meta = $cfg;
|
||||
self::$register[$name] = (array)$cfg2;
|
||||
self::$register[$name] = (array) $cfg2;
|
||||
Logger::log("[OFF] '".$name."'");
|
||||
}
|
||||
} else {
|
||||
|
@ -265,14 +287,15 @@ class Modules {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enables a module when it is disabled
|
||||
* Enables a module when it is disabled.
|
||||
*
|
||||
* @param string Module name
|
||||
* @param bool true for permanent enable
|
||||
*
|
||||
* @access public
|
||||
* @param String Module name
|
||||
* @param boolean true for permanent enable
|
||||
* @throws FuzeWorks\ModuleException
|
||||
*/
|
||||
public static function enableModule($name, $permanent = true) {
|
||||
public static function enableModule($name, $permanent = true)
|
||||
{
|
||||
if (isset(self::$register[$name])) {
|
||||
// Change the register
|
||||
$info = (object) self::$register[$name];
|
||||
|
@ -281,6 +304,7 @@ class Modules {
|
|||
if (isset($info->enabled)) {
|
||||
if ($info->enabled) {
|
||||
Logger::logWarning("Could not enable module '".$name."'. Module is already enabled.");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -288,13 +312,13 @@ class Modules {
|
|||
// Otherwise move data from meta to the module config
|
||||
$info = $info->meta;
|
||||
$info->enabled = true;
|
||||
self::$register[$name] = (array)$info;
|
||||
self::$register[$name] = (array) $info;
|
||||
|
||||
Logger::log("Enabled module '".$name."'");
|
||||
|
||||
// Enable it permanently if so desired
|
||||
if ($permanent) {
|
||||
$file = $info->directory . "/moduleInfo.php";
|
||||
$file = $info->directory.'/moduleInfo.php';
|
||||
self::setModuleValue($file, 'enabled', true);
|
||||
}
|
||||
|
||||
|
@ -306,20 +330,22 @@ class Modules {
|
|||
}
|
||||
|
||||
/**
|
||||
* Disableds a module when it is enabled
|
||||
* Disableds a module when it is enabled.
|
||||
*
|
||||
* @param string Module name
|
||||
* @param bool true for permanent disable
|
||||
*
|
||||
* @access public
|
||||
* @param String Module name
|
||||
* @param boolean true for permanent disable
|
||||
* @throws FuzeWorks\ModuleException
|
||||
*/
|
||||
public static function disableModule($name, $permanent = true) {
|
||||
public static function disableModule($name, $permanent = true)
|
||||
{
|
||||
if (isset(self::$register[$name])) {
|
||||
$info = (object) self::$register[$name];
|
||||
|
||||
// Do nothing if it is already disabled
|
||||
if (isset($info->meta)) {
|
||||
Logger::logWarning("Could not disable module '".$name."'. Module is already disabled.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -328,10 +354,10 @@ class Modules {
|
|||
$disabled->directory = $info->directory;
|
||||
$disabled->module_name = $info->module_name;
|
||||
|
||||
self::$register[$name] = (array)$disabled;
|
||||
self::$register[$name] = (array) $disabled;
|
||||
Logger::log("Disabled module '".$name."'");
|
||||
if ($permanent) {
|
||||
$file = $info->directory . "/moduleInfo.php";
|
||||
$file = $info->directory.'/moduleInfo.php';
|
||||
self::setModuleValue($file, 'enabled', false);
|
||||
}
|
||||
|
||||
|
@ -343,20 +369,19 @@ class Modules {
|
|||
} else {
|
||||
throw new ModuleException("Could not disable module '".$name."'. Module does not exist.", 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a register with all the module headers from all the existing modules.
|
||||
*
|
||||
* Used to correctly load all modules
|
||||
* @return void
|
||||
*/
|
||||
public static function buildRegister() {
|
||||
Logger::newLevel("Loading Module Headers", 'Core');
|
||||
public static function buildRegister()
|
||||
{
|
||||
Logger::newLevel('Loading Module Headers', 'Core');
|
||||
|
||||
// Get all the module directories
|
||||
$dir = "Modules/";
|
||||
$dir = 'Modules/';
|
||||
$mod_dirs = array();
|
||||
$mod_dirs = array_values(array_diff(scandir($dir), array('..', '.')));
|
||||
|
||||
|
@ -365,19 +390,19 @@ class Modules {
|
|||
$event_register = array();
|
||||
|
||||
// Cycle through all module directories
|
||||
for ($i=0; $i < count($mod_dirs); $i++) {
|
||||
$mod_dir = $dir . $mod_dirs[$i] . "/";
|
||||
for ($i = 0; $i < count($mod_dirs); ++$i) {
|
||||
$mod_dir = $dir.$mod_dirs[$i].'/';
|
||||
// If a moduleInfo.php exists, load it
|
||||
if (file_exists($mod_dir . "/moduleInfo.php")) {
|
||||
if (file_exists($mod_dir.'/moduleInfo.php')) {
|
||||
// Load the configuration file
|
||||
$cfg = (object) require($mod_dir . "/moduleInfo.php");
|
||||
$cfg = (object) include $mod_dir.'/moduleInfo.php';
|
||||
|
||||
// Set enabled for now
|
||||
$enabled = true;
|
||||
|
||||
// Define the module name
|
||||
$name = "";
|
||||
$name .= (!empty($cfg->author) ? strtolower($cfg->author)."/" : "");
|
||||
$name = '';
|
||||
$name .= (!empty($cfg->author) ? strtolower($cfg->author).'/' : '');
|
||||
$name .= strtolower($cfg->module_name);
|
||||
|
||||
// Get the module directory
|
||||
|
@ -405,10 +430,11 @@ class Modules {
|
|||
$register[$name] = (array) $cfg;
|
||||
|
||||
// Log the name for enabled and disabled
|
||||
if (!$enabled)
|
||||
if (!$enabled) {
|
||||
Logger::newLevel("[OFF] '".$name."'");
|
||||
else
|
||||
} else {
|
||||
Logger::newLevel("[ON] '".$name."'");
|
||||
}
|
||||
|
||||
// And possibly some aliases
|
||||
if (isset($cfg->aliases)) {
|
||||
|
@ -441,10 +467,11 @@ class Modules {
|
|||
// Get the events and add them
|
||||
foreach ($cfg->events as $event) {
|
||||
// First check if the event already exists, if so, append it
|
||||
if (isset($event_register[$event]))
|
||||
if (isset($event_register[$event])) {
|
||||
$event_register[$event][] = $name;
|
||||
else
|
||||
} else {
|
||||
$event_register[$event] = array($name);
|
||||
}
|
||||
|
||||
// Log the event
|
||||
Logger::Log('Event added: \''.$event.'\'');
|
||||
|
@ -456,7 +483,7 @@ class Modules {
|
|||
// Cycle through advertisements
|
||||
foreach ($cfg->advertise as $advertiseName => $advertiseData) {
|
||||
// Log advertisement
|
||||
Logger::log('Advertisement added: \'' .$advertiseName. '\'');
|
||||
Logger::log('Advertisement added: \''.$advertiseName.'\'');
|
||||
|
||||
// Add to advertiseRegister
|
||||
self::$advertiseRegister[$advertiseName][$name] = $advertiseData;
|
||||
|
@ -464,7 +491,6 @@ class Modules {
|
|||
}
|
||||
|
||||
Logger::stopLevel();
|
||||
|
||||
} else {
|
||||
// If no details are specified, create a basic mock module
|
||||
$name = $mod_dirs[$i];
|
||||
|
@ -472,14 +498,14 @@ class Modules {
|
|||
// Build a default mock module config
|
||||
$mock = new stdClass();
|
||||
$mock->module_class = ucfirst($name);
|
||||
$mock->module_file = 'class.'.strtolower($name).".php";
|
||||
$mock->module_file = 'class.'.strtolower($name).'.php';
|
||||
$mock->module_name = $name;
|
||||
$mock->dependencies = array();
|
||||
$mock->versions = array();
|
||||
$mock->directory = $mod_dir;
|
||||
|
||||
// Apply it
|
||||
$register[$name] = (array)$mock;
|
||||
$register[$name] = (array) $mock;
|
||||
Logger::newLevel("[ON] '".$name."'");
|
||||
Logger::stopLevel();
|
||||
}
|
||||
|
@ -489,19 +515,18 @@ class Modules {
|
|||
self::$register = $register;
|
||||
Events::$register = $event_register;
|
||||
Logger::stopLevel();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Module Callable
|
||||
* The Module Callable.
|
||||
*
|
||||
* When a module listens for a specific routing path, this callable get's called.
|
||||
* After this the module can handle the request with the route() function in the module's root directory
|
||||
* @access public
|
||||
*
|
||||
* @param array Regex matches
|
||||
* @return void
|
||||
*/
|
||||
public static function moduleCallable($matches = array()){
|
||||
public static function moduleCallable($matches = array())
|
||||
{
|
||||
// First detect what module is attached to this route
|
||||
Logger::newLevel('Module callable called!');
|
||||
|
||||
|
@ -517,13 +542,11 @@ class Modules {
|
|||
unset($matches['route']);
|
||||
$mod->route($matches);
|
||||
} else {
|
||||
Logger::logError("Route did not match known module. Fatal error");
|
||||
Logger::logError('Route did not match known module. Fatal error');
|
||||
|
||||
return Logger::http_error(500);
|
||||
}
|
||||
|
||||
Logger::stopLevel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,19 +20,22 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
use \Application\Init;
|
||||
|
||||
use Application\Init;
|
||||
|
||||
/**
|
||||
* Class Router
|
||||
* Class Router.
|
||||
*
|
||||
* This class handles the framework's routing. The router determines which system should be loaded and called.
|
||||
* The overall structure of the routing is as follows:
|
||||
|
@ -75,12 +78,11 @@ use \Application\Init;
|
|||
* @see Router::setPath
|
||||
* @see Router::route
|
||||
*
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Router {
|
||||
|
||||
class Router
|
||||
{
|
||||
/**
|
||||
* @var null|string The provided path
|
||||
*/
|
||||
|
@ -102,14 +104,12 @@ class Router {
|
|||
private static $matches = null;
|
||||
|
||||
/**
|
||||
* The constructor adds the default route to the routing table
|
||||
* The constructor adds the default route to the routing table.
|
||||
*/
|
||||
public static function init(){
|
||||
|
||||
foreach(Config::get('routes') as $route => $callable){
|
||||
|
||||
if(is_int($route)) {
|
||||
|
||||
public static function init()
|
||||
{
|
||||
foreach (Config::get('routes') as $route => $callable) {
|
||||
if (is_int($route)) {
|
||||
$route = $callable;
|
||||
$callable = array('\FuzeWorks\Router', 'defaultCallable');
|
||||
}
|
||||
|
@ -119,56 +119,60 @@ class Router {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the current routing path
|
||||
* Returns the current routing path.
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function getPath(){
|
||||
|
||||
public static function getPath()
|
||||
{
|
||||
return self::$path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with all the routes
|
||||
* Returns an array with all the routes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRoutes(){
|
||||
|
||||
public static function getRoutes()
|
||||
{
|
||||
return self::$routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently loaded callable
|
||||
* Returns the currently loaded callable.
|
||||
*
|
||||
* @return null|callable
|
||||
*/
|
||||
public static function getCallable(){
|
||||
|
||||
public static function getCallable()
|
||||
{
|
||||
return self::$callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the matches with the RegEx route
|
||||
* Returns all the matches with the RegEx route.
|
||||
*
|
||||
* @return null|array
|
||||
*/
|
||||
public static function getMatches() {
|
||||
|
||||
public static function getMatches()
|
||||
{
|
||||
return self::$matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current routing path
|
||||
* Set the current routing path.
|
||||
*
|
||||
* @param string $path The routing path (e.g. a/b/c/d/e)
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function setPath($path){
|
||||
public static function setPath($path)
|
||||
{
|
||||
|
||||
// Fire the event to notify our modules
|
||||
$event = Events::fireEvent('routerSetPathEvent', $path);
|
||||
|
||||
// The event has been cancelled
|
||||
if($event->isCancelled()){
|
||||
|
||||
if ($event->isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -176,18 +180,20 @@ class Router {
|
|||
$path = preg_replace('@[/]+@', '/', $event->path);
|
||||
|
||||
// Remove first slash
|
||||
if(substr($path, 0, 1) == '/')
|
||||
if (substr($path, 0, 1) == '/') {
|
||||
$path = substr($path, 1);
|
||||
}
|
||||
|
||||
// Remove trailing slash
|
||||
if(substr($path, -1, 1) == '/')
|
||||
$path = substr($path, 0, strlen($path)-1);
|
||||
if (substr($path, -1, 1) == '/') {
|
||||
$path = substr($path, 0, strlen($path) - 1);
|
||||
}
|
||||
|
||||
return self::$path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a route
|
||||
* Add a route.
|
||||
*
|
||||
* The path will be checked before custom routes before the default route(/controller/function/param1/param2/etc)
|
||||
* When the given RegEx matches the current routing-path, the callable will be called.
|
||||
|
@ -231,23 +237,24 @@ class Router {
|
|||
* @param callable $callable The callable to execute
|
||||
* @param bool $prepend Whether or not to insert at the beginning of the routing table
|
||||
*/
|
||||
public static function addRoute($route, $callable, $prepend = true){
|
||||
|
||||
if($prepend)
|
||||
public static function addRoute($route, $callable, $prepend = true)
|
||||
{
|
||||
if ($prepend) {
|
||||
self::$routes = array($route => $callable) + self::$routes;
|
||||
else
|
||||
} else {
|
||||
self::$routes[$route] = $callable;
|
||||
}
|
||||
|
||||
Logger::log('Route added at '.($prepend ? 'top' : 'bottom').': "'.$route.'"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a route from the array based on the given route
|
||||
* Removes a route from the array based on the given route.
|
||||
*
|
||||
* @param $route string The route to remove
|
||||
*/
|
||||
public static function removeRoute($route){
|
||||
|
||||
public static function removeRoute($route)
|
||||
{
|
||||
unset(self::$routes[$route]);
|
||||
|
||||
Logger::log('Route removed: '.$route);
|
||||
|
@ -258,7 +265,7 @@ class Router {
|
|||
*
|
||||
* Determines what callable should be loaded and what data matches the route regex.
|
||||
*
|
||||
* @param boolean $loadCallable Immediate load the callable when it's route matches
|
||||
* @param bool $loadCallable Immediate load the callable when it's route matches
|
||||
*/
|
||||
public static function route($loadCallable = true)
|
||||
{
|
||||
|
@ -266,8 +273,7 @@ class Router {
|
|||
$event = Events::fireEvent('routerRouteEvent', self::$routes, $loadCallable, self::$path);
|
||||
|
||||
// The event has been cancelled
|
||||
if($event->isCancelled()){
|
||||
|
||||
if ($event->isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -277,25 +283,25 @@ class Router {
|
|||
|
||||
//Check the custom routes
|
||||
foreach ($routes as $r => $c) {
|
||||
|
||||
//A custom route is found
|
||||
if(preg_match($r, $event->path, $matches)) {
|
||||
if (preg_match($r, $event->path, $matches)) {
|
||||
Logger::log('Route matched: '.$r);
|
||||
|
||||
// Add the matches to the current class
|
||||
self::$matches = $matches;
|
||||
|
||||
self::$callable = $c;
|
||||
if(!$loadCallable || !self::loadCallable($matches, $r))
|
||||
if (!$loadCallable || !self::loadCallable($matches, $r)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we found a callable anyway
|
||||
if(self::$callable === null){
|
||||
|
||||
if (self::$callable === null) {
|
||||
Logger::log('No routes found for given path: "'.$event->path.'"', E_WARNING);
|
||||
Logger::http_error(404);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -309,26 +315,27 @@ class Router {
|
|||
*
|
||||
* @param array Preg matches with the routing path
|
||||
* @param string The route that matched
|
||||
* @return boolean Whether or not the callable was satisfied
|
||||
*
|
||||
* @return bool Whether or not the callable was satisfied
|
||||
*/
|
||||
public static function loadCallable($matches = array(), $route){
|
||||
|
||||
public static function loadCallable($matches = array(), $route)
|
||||
{
|
||||
Logger::newLevel('Loading callable');
|
||||
|
||||
// Fire the event to notify our modules
|
||||
$event = Events::fireEvent('routerLoadCallableEvent', self::$callable, $matches, $route);
|
||||
|
||||
// The event has been cancelled
|
||||
if($event->isCancelled())
|
||||
if ($event->isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prepare the arguments and add the route
|
||||
$args = $event->matches;
|
||||
$args['route'] = $event->route;
|
||||
|
||||
if(!is_callable($event->callable))
|
||||
if(isset(self::$callable['controller'])) {
|
||||
|
||||
if (!is_callable($event->callable)) {
|
||||
if (isset(self::$callable['controller'])) {
|
||||
// Reset the arguments and fetch from custom callable
|
||||
$args = array();
|
||||
$args['controller'] = isset(self::$callable['controller']) ? self::$callable['controller'] : (isset($matches['controller']) ? $matches['controller'] : null);
|
||||
|
@ -336,38 +343,41 @@ class Router {
|
|||
$args['parameters'] = isset(self::$callable['parameters']) ? self::$callable['parameters'] : (isset($matches['parameters']) ? explode('/', $matches['parameters']) : null);
|
||||
|
||||
self::$callable = array('\FuzeWorks\Router', 'defaultCallable');
|
||||
}else{
|
||||
|
||||
} else {
|
||||
Logger::log('The given callable is not callable!', E_ERROR);
|
||||
Logger::http_error(500);
|
||||
Logger::stopLevel();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// And log the input to the logger
|
||||
Logger::newLevel('Calling callable');
|
||||
foreach ($args as $key => $value) {
|
||||
Logger::log($key.": ".var_export($value,true)."");
|
||||
Logger::log($key.': '.var_export($value, true).'');
|
||||
}
|
||||
Logger::stopLevel();
|
||||
|
||||
$skip = call_user_func_array(self::$callable, array($args)) === false;
|
||||
|
||||
if($skip)
|
||||
if ($skip) {
|
||||
Logger::log('Callable not satisfied, skipping to next callable');
|
||||
}
|
||||
|
||||
Logger::stopLevel();
|
||||
|
||||
return $skip;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default callable
|
||||
* The default callable.
|
||||
*
|
||||
* This callable will do the 'old skool' routing. It will load the controllers from the controller-directory
|
||||
* in the application-directory.
|
||||
*/
|
||||
public static function defaultCallable($arguments = array()){
|
||||
|
||||
public static function defaultCallable($arguments = array())
|
||||
{
|
||||
Logger::log('Default callable called!');
|
||||
|
||||
$controller = empty($arguments['controller']) ? Config::get('main')->default_controller : $arguments['controller'];
|
||||
|
@ -381,10 +391,10 @@ class Router {
|
|||
Logger::log('Loading controller '.$class.' from file: '.$file);
|
||||
|
||||
// Check if the file exists
|
||||
if(file_exists($file)){
|
||||
|
||||
if(!class_exists($class))
|
||||
require $file;
|
||||
if (file_exists($file)) {
|
||||
if (!class_exists($class)) {
|
||||
include $file;
|
||||
}
|
||||
|
||||
// Get the path the controller should know about
|
||||
$path = substr(self::getPath(), ($pos = strpos(self::getPath(), '/')) !== false ? $pos + 1 : 0);
|
||||
|
@ -398,22 +408,18 @@ class Router {
|
|||
}
|
||||
|
||||
// Check if method exists or if there is a caller function
|
||||
if(method_exists(self::$callable, $function) || method_exists(self::$callable, '__call')){
|
||||
|
||||
if (method_exists(self::$callable, $function) || method_exists(self::$callable, '__call')) {
|
||||
// Execute the function on the controller
|
||||
echo self::$callable->{$function}($parameters);
|
||||
}else{
|
||||
|
||||
} else {
|
||||
// Function could not be found
|
||||
Logger::log('Could not find function '.$function.' on controller '.$class);
|
||||
Logger::http_error(404);
|
||||
}
|
||||
}else{
|
||||
|
||||
} else {
|
||||
// Controller could not be found
|
||||
Logger::log('Could not find controller '.$class);
|
||||
Logger::http_error(404);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,58 +20,62 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
use \FuzeWorks\Module;
|
||||
|
||||
use FuzeWorks\Module;
|
||||
|
||||
/**
|
||||
* Admin Module
|
||||
* Admin Module.
|
||||
*
|
||||
* Admin panel module controller
|
||||
* @package net.techfuze.fuzeworks.admin
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Main {
|
||||
class Main
|
||||
{
|
||||
use Module;
|
||||
|
||||
/**
|
||||
* Loads the module and registers the events
|
||||
*
|
||||
* @access public
|
||||
* Loads the module and registers the events.
|
||||
*/
|
||||
public function onLoad() {
|
||||
require_once(self::getModulePath() . "/classes/class.layout_manager.php");
|
||||
require_once(self::getModulePath() . "/classes/class.admin_exception.php");
|
||||
require_once(self::getModulePath() . "/classes/class.theme_manager.php");
|
||||
require_once(self::getModulePath() . "/classes/class.advertise_fetcher.php");
|
||||
require_once(self::getModulePath() . "/classes/class.page_loader.php");
|
||||
require_once(self::getModulePath() . "/classes/class.page_data.php");
|
||||
require_once(self::getModulePath() . "/classes/class.page.php");
|
||||
require_once(self::getModulePath() . "/classes/class.page_list.php");
|
||||
require_once(self::getModulePath() . "/classes/class.page_router_interface.php");
|
||||
require_once(self::getModulePath() . "/classes/class.page_interface.php");
|
||||
require_once(self::getModulePath() . "/classes/class.admin_router.php");
|
||||
public function onLoad()
|
||||
{
|
||||
include_once self::getModulePath().'/classes/class.layout_manager.php';
|
||||
include_once self::getModulePath().'/classes/class.admin_exception.php';
|
||||
include_once self::getModulePath().'/classes/class.theme_manager.php';
|
||||
include_once self::getModulePath().'/classes/class.advertise_fetcher.php';
|
||||
include_once self::getModulePath().'/classes/class.page_loader.php';
|
||||
include_once self::getModulePath().'/classes/class.page_data.php';
|
||||
include_once self::getModulePath().'/classes/class.page.php';
|
||||
include_once self::getModulePath().'/classes/class.page_list.php';
|
||||
include_once self::getModulePath().'/classes/class.page_router_interface.php';
|
||||
include_once self::getModulePath().'/classes/class.page_interface.php';
|
||||
include_once self::getModulePath().'/classes/class.admin_router.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called when the path matches the regex of this module.
|
||||
* @access public
|
||||
*
|
||||
* @param array Regex matches
|
||||
* @return void
|
||||
*/
|
||||
public function route($matches = array()) {
|
||||
public function route($matches = array())
|
||||
{
|
||||
// First create a pageList based on the advertisements
|
||||
$advertisements = self::getAdvertisements('admin');
|
||||
if (!is_array($advertisements))
|
||||
throw new AdminException("Could not load advertised modules. Malformed object retrieved", 1);
|
||||
if (!is_array($advertisements)) {
|
||||
throw new AdminException('Could not load advertised modules. Malformed object retrieved', 1);
|
||||
}
|
||||
|
||||
$pageList = AdvertiseFetcher::getPageList($advertisements);
|
||||
|
||||
|
@ -87,10 +91,8 @@ class Main {
|
|||
echo $html;
|
||||
}
|
||||
|
||||
public function getAdminRouter() {
|
||||
public function getAdminRouter()
|
||||
{
|
||||
return new AdminRouter();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,22 +20,24 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
|
||||
/**
|
||||
* Class Exception
|
||||
* @package net.techfuze.fuzeworks.admin
|
||||
* Class Exception.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class AdminException extends \Exception{}
|
||||
|
||||
?>
|
||||
class AdminException extends \Exception
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,37 +20,39 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
|
||||
class AdminRouter implements PageRouterInterface {
|
||||
|
||||
class AdminRouter implements PageRouterInterface
|
||||
{
|
||||
private $pageObject;
|
||||
|
||||
public function route() {
|
||||
public function route()
|
||||
{
|
||||
//echo $pagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import the page object from the Admin Module
|
||||
* Import the page object from the Admin Module.
|
||||
*
|
||||
* @param Page $pageObject Page object
|
||||
* @return void
|
||||
*/
|
||||
public function importPage($pageObject) {
|
||||
public function importPage($pageObject)
|
||||
{
|
||||
$this->pageObject = $pageObject;
|
||||
}
|
||||
|
||||
public function getPage() {
|
||||
public function getPage()
|
||||
{
|
||||
return $this->pageObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,27 +20,35 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
use \FuzeWorks\Logger;
|
||||
|
||||
class AdvertiseFetcher {
|
||||
use FuzeWorks\Logger;
|
||||
|
||||
class AdvertiseFetcher
|
||||
{
|
||||
/**
|
||||
* Create a pageList using the advertisements from the admin module
|
||||
* Create a pageList using the advertisements from the admin module.
|
||||
*
|
||||
* @param array $advertisements The advertisement repository
|
||||
*
|
||||
* @throws AdminException On fatal and/or missing data
|
||||
*
|
||||
* @return PageList An object oriented page list with details
|
||||
*
|
||||
* @todo Implement Unit Test
|
||||
*/
|
||||
public static function getPageList($advertisements) {
|
||||
public static function getPageList($advertisements)
|
||||
{
|
||||
// Prepare a pageList
|
||||
Logger::newLevel('Generating PageList');
|
||||
$pageList = new PageList();
|
||||
|
@ -52,8 +60,9 @@ class AdvertiseFetcher {
|
|||
$pages = (isset($data['pages']) ? $data['pages'] : null);
|
||||
|
||||
// Check if everything is set, if not shout out in terror
|
||||
if (is_null($identifier) || is_null($pages))
|
||||
if (is_null($identifier) || is_null($pages)) {
|
||||
throw new AdminException("Incomplete data for module '".$module."'", 1);
|
||||
}
|
||||
|
||||
// And then the pages
|
||||
foreach ($pages as $pageData) {
|
||||
|
@ -67,21 +76,20 @@ class AdvertiseFetcher {
|
|||
$name = (isset($pageData['name']) ? $pageData['name'] : null);
|
||||
|
||||
// And throw errors if non-existent
|
||||
if (is_null($page_path) || is_null($name))
|
||||
if (is_null($page_path) || is_null($name)) {
|
||||
throw new AdminException("Incomplete data for module '".$module."'", 1);
|
||||
}
|
||||
|
||||
// And set those values
|
||||
$page->setPagePath($page_path);
|
||||
$page->setName($name);
|
||||
$unique_identifier = $identifier . "/" . $page_path;
|
||||
$unique_identifier = $identifier.'/'.$page_path;
|
||||
Logger::log("Adding page '".$name."' on '".$unique_identifier."'");
|
||||
|
||||
|
||||
|
||||
// And at last for the optional values
|
||||
$page->setIcon( (isset($pageData['icon']) ? $pageData['icon'] : '') );
|
||||
$page->setPermissionGroups( (isset($pageData['permissionGroups']) ? $pageData['permissionGroups'] : array()) );
|
||||
$page->setPriority( (isset($pageData['priority']) ? $pageData['priority'] : 1) );
|
||||
$page->setIcon((isset($pageData['icon']) ? $pageData['icon'] : ''));
|
||||
$page->setPermissionGroups((isset($pageData['permissionGroups']) ? $pageData['permissionGroups'] : array()));
|
||||
$page->setPriority((isset($pageData['priority']) ? $pageData['priority'] : 1));
|
||||
|
||||
// And finally add the page
|
||||
$pageList->addPage($page, $unique_identifier);
|
||||
|
@ -90,8 +98,7 @@ class AdvertiseFetcher {
|
|||
|
||||
// And finally return the pageList\
|
||||
Logger::stopLevel();
|
||||
|
||||
return $pageList;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,32 +20,39 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
use \FuzeWorks\Layout;
|
||||
use \FuzeWorks\Config;
|
||||
|
||||
class LayoutManager {
|
||||
use FuzeWorks\Layout;
|
||||
use FuzeWorks\Config;
|
||||
|
||||
class LayoutManager
|
||||
{
|
||||
private static $pageList;
|
||||
private static $matches;
|
||||
|
||||
/**
|
||||
* Load the panel of this admin interface
|
||||
* Load the panel of this admin interface.
|
||||
*
|
||||
* @throws AdminException
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public static function loadPanel() {
|
||||
public static function loadPanel()
|
||||
{
|
||||
// First check if the pageList is set and valid
|
||||
if (is_null(self::$pageList))
|
||||
throw new AdminException("Can not load panel. PageList is not set", 1);
|
||||
if (is_null(self::$pageList)) {
|
||||
throw new AdminException('Can not load panel. PageList is not set', 1);
|
||||
}
|
||||
|
||||
// Load the theme
|
||||
ThemeManager::loadTheme();
|
||||
|
@ -72,40 +79,43 @@ class LayoutManager {
|
|||
return Layout::get('panel');
|
||||
}
|
||||
|
||||
public static function loadPanelAPI() {
|
||||
|
||||
public static function loadPanelAPI()
|
||||
{
|
||||
}
|
||||
|
||||
public static function loadLogin() {
|
||||
|
||||
public static function loadLogin()
|
||||
{
|
||||
}
|
||||
|
||||
public static function loadLoginAPI() {
|
||||
|
||||
public static function loadLoginAPI()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the pageList
|
||||
* Set the pageList.
|
||||
*
|
||||
* @param PageList $pageList PageList
|
||||
*/
|
||||
public static function setPageList($pageList) {
|
||||
public static function setPageList($pageList)
|
||||
{
|
||||
self::$pageList = $pageList;
|
||||
}
|
||||
|
||||
public static function setMatches($matches) {
|
||||
public static function setMatches($matches)
|
||||
{
|
||||
self::$matches = $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the basic variables required for every template
|
||||
* Get all the basic variables required for every template.
|
||||
*
|
||||
* @return array with settings
|
||||
*/
|
||||
private static function getVariables() {
|
||||
private static function getVariables()
|
||||
{
|
||||
$vars = array();
|
||||
$vars['adminURL'] = Config::get('main')->SITE_URL . "admin/";
|
||||
$vars['adminURL'] = Config::get('main')->SITE_URL.'admin/';
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,18 +20,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
|
||||
class Page {
|
||||
|
||||
class Page
|
||||
{
|
||||
private $pagePath;
|
||||
private $subPath = array();
|
||||
private $html;
|
||||
|
@ -158,5 +160,3 @@ class Page {
|
|||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,18 +20,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
|
||||
class PageData {
|
||||
|
||||
class PageData
|
||||
{
|
||||
public $module;
|
||||
public $identifier;
|
||||
public $page_path;
|
||||
|
@ -208,5 +210,3 @@ class PageData {
|
|||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,18 +20,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
|
||||
class PageList {
|
||||
|
||||
class PageList
|
||||
{
|
||||
public $pages = array();
|
||||
|
||||
/**
|
||||
|
@ -45,23 +47,24 @@ class PageList {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve a page
|
||||
* Retrieve a page.
|
||||
*
|
||||
* @param string $unique_identifier Unique name for the page
|
||||
*
|
||||
* @return PageData PageData Object
|
||||
*/
|
||||
public function getPage($unique_identifier) {
|
||||
public function getPage($unique_identifier)
|
||||
{
|
||||
return $this->pages[$unique_identifier];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a page to the array
|
||||
* @param PageData $page PageData Object
|
||||
* Add a page to the array.
|
||||
*
|
||||
* @return void
|
||||
* @param PageData $page PageData Object
|
||||
*/
|
||||
public function addPage($page, $unique_identifier) {
|
||||
public function addPage($page, $unique_identifier)
|
||||
{
|
||||
$this->pages[$unique_identifier] = $page;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,21 +20,24 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
use \FuzeWorks\Logger;
|
||||
use \FuzeWorks\Layout;
|
||||
use \FuzeWorks\Modules;
|
||||
|
||||
class PageLoader {
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\Layout;
|
||||
use FuzeWorks\Modules;
|
||||
|
||||
class PageLoader
|
||||
{
|
||||
private static $pageList;
|
||||
private static $activePage;
|
||||
private static $html;
|
||||
|
@ -42,29 +45,34 @@ class PageLoader {
|
|||
private static $title;
|
||||
|
||||
/**
|
||||
* Set the pageList
|
||||
* Set the pageList.
|
||||
*
|
||||
* @param PageList $pageList PageList
|
||||
*/
|
||||
public static function setPageList($pageList) {
|
||||
public static function setPageList($pageList)
|
||||
{
|
||||
self::$pageList = $pageList;
|
||||
}
|
||||
|
||||
public static function loadPage($matches) {
|
||||
public static function loadPage($matches)
|
||||
{
|
||||
// First check if any data is given at all
|
||||
Logger::newLevel("Retrieving page from module");
|
||||
Logger::newLevel('Retrieving page from module');
|
||||
if (!isset($matches['identifier']) && !isset($matches['page'])) {
|
||||
// If nothing is provided, load the dashboard
|
||||
Logger::log("No input retrieved. Loading dashboard");
|
||||
Logger::log('No input retrieved. Loading dashboard');
|
||||
|
||||
return self::dashboard();
|
||||
} elseif (!isset($matches['identifier']) || !isset($matches['page'])) {
|
||||
// If incomplete data is provided, load a 404
|
||||
Logger::log("Invalid input retrieved. Loading 404 not found page");
|
||||
Logger::log('Invalid input retrieved. Loading 404 not found page');
|
||||
|
||||
return self::error404();
|
||||
}
|
||||
|
||||
// If enough data is provided, try and load a page
|
||||
Logger::log("Input received. Attempting to find page");
|
||||
$unique_identifier = $matches['identifier'] . '/' . $matches['page'];
|
||||
Logger::log('Input received. Attempting to find page');
|
||||
$unique_identifier = $matches['identifier'].'/'.$matches['page'];
|
||||
if (isset(self::$pageList->pages[$unique_identifier])) {
|
||||
// Page found, start loading process
|
||||
$page = self::$pageList->getPage($unique_identifier);
|
||||
|
@ -79,16 +87,17 @@ class PageLoader {
|
|||
// Then check if the router is valid, if not, return 500
|
||||
if (!$router instanceof PageRouterInterface) {
|
||||
Logger::logError("Could not load '".$unique_identifier."' on module '".$page->getModule()."'. ".get_class($router)." does not implement \Module\Admin\PageRouterInterface");
|
||||
|
||||
return self::error500();
|
||||
}
|
||||
|
||||
// Route the request into the module
|
||||
Logger::log("Input valid and module loaded. Attempting to route request");
|
||||
Logger::log('Input valid and module loaded. Attempting to route request');
|
||||
|
||||
// Generating page object
|
||||
$pageObject = new Page();
|
||||
$pageObject->setPagePath($matches['page']);
|
||||
$pageObject->setSubPath( (isset($matches['subdata']) ? $matches['subdata'] : null) );
|
||||
$pageObject->setSubPath((isset($matches['subdata']) ? $matches['subdata'] : null));
|
||||
|
||||
// And send it
|
||||
$router->importPage($pageObject);
|
||||
|
@ -102,43 +111,48 @@ class PageLoader {
|
|||
// $html = $pageObject->getHtml();
|
||||
|
||||
Logger::stopLevel();
|
||||
|
||||
return '';
|
||||
} else {
|
||||
// Error, router does not exist
|
||||
Logger::logError("Could not load '".$unique_identifier."' on module '".$page->getModule()."'. ".get_class($module)." does not implement method getAdminRouter()");
|
||||
Logger::logError("Could not load '".$unique_identifier."' on module '".$page->getModule()."'. ".get_class($module).' does not implement method getAdminRouter()');
|
||||
Logger::stopLevel();
|
||||
|
||||
return self::error500();
|
||||
}
|
||||
}
|
||||
|
||||
Logger::log("Matching page was not found. Loading 404 not found page");
|
||||
Logger::log('Matching page was not found. Loading 404 not found page');
|
||||
Logger::stopLevel();
|
||||
|
||||
return self::error404();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function getHtml() {
|
||||
public static function getHtml()
|
||||
{
|
||||
return self::$html;
|
||||
}
|
||||
|
||||
public static function getActivePage() {
|
||||
public static function getActivePage()
|
||||
{
|
||||
return 'fuzeadmin/testPage';
|
||||
}
|
||||
|
||||
public static function dashboard() {
|
||||
|
||||
public static function dashboard()
|
||||
{
|
||||
}
|
||||
|
||||
public static function error404() {
|
||||
public static function error404()
|
||||
{
|
||||
Logger::http_error(404, false);
|
||||
|
||||
return Layout::get('404');
|
||||
}
|
||||
|
||||
public static function error500() {
|
||||
public static function error500()
|
||||
{
|
||||
Logger::http_error(500, false);
|
||||
|
||||
return Layout::get('500');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,21 +20,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
|
||||
interface PageRouterInterface {
|
||||
|
||||
interface PageRouterInterface
|
||||
{
|
||||
public function importPage($pageObject);
|
||||
public function getPage();
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,35 +20,37 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Admin;
|
||||
use \FuzeWorks\Layout;
|
||||
use \FuzeWorks\Logger;
|
||||
|
||||
class ThemeManager {
|
||||
use FuzeWorks\Layout;
|
||||
|
||||
class ThemeManager
|
||||
{
|
||||
private static $themeDir = 'views/adminlte2.1/';
|
||||
|
||||
public static function loadTheme($theme = null) {
|
||||
self::$themeDir = Main::getModulePath() . 'themes/adminlte2.1/';
|
||||
public static function loadTheme($theme = null)
|
||||
{
|
||||
self::$themeDir = Main::getModulePath().'themes/adminlte2.1/';
|
||||
Layout::setDirectory(self::$themeDir);
|
||||
}
|
||||
|
||||
public static function getDirectory() {
|
||||
public static function getDirectory()
|
||||
{
|
||||
// First check if the theme is actually loaded
|
||||
if (empty(self::$themeDir))
|
||||
throw new AdminException("Could not load panel. Theme not loaded", 1);
|
||||
if (empty(self::$themeDir)) {
|
||||
throw new AdminException('Could not load panel. Theme not loaded', 1);
|
||||
}
|
||||
// And then return the theme Directory
|
||||
return self::$themeDir;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,11 +20,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
|
@ -38,7 +40,7 @@ return array(
|
|||
'dependencies' => array(),
|
||||
'events' => array(),
|
||||
'routes' => array('/^admin(|\/(?P<identifier>.*?)(|\/(?<page>.*?)(|\/(?P<subdata>.*?))))$/'),
|
||||
'advertise' => array('admin' => array( 'identifier' => 'fuzeadmin', 'pages' => array( array( 'name' => 'TEST', 'page_path' => 'testPage', 'icon' => 'fa-plane')) )),
|
||||
'advertise' => array('admin' => array('identifier' => 'fuzeadmin', 'pages' => array(array('name' => 'TEST', 'page_path' => 'testPage', 'icon' => 'fa-plane')))),
|
||||
'listenFor' => array('admin'),
|
||||
'name' => 'FuzeWorks Admin Panel',
|
||||
'description' => 'Control Panel for FuzeWorks Modules and FrameWork',
|
||||
|
@ -47,5 +49,5 @@ return array(
|
|||
'website' => 'http://fuzeworks.techfuze.net/',
|
||||
'date_created' => '13-01-2016',
|
||||
'date_updated' => '17-01-2016',
|
||||
'enabled' => true
|
||||
'enabled' => true,
|
||||
);
|
||||
|
|
|
@ -7,18 +7,18 @@
|
|||
<!-- Tell the browser to be responsive to screen width -->
|
||||
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
|
||||
<!-- Bootstrap 3.3.5 -->
|
||||
<link rel="stylesheet" href="<?php echo($vars['viewDir']); ?>/assets/bootstrap/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo $vars['viewDir']; ?>/assets/bootstrap/css/bootstrap.min.css">
|
||||
<!-- Font Awesome -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
|
||||
<!-- Ionicons -->
|
||||
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
|
||||
<!-- Theme style -->
|
||||
<link rel="stylesheet" href="<?php echo($vars['viewDir']); ?>/assets/dist/css/AdminLTE.min.css">
|
||||
<link rel="stylesheet" href="<?php echo $vars['viewDir']; ?>/assets/dist/css/AdminLTE.min.css">
|
||||
<!-- AdminLTE Skins. We have chosen the skin-blue for this starter
|
||||
page. However, you can choose any other skin. Make sure you
|
||||
apply the skin class to the body tag so the changes take effect.
|
||||
-->
|
||||
<link rel="stylesheet" href="<?php echo($vars['viewDir']); ?>/assets/dist/css/skins/skin-blue.min.css">
|
||||
<link rel="stylesheet" href="<?php echo $vars['viewDir']; ?>/assets/dist/css/skins/skin-blue.min.css">
|
||||
|
||||
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||
|
@ -131,7 +131,7 @@
|
|||
<!-- Sidebar Menu -->
|
||||
<ul class="sidebar-menu">
|
||||
<li class="header">Navigate</li>
|
||||
<?php include('view.sidebar.php'); ?>
|
||||
<?php require 'view.sidebar.php'; ?>
|
||||
</ul><!-- /.sidebar-menu -->
|
||||
</section>
|
||||
<!-- /.sidebar -->
|
||||
|
@ -153,7 +153,7 @@
|
|||
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<?php echo($vars['pageHTML']); ?>
|
||||
<?php echo $vars['pageHTML']; ?>
|
||||
<!-- Your Page Content Here -->
|
||||
|
||||
</section><!-- /.content -->
|
||||
|
@ -236,14 +236,14 @@
|
|||
<!-- REQUIRED JS SCRIPTS -->
|
||||
|
||||
<!-- jQuery 2.1.4 -->
|
||||
<script src="<?php echo($vars['viewDir']); ?>/assets/plugins/jQuery/jQuery-2.1.4.min.js"></script>
|
||||
<script src="<?php echo $vars['viewDir']; ?>/assets/plugins/jQuery/jQuery-2.1.4.min.js"></script>
|
||||
<!-- Bootstrap 3.3.5 -->
|
||||
<script src="<?php echo($vars['viewDir']); ?>/assets/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script src="<?php echo $vars['viewDir']; ?>/assets/bootstrap/js/bootstrap.min.js"></script>
|
||||
<!-- AdminLTE App -->
|
||||
<script src="<?php echo($vars['viewDir']); ?>/assets/dist/js/app.min.js"></script>
|
||||
<script src="<?php echo $vars['viewDir']; ?>/assets/dist/js/app.min.js"></script>
|
||||
|
||||
<!-- SlimScroll -->
|
||||
<script src="<?php echo($vars['viewDir']); ?>/assets/plugins/slimScroll/jquery.slimscroll.min.js"></script>
|
||||
<script src="<?php echo $vars['viewDir']; ?>/assets/plugins/slimScroll/jquery.slimscroll.min.js"></script>
|
||||
|
||||
<!-- Optionally, you can add Slimscroll and FastClick plugins.
|
||||
Both of these plugins are recommended to enhance the
|
||||
|
|
|
@ -4,10 +4,7 @@
|
|||
$pageList = $vars['pageList'];
|
||||
|
||||
// The cycle through all and print the sidebar links
|
||||
foreach ($pageList->getPages() as $page) {
|
||||
echo("<li name='sidebar:".$page->getIdentifier()."/".$page->getPagePath()."'><a href='".$vars['adminURL']. $page->getIdentifier()."/".$page->getPagePath()."'>
|
||||
<i class='".($page->getIcon() == '' ? '' : 'fa ' . $page->getIcon())."'></i> <span>".$page->getName()."</span></a></li>");
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
foreach ($pageList->getPages() as $page) {
|
||||
echo "<li name='sidebar:".$page->getIdentifier().'/'.$page->getPagePath()."'><a href='".$vars['adminURL'].$page->getIdentifier().'/'.$page->getPagePath()."'>
|
||||
<i class='".($page->getIcon() == '' ? '' : 'fa '.$page->getIcon())."'></i> <span>".$page->getName().'</span></a></li>';
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,33 +20,38 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Api;
|
||||
use \FuzeWorks\Module;
|
||||
|
||||
use FuzeWorks\Module;
|
||||
|
||||
/**
|
||||
* Loading class for multiple API types
|
||||
* Loading class for multiple API types.
|
||||
*
|
||||
* Currently loads a REST API class which controllers can extend so they provide a standardized API
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Main {
|
||||
class Main
|
||||
{
|
||||
use Module;
|
||||
/**
|
||||
* Gets loaded upon module initialization
|
||||
* Gets loaded upon module initialization.
|
||||
*
|
||||
* Loads all the API types
|
||||
*/
|
||||
public function onLoad() {
|
||||
require_once(self::getModulePath() . "/class.rest.php");
|
||||
public function onLoad()
|
||||
{
|
||||
include_once self::getModulePath().'/class.rest.php';
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,72 +20,75 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Api;
|
||||
use \FuzeWorks\Module;
|
||||
use \FuzeWorks\Layout;
|
||||
|
||||
use FuzeWorks\Layout;
|
||||
|
||||
/**
|
||||
* RestAPI class for creating API's out of modules or contrllers
|
||||
* RestAPI class for creating API's out of modules or contrllers.
|
||||
*
|
||||
* Extend a Controller with this class, and be sure to return the data from methods of your controller.
|
||||
* This data will be parsed by this class and returned as valid JSON data.
|
||||
* The necessity of API keys can be configured in the controller by settings $this->requireApiKey = false;
|
||||
* @package net.techfuze.fuzeworks.core
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
abstract class RestAPI
|
||||
{
|
||||
/**
|
||||
* Property: method
|
||||
* The HTTP method this request was made in, either GET, POST, PUT or DELETE
|
||||
* The HTTP method this request was made in, either GET, POST, PUT or DELETE.
|
||||
*/
|
||||
protected $method = '';
|
||||
/**
|
||||
* Property: endpoint
|
||||
* The Model requested in the URI. eg: /files
|
||||
* The Model requested in the URI. eg: /files.
|
||||
*/
|
||||
protected $endpoint = '';
|
||||
/**
|
||||
* Property: verb
|
||||
* An optional additional descriptor about the endpoint, used for things that can
|
||||
* not be handled by the basic methods. eg: /files/process
|
||||
* not be handled by the basic methods. eg: /files/process.
|
||||
*/
|
||||
protected $verb = '';
|
||||
/**
|
||||
* Property: args
|
||||
* Any additional URI components after the endpoint and verb have been removed, in our
|
||||
* case, an integer ID for the resource. eg: /<endpoint>/<verb>/<arg0>/<arg1>
|
||||
* or /<endpoint>/<arg0>
|
||||
* or /<endpoint>/<arg0>.
|
||||
*/
|
||||
protected $args = Array();
|
||||
protected $args = array();
|
||||
/**
|
||||
* Property: file
|
||||
* Stores the input of the PUT request
|
||||
* Stores the input of the PUT request.
|
||||
*/
|
||||
protected $file = Null;
|
||||
protected $file = null;
|
||||
|
||||
/**
|
||||
* Whether API authentication is needed before interacting with the API
|
||||
* Whether API authentication is needed before interacting with the API.
|
||||
*/
|
||||
protected $requireApiKey = true;
|
||||
|
||||
/**
|
||||
* Constructor: __construct
|
||||
* Allow for CORS, assemble and pre-process the data
|
||||
* Allow for CORS, assemble and pre-process the data.
|
||||
*/
|
||||
public function __construct($request) {
|
||||
header("Access-Control-Allow-Orgin: *");
|
||||
header("Access-Control-Allow-Methods: *");
|
||||
header("Content-Type: application/json");
|
||||
public function __construct($request)
|
||||
{
|
||||
header('Access-Control-Allow-Orgin: *');
|
||||
header('Access-Control-Allow-Methods: *');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// Return layout data as string
|
||||
Layout::setEngine('JSON');
|
||||
|
@ -101,14 +104,14 @@ abstract class RestAPI
|
|||
if ($this->method == 'POST' && array_key_exists('HTTP_X_HTTP_METHOD', $_SERVER)) {
|
||||
if ($_SERVER['HTTP_X_HTTP_METHOD'] == 'DELETE') {
|
||||
$this->method = 'DELETE';
|
||||
} else if ($_SERVER['HTTP_X_HTTP_METHOD'] == 'PUT') {
|
||||
} elseif ($_SERVER['HTTP_X_HTTP_METHOD'] == 'PUT') {
|
||||
$this->method = 'PUT';
|
||||
} else {
|
||||
throw new Exception("Unexpected Header");
|
||||
throw new Exception('Unexpected Header');
|
||||
}
|
||||
}
|
||||
|
||||
switch($this->method) {
|
||||
switch ($this->method) {
|
||||
case 'DELETE':
|
||||
case 'POST':
|
||||
$this->request = $this->_cleanInputs($_POST);
|
||||
|
@ -118,7 +121,7 @@ abstract class RestAPI
|
|||
break;
|
||||
case 'PUT':
|
||||
$this->request = $this->_cleanInputs($_GET);
|
||||
$this->file = file_get_contents("php://input");
|
||||
$this->file = file_get_contents('php://input');
|
||||
break;
|
||||
default:
|
||||
$this->_response('Invalid Method', 405);
|
||||
|
@ -134,23 +137,29 @@ abstract class RestAPI
|
|||
}
|
||||
|
||||
/**
|
||||
* Process an API request when retrieving
|
||||
* @return String JSON encoded response
|
||||
* Process an API request when retrieving.
|
||||
*
|
||||
* @return string JSON encoded response
|
||||
*/
|
||||
public function processAPI() {
|
||||
public function processAPI()
|
||||
{
|
||||
if (method_exists($this, $this->endpoint)) {
|
||||
return $this->_response($this->{$this->endpoint}($this->args));
|
||||
}
|
||||
|
||||
return $this->_response("No Endpoint: $this->endpoint", 404);
|
||||
}
|
||||
|
||||
private function _response($data, $status = 200) {
|
||||
header("HTTP/1.1 " . $status . " " . $this->_requestStatus($status));
|
||||
private function _response($data, $status = 200)
|
||||
{
|
||||
header('HTTP/1.1 '.$status.' '.$this->_requestStatus($status));
|
||||
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
private function _cleanInputs($data) {
|
||||
$clean_input = Array();
|
||||
private function _cleanInputs($data)
|
||||
{
|
||||
$clean_input = array();
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $k => $v) {
|
||||
$clean_input[$k] = $this->_cleanInputs($v);
|
||||
|
@ -158,16 +167,19 @@ abstract class RestAPI
|
|||
} else {
|
||||
$clean_input = trim(strip_tags($data));
|
||||
}
|
||||
|
||||
return $clean_input;
|
||||
}
|
||||
|
||||
private function _requestStatus($code) {
|
||||
private function _requestStatus($code)
|
||||
{
|
||||
$status = array(
|
||||
200 => 'OK',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
500 => 'Internal Server Error',
|
||||
);
|
||||
return ($status[$code])?$status[$code]:$status[500];
|
||||
|
||||
return ($status[$code]) ? $status[$code] : $status[500];
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,11 +20,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,54 +20,59 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Database;
|
||||
use \FuzeWorks\Module;
|
||||
use \FuzeWorks\Config;
|
||||
use \FuzeWorks\Logger;
|
||||
use \FuzeWorks\Events;
|
||||
use \FuzeWorks\EventPriority;
|
||||
use \PDO;
|
||||
use \FuzeWorks\DatabaseException;
|
||||
|
||||
use FuzeWorks\Module;
|
||||
use FuzeWorks\Config;
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\Events;
|
||||
use FuzeWorks\EventPriority;
|
||||
use PDO;
|
||||
use FuzeWorks\DatabaseException;
|
||||
|
||||
/**
|
||||
* Database Class
|
||||
* Database Class.
|
||||
*
|
||||
* This class is a wrapper for PDO.
|
||||
*
|
||||
* @package net.techfuze.fuzeworks.database
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Main {
|
||||
class Main
|
||||
{
|
||||
use Module;
|
||||
|
||||
/**
|
||||
* The default database connection
|
||||
* @access private
|
||||
* The default database connection.
|
||||
*
|
||||
* @var PDO Class
|
||||
*/
|
||||
private $DBH;
|
||||
public $prefix;
|
||||
|
||||
public function onLoad() {
|
||||
public function onLoad()
|
||||
{
|
||||
Config::$dbActive = true;
|
||||
Events::addListener(array($this, 'shutdown'), 'coreShutdownEvent', EventPriority::NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to a database
|
||||
* @access public
|
||||
* Connect to a database.
|
||||
*
|
||||
* @param StdObject Config, like the database config in Application/Config
|
||||
*/
|
||||
public function connect($config = null) {
|
||||
public function connect($config = null)
|
||||
{
|
||||
// If nothing is given, connect to database from the main config, otherwise use the served configuration
|
||||
if (is_null($config)) {
|
||||
$db = Config::get('database');
|
||||
|
@ -82,8 +87,8 @@ class Main {
|
|||
// Get the DSN for popular types of databases or a custom DSN
|
||||
switch (strtolower($db->type)) {
|
||||
case 'mysql':
|
||||
$dsn = "mysql:host=".$db->host.";";
|
||||
$dsn .= (!empty($db->database) ? "dbname=".$db->database.";" : "");
|
||||
$dsn = 'mysql:host='.$db->host.';';
|
||||
$dsn .= (!empty($db->database) ? 'dbname='.$db->database.';' : '');
|
||||
break;
|
||||
case 'custom':
|
||||
$dsn = $db->dsn;
|
||||
|
@ -91,58 +96,67 @@ class Main {
|
|||
}
|
||||
|
||||
try {
|
||||
Logger::logInfo("Connecting to '".$dsn."'", "Database");
|
||||
Logger::logInfo("Connecting to '".$dsn."'", 'Database');
|
||||
// And create the connection
|
||||
$this->DBH = new PDO($dsn, $db->username, $db->password, (isset($db->options) ? $db->options : null));
|
||||
$this->DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
Logger::logInfo("Connected to database", "Database");
|
||||
Logger::logInfo('Connected to database', 'Database');
|
||||
|
||||
// And set the prefix
|
||||
$this->prefix = $db->prefix;
|
||||
} catch (Exception $e) {
|
||||
throw (new DatabaseException('Could not connect to the database: "'. $e->getMessage() . '"'));
|
||||
throw (new DatabaseException('Could not connect to the database: "'.$e->getMessage().'"'));
|
||||
}
|
||||
}
|
||||
|
||||
public function shutdown() {
|
||||
Logger::log("Closing open database connections");
|
||||
public function shutdown()
|
||||
{
|
||||
Logger::log('Closing open database connections');
|
||||
$this->DBH = null;
|
||||
}
|
||||
|
||||
public function getPrefix() {
|
||||
public function getPrefix()
|
||||
{
|
||||
if (!$this->is_active()) {
|
||||
$this->connect();
|
||||
}
|
||||
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
public function is_active() {
|
||||
if($this->DBH === null){
|
||||
public function is_active()
|
||||
{
|
||||
if ($this->DBH === null) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function __call($name, $params) {
|
||||
public function __call($name, $params)
|
||||
{
|
||||
if ($this->is_active()) {
|
||||
return call_user_func_array(array($this->DBH, $name), $params);
|
||||
} else {
|
||||
$this->connect();
|
||||
|
||||
return call_user_func_array(array($this->DBH, $name), $params);
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
public function __get($name)
|
||||
{
|
||||
if ($this->is_active()) {
|
||||
return $this->DBH->$name;
|
||||
} else {
|
||||
$this->connect();
|
||||
|
||||
return $this->DBH->$name;
|
||||
}
|
||||
}
|
||||
|
||||
public function __set($name, $value) {
|
||||
public function __set($name, $value)
|
||||
{
|
||||
if ($this->is_active()) {
|
||||
$this->DBH->$name = $value;
|
||||
} else {
|
||||
|
@ -151,6 +165,3 @@ class Main {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,11 +20,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,49 +20,53 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
|
||||
namespace Module\DatabaseUtils;
|
||||
use \FuzeWorks\Module;
|
||||
use \FuzeWorks\Modules;
|
||||
use \FuzeWorks\Bus;
|
||||
use \FuzeWorks\ModelServer;
|
||||
use \FuzeWorks\DatabaseException;
|
||||
use \FuzeWorks\Config;
|
||||
use \FuzeWorks\Logger;
|
||||
use \PDOException;
|
||||
|
||||
use FuzeWorks\Module;
|
||||
use FuzeWorks\Modules;
|
||||
use FuzeWorks\ModelServer;
|
||||
use FuzeWorks\DatabaseException;
|
||||
use FuzeWorks\Config;
|
||||
use FuzeWorks\Logger;
|
||||
use PDOException;
|
||||
|
||||
/**
|
||||
* Main class of the database utilities and model providers
|
||||
* @package net.techfuze.fuzeworks.databaseutils
|
||||
* Main class of the database utilities and model providers.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Main implements ModelServer {
|
||||
class Main implements ModelServer
|
||||
{
|
||||
use Module;
|
||||
|
||||
public $fields = array();
|
||||
public $primary = 'id';
|
||||
public $table = '';
|
||||
|
||||
public function onLoad() {
|
||||
require_once(self::getModulePath() . '/class.query.php');
|
||||
public function onLoad()
|
||||
{
|
||||
include_once self::getModulePath().'/class.query.php';
|
||||
}
|
||||
|
||||
public function giveModel($type) {
|
||||
public function giveModel($type)
|
||||
{
|
||||
return new Model();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Model
|
||||
* Class Model.
|
||||
*
|
||||
* Models provide an easy connection to database tables. Each table requires its own model. You don't need to worry about your queries or syntax anymore, because
|
||||
* models will handle queries and error handling. Because of this, you can freely change your database infrastructure without fear of needing to change your
|
||||
|
@ -71,53 +75,50 @@ class Main implements ModelServer {
|
|||
* Models also allow custom methods to be created on them. You can use those methods to create specific operations or joins and then use the newly created method
|
||||
* everywhere in your project. The code is at one place, the usages all over your project. Isn't that great?
|
||||
*
|
||||
* @package net.techfuze.fuzeworks.databaseutils
|
||||
* @author GOScripting
|
||||
* @copyright Copyright (c) 2014 - 2015, GOScripting B.V. (http://goscripting.com)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://goframework.net
|
||||
*/
|
||||
class Model {
|
||||
|
||||
class Model
|
||||
{
|
||||
/**
|
||||
* @var string The name of the database table
|
||||
*/
|
||||
public $table = '';
|
||||
|
||||
/**
|
||||
* Traditional query interface
|
||||
* Traditional query interface.
|
||||
*
|
||||
* @param string $query
|
||||
* @param null $binds
|
||||
*
|
||||
* @return mixed returns fetched rows if available, otherwise returns number of affected rows
|
||||
*
|
||||
* @throws DatabaseException
|
||||
*/
|
||||
public function query($query, $binds = null){
|
||||
|
||||
if(Config::get('database')->debug)
|
||||
Logger::log("Manuel Query: ".$query, "Database Model");
|
||||
|
||||
try{
|
||||
public function query($query, $binds = null)
|
||||
{
|
||||
if (Config::get('database')->debug) {
|
||||
Logger::log('Manuel Query: '.$query, 'Database Model');
|
||||
}
|
||||
|
||||
try {
|
||||
$sth = Modules::get('core/database')->prepare($query);
|
||||
if($binds === null){
|
||||
|
||||
if ($binds === null) {
|
||||
$sth->execute();
|
||||
}else{
|
||||
|
||||
} else {
|
||||
$sth->execute($binds);
|
||||
}
|
||||
}catch (PDOException $e){
|
||||
|
||||
} catch (PDOException $e) {
|
||||
throw new DatabaseException('Could not execute SQL-query due PDO-exception '.$e->getMessage());
|
||||
}
|
||||
|
||||
if($sth->columnCount() > 0){
|
||||
|
||||
if ($sth->columnCount() > 0) {
|
||||
// Fetch results
|
||||
$result = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}else{
|
||||
|
||||
} else {
|
||||
// Fetch number of affected rows
|
||||
$result = $sth->rowCount();
|
||||
}
|
||||
|
@ -126,21 +127,26 @@ class Model {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the table you wish to approach
|
||||
* @param String $table Table name
|
||||
* Set the table you wish to approach.
|
||||
*
|
||||
* @param string $table Table name
|
||||
*/
|
||||
public function setTable($table) {
|
||||
public function setTable($table)
|
||||
{
|
||||
$this->table = $table;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default table will be set to $this->table
|
||||
* The default table will be set to $this->table.
|
||||
*
|
||||
* @see Query::select
|
||||
*
|
||||
* @return Query
|
||||
*/
|
||||
public function select(){
|
||||
|
||||
public function select()
|
||||
{
|
||||
$queryBuilder = new Query();
|
||||
$queryBuilder->setTable($this->table);
|
||||
call_user_func_array(array($queryBuilder, 'select'), func_get_args());
|
||||
|
@ -150,13 +156,14 @@ class Model {
|
|||
}
|
||||
|
||||
/**
|
||||
* The default table will be set to $this->table
|
||||
* The default table will be set to $this->table.
|
||||
*
|
||||
* @see Query::update
|
||||
*
|
||||
* @return Query
|
||||
*/
|
||||
|
||||
public function update(){
|
||||
|
||||
public function update()
|
||||
{
|
||||
$queryBuilder = new Query();
|
||||
$queryBuilder->setTable($this->table);
|
||||
$queryBuilder->update($this->table);
|
||||
|
@ -165,13 +172,14 @@ class Model {
|
|||
}
|
||||
|
||||
/**
|
||||
* The default table will be set to $this->table
|
||||
* The default table will be set to $this->table.
|
||||
*
|
||||
* @see Query::delete
|
||||
*
|
||||
* @return Query
|
||||
*/
|
||||
|
||||
public function delete(){
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$queryBuilder = new Query();
|
||||
$queryBuilder->setTable($this->table);
|
||||
call_user_func_array(array($queryBuilder, 'delete'), func_get_args());
|
||||
|
@ -181,15 +189,18 @@ class Model {
|
|||
}
|
||||
|
||||
/**
|
||||
* The default table will be set to $this->table
|
||||
* The default table will be set to $this->table.
|
||||
*
|
||||
* @see Query::insert
|
||||
*
|
||||
* @param $array Array with values
|
||||
*
|
||||
* @return Query
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public function insert($array){
|
||||
|
||||
public function insert($array)
|
||||
{
|
||||
$queryBuilder = new Query();
|
||||
$queryBuilder->setTable($this->table);
|
||||
call_user_func_array(array($queryBuilder, 'insert'), func_get_args());
|
||||
|
@ -198,15 +209,18 @@ class Model {
|
|||
}
|
||||
|
||||
/**
|
||||
* The default table will be set to $this->table
|
||||
* The default table will be set to $this->table.
|
||||
*
|
||||
* @see Query::replace
|
||||
*
|
||||
* @param $array Array with values
|
||||
*
|
||||
* @return Query
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public function replace($array){
|
||||
|
||||
public function replace($array)
|
||||
{
|
||||
$queryBuilder = new Query();
|
||||
$queryBuilder->setTable($this->table);
|
||||
call_user_func_array(array($queryBuilder, 'replace'), func_get_args());
|
||||
|
@ -215,15 +229,17 @@ class Model {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return latest insert id
|
||||
* Return latest insert id.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLastInsertId(){
|
||||
public function getLastInsertId()
|
||||
{
|
||||
return Modules::get('core/database')->lastInsertId();
|
||||
}
|
||||
|
||||
public function __call($name, $params) {
|
||||
public function __call($name, $params)
|
||||
{
|
||||
return call_user_func_array(array(Modules::get('core/database'), $name), $params);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
return array(
|
||||
|
||||
'module_class' => 'Module\DatabaseUtils\Main',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,61 +20,69 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Example;
|
||||
use \FuzeWorks\Module;
|
||||
use \FuzeWorks\Event;
|
||||
use \FuzeWorks\EventPriority;
|
||||
use \FuzeWorks\Events;
|
||||
use \FuzeWorks\Logger;
|
||||
|
||||
use FuzeWorks\Module;
|
||||
use FuzeWorks\Event;
|
||||
use FuzeWorks\EventPriority;
|
||||
use FuzeWorks\Events;
|
||||
use FuzeWorks\Logger;
|
||||
|
||||
/**
|
||||
* Example module.
|
||||
*
|
||||
* Use this is a reference to create new modules.
|
||||
* @package net.techfuze.fuzeworks.example
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Main {
|
||||
|
||||
class Main
|
||||
{
|
||||
use Module;
|
||||
|
||||
/**
|
||||
* Loads the module and registers the events
|
||||
* Loads the module and registers the events.
|
||||
*
|
||||
* Every main moduleclass needs an onLoad method. This method is called first before anything else and cam be used to do some global actions.
|
||||
* @access public
|
||||
*/
|
||||
public function onLoad() {
|
||||
public function onLoad()
|
||||
{
|
||||
// Here we register an eventListener for the ExampleEvent. See ExampleListener for more info
|
||||
Events::addListener(array($this, 'exampleListener'), 'ExampleEvent', EventPriority::NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method that can be called
|
||||
* @return String Example text
|
||||
* Test method that can be called.
|
||||
*
|
||||
* @return string Example text
|
||||
*/
|
||||
public function test() {
|
||||
return "It works!";
|
||||
public function test()
|
||||
{
|
||||
return 'It works!';
|
||||
}
|
||||
|
||||
/**
|
||||
* An example listener that introduces you to the basics of event handling
|
||||
* An example listener that introduces you to the basics of event handling.
|
||||
*
|
||||
* @param ExampleEvent $event The event to listen for
|
||||
*
|
||||
* @return ExampleEvent The event after it has been handled
|
||||
*/
|
||||
public function exampleListener($event) {
|
||||
Logger::log("Called the eventListener. This listener can now handle the event and change some data");
|
||||
public function exampleListener($event)
|
||||
{
|
||||
Logger::log('Called the eventListener. This listener can now handle the event and change some data');
|
||||
// For this listener, we only change one variable
|
||||
$event->setVariable("New Value");
|
||||
$event->setVariable('New Value');
|
||||
|
||||
// And then we return it
|
||||
return $event;
|
||||
|
@ -83,13 +91,14 @@ class Main {
|
|||
/**
|
||||
* In this example we create a simple event. This event will be created, passed around and then received in the example listener.
|
||||
*/
|
||||
public function createEvent() {
|
||||
public function createEvent()
|
||||
{
|
||||
// First we log some data
|
||||
Logger::log("Now creating a test event.");
|
||||
Logger::log('Now creating a test event.');
|
||||
|
||||
// First we create the event object and some variables to assign to it
|
||||
$eventObject = new ExampleEvent();
|
||||
$variable = "Test Variable";
|
||||
$variable = 'Test Variable';
|
||||
|
||||
// Then we fire the event by parsing the event object and the variables into the fireEvent function.
|
||||
$event = Events::fireEvent($eventObject, $variable);
|
||||
|
@ -103,32 +112,32 @@ class Main {
|
|||
|
||||
/**
|
||||
* Gets called when the path matches the regex of this module.
|
||||
* @access public
|
||||
*
|
||||
* @param array Regex matches
|
||||
* @return void
|
||||
*/
|
||||
public function route($matches = array()) {
|
||||
public function route($matches = array())
|
||||
{
|
||||
// Just print the inputted data:
|
||||
echo "<h3>Input data: ".$matches['data']."</h3>";
|
||||
echo '<h3>Input data: '.$matches['data'].'</h3>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ExampleEvent extends Event {
|
||||
|
||||
class ExampleEvent extends Event
|
||||
{
|
||||
private $var1;
|
||||
|
||||
public function init($variable) {
|
||||
public function init($variable)
|
||||
{
|
||||
$this->var1 = $variable;
|
||||
}
|
||||
|
||||
public function getVariable() {
|
||||
public function getVariable()
|
||||
{
|
||||
return $this->var1;
|
||||
}
|
||||
|
||||
public function setVariable($var) {
|
||||
public function setVariable($var)
|
||||
{
|
||||
$this->var1 = $var;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,11 +20,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
|
@ -85,5 +87,5 @@ return array(
|
|||
'date_updated' => '29-04-2015',
|
||||
|
||||
// whether the module is enabled or not. If it is disabled, it can not be loaded.
|
||||
'enabled' => true
|
||||
'enabled' => true,
|
||||
);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,58 +20,62 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
namespace Module\Mailer;
|
||||
use \FuzeWorks\Module;
|
||||
use \FuzeWorks\ModuleException;
|
||||
use \FuzeWorks\Config;
|
||||
use \FuzeWorks\Logger;
|
||||
use \PHPMailer;
|
||||
|
||||
use FuzeWorks\Module;
|
||||
use FuzeWorks\ModuleException;
|
||||
use FuzeWorks\Config;
|
||||
use PHPMailer;
|
||||
|
||||
/**
|
||||
* Main class for the Mailer module
|
||||
* Main class for the Mailer module.
|
||||
*
|
||||
* This class is a simple wrapper for PHPMailer. It has a simple prepared config file and can create instances based on these config files.
|
||||
* @package net.techfuze.fuzeworks.mailer
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Main {
|
||||
|
||||
class Main
|
||||
{
|
||||
use Module;
|
||||
|
||||
/**
|
||||
* Array of all the active PHPMailer instances
|
||||
* @access private
|
||||
* @var Array of \PHPMailer
|
||||
* Array of all the active PHPMailer instances.
|
||||
*
|
||||
* @var array of \PHPMailer
|
||||
*/
|
||||
private $mailers = array();
|
||||
|
||||
/**
|
||||
* First function to get called. Initiates all module variables
|
||||
* @access public
|
||||
* First function to get called. Initiates all module variables.
|
||||
*/
|
||||
public function onLoad() {
|
||||
public function onLoad()
|
||||
{
|
||||
if (!class_exists('\PHPMailer')) {
|
||||
throw new ModuleException("PHPMailer class not found! Is composer installed?", 1);
|
||||
throw new ModuleException('PHPMailer class not found! Is composer installed?', 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return one of the instances of PHPMailer.
|
||||
* If not found, it creates a new instance and returns that
|
||||
* @access public
|
||||
* @param String instance name
|
||||
* If not found, it creates a new instance and returns that.
|
||||
*
|
||||
* @param string instance name
|
||||
*
|
||||
* @return \PHPMailer instance
|
||||
*/
|
||||
public function __get($name) {
|
||||
public function __get($name)
|
||||
{
|
||||
if (!isset($this->mailers[$name])) {
|
||||
$this->mailers[$name] = new PHPMailer();
|
||||
|
||||
|
@ -102,12 +106,9 @@ use \PHPMailer;
|
|||
} elseif ($cfg->sender_name == '' && $cfg->sender_mail != '') {
|
||||
$mail->From = $cfg->sender_mail;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->mailers[$name];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,36 +20,36 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
return array(
|
||||
|
||||
# Sendmail Settings
|
||||
// Sendmail Settings
|
||||
'sendmail_enabled' => true,
|
||||
|
||||
# SMTP Settings
|
||||
// SMTP Settings
|
||||
'smtp_enabled' => false,
|
||||
'smtp_host' => '',
|
||||
'smtp_port' => 25,
|
||||
'smtp_auth' => false,
|
||||
'smtp_username' => '',
|
||||
'smtp_password' => '',
|
||||
/**
|
||||
/*
|
||||
* 0 = off
|
||||
* 1 = client messages
|
||||
* 2 = client and server messages
|
||||
*/
|
||||
'smtp_debug_level' => 0,
|
||||
|
||||
# Common sender information
|
||||
// Common sender information
|
||||
'sender_name' => '',
|
||||
'sender_mail' => '',
|
||||
);
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,11 +20,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
|
|
17
index.php
17
index.php
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,24 +20,23 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use \FuzeWorks\Core;
|
||||
use \FuzeWorks\Router;
|
||||
use FuzeWorks\Core;
|
||||
use FuzeWorks\Router;
|
||||
|
||||
// Include framework
|
||||
require_once( dirname(__FILE__) . "/Core/System/class.core.php");
|
||||
require_once dirname(__FILE__).'/Core/System/class.core.php';
|
||||
|
||||
// Load it
|
||||
Core::init();
|
||||
|
||||
Router::setPath( (isset($_GET['path']) ? $_GET['path'] : null) );
|
||||
Router::setPath((isset($_GET['path']) ? $_GET['path'] : null));
|
||||
Router::route();
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,31 +20,32 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use FuzeWorks\Events;
|
||||
use FuzeWorks\Layout;
|
||||
|
||||
/**
|
||||
* Class CoreTestAbstract
|
||||
* Class CoreTestAbstract.
|
||||
*
|
||||
* Provides the event tests with some basic functionality
|
||||
*/
|
||||
abstract class CoreTestAbstract extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Remove all listeners before the next test starts
|
||||
* Remove all listeners before the next test starts.
|
||||
*
|
||||
* Reset the layout manager
|
||||
*/
|
||||
public function tearDown(){
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Events::$listeners = array();
|
||||
Layout::reset();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,11 +20,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
// Load the abstract
|
||||
|
@ -32,8 +34,8 @@
|
|||
use \FuzeWorks\Config;
|
||||
use \FuzeWorks\Core;
|
||||
|
||||
require_once "abstract.coreTestAbstract.php";
|
||||
require_once( "Core/System/class.core.php");
|
||||
require_once 'abstract.coreTestAbstract.php';
|
||||
require_once 'Core/System/class.core.php';
|
||||
|
||||
ob_start();
|
||||
Core::init();
|
||||
|
@ -43,5 +45,3 @@ $cfg = Config::get('error');
|
|||
$cfg->debug = false;
|
||||
$cfg->error_reporting = false;
|
||||
$cfg->commit();
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,22 +20,25 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class CoreTest
|
||||
* Class CoreTest.
|
||||
*
|
||||
* Core testing suite, will test basic core functionality
|
||||
*/
|
||||
class CoreTest extends CoreTestAbstract
|
||||
class coreTest extends CoreTestAbstract
|
||||
{
|
||||
public function testCanLoadStartupFiles(){
|
||||
public function testCanLoadStartupFiles()
|
||||
{
|
||||
|
||||
// Assert
|
||||
$this->assertTrue(class_exists('\FuzeWorks\Config'));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,28 +20,26 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use \FuzeWorks\Core;
|
||||
use \FuzeWorks\Layout;
|
||||
use \FuzeWorks\Events;
|
||||
use \FuzeWorks\TemplateEngine\TemplateEngine;
|
||||
|
||||
/**
|
||||
* Class LayoutTest
|
||||
* Class LayoutTest.
|
||||
*
|
||||
* This test will test the layout manager and the default TemplateEngines
|
||||
*/
|
||||
class LayoutTest extends CoreTestAbstract
|
||||
class layoutTest extends CoreTestAbstract
|
||||
{
|
||||
|
||||
public function testGetFileExtensions() {
|
||||
public function testGetFileExtensions()
|
||||
{
|
||||
// Test getting php files
|
||||
$this->assertEquals('php', Layout::getExtensionFromFile('class.test.php'));
|
||||
$this->assertEquals('php', Layout::getExtensionFromFile('class.test.org.php'));
|
||||
|
@ -49,9 +47,11 @@ class LayoutTest extends CoreTestAbstract
|
|||
|
||||
/**
|
||||
* @depends testGetFileExtensions
|
||||
*
|
||||
* @todo Add malformed paths
|
||||
*/
|
||||
public function testGetFilePath(){
|
||||
public function testGetFilePath()
|
||||
{
|
||||
|
||||
// Extensions to be used in this test
|
||||
$extensions = array('php', 'json');
|
||||
|
@ -75,7 +75,8 @@ class LayoutTest extends CoreTestAbstract
|
|||
/**
|
||||
* @expectedException \FuzeWorks\LayoutException
|
||||
*/
|
||||
public function testMissingDirectory() {
|
||||
public function testMissingDirectory()
|
||||
{
|
||||
// Directory that does not exist
|
||||
Layout::setFileFromString('test', 'tests/layout/doesNotExist/', array('php'));
|
||||
}
|
||||
|
@ -83,18 +84,21 @@ class LayoutTest extends CoreTestAbstract
|
|||
/**
|
||||
* @expectedException \FuzeWorks\LayoutException
|
||||
*/
|
||||
public function testMissingFile() {
|
||||
public function testMissingFile()
|
||||
{
|
||||
Layout::setFileFromString('test', 'tests/layout/testMissingFile/', array('php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \FuzeWorks\LayoutException
|
||||
*/
|
||||
public function testUnknownFileExtension() {
|
||||
public function testUnknownFileExtension()
|
||||
{
|
||||
Layout::setFileFromString('test', 'tests/layout/testUnknownFileExtension/', array('php'));
|
||||
}
|
||||
|
||||
public function testGetEngineFromExtension() {
|
||||
public function testGetEngineFromExtension()
|
||||
{
|
||||
Layout::loadTemplateEngines();
|
||||
|
||||
// Test all the default engines
|
||||
|
@ -107,14 +111,16 @@ class LayoutTest extends CoreTestAbstract
|
|||
* @depends testGetEngineFromExtension
|
||||
* @expectedException \FuzeWorks\LayoutException
|
||||
*/
|
||||
public function testGetEngineFromExtensionFail() {
|
||||
public function testGetEngineFromExtensionFail()
|
||||
{
|
||||
Layout::getEngineFromExtension('faulty');
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetEngineFromExtension
|
||||
*/
|
||||
public function testCustomEngine() {
|
||||
public function testCustomEngine()
|
||||
{
|
||||
|
||||
// Create the engine
|
||||
$mock = $this->getMockBuilder('\FuzeWorks\TemplateEngine\TemplateEngine')->getMock();
|
||||
|
@ -132,7 +138,8 @@ class LayoutTest extends CoreTestAbstract
|
|||
$this->assertEquals('output', Layout::get('test', 'tests/layout/testCustomEngine/'));
|
||||
}
|
||||
|
||||
public function testPHPEngine() {
|
||||
public function testPHPEngine()
|
||||
{
|
||||
|
||||
// Directory of these tests
|
||||
$directory = 'tests/layout/testEngines/';
|
||||
|
@ -140,7 +147,8 @@ class LayoutTest extends CoreTestAbstract
|
|||
$this->assertEquals('PHP Template Check', Layout::get('php', $directory));
|
||||
}
|
||||
|
||||
public function testJSONEngine() {
|
||||
public function testJSONEngine()
|
||||
{
|
||||
|
||||
// Directory of these tests
|
||||
$directory = 'tests/layout/testEngines/';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,91 +20,86 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use \FuzeWorks\Core;
|
||||
use \FuzeWorks\Models;
|
||||
|
||||
/**
|
||||
* Class ModelTest
|
||||
* Class ModelTest.
|
||||
*
|
||||
* Core model testing suite, will test basic model functionality
|
||||
*
|
||||
*/
|
||||
class ModelTest extends CoreTestAbstract
|
||||
class modelTest extends CoreTestAbstract
|
||||
{
|
||||
/**
|
||||
* Select
|
||||
* Select.
|
||||
*/
|
||||
|
||||
public function testSelectSimple()
|
||||
{
|
||||
$query = Models::get('sqltable')->select();
|
||||
$this->assertEquals('SELECT * FROM table', $query->getSql());
|
||||
}
|
||||
|
||||
public function testSelectSimpleOneField(){
|
||||
|
||||
public function testSelectSimpleOneField()
|
||||
{
|
||||
$query = Models::get('sqltable')->select('field1');
|
||||
$this->assertEquals('SELECT field1 FROM table', $query->getSql());
|
||||
}
|
||||
|
||||
public function testSelectSimpleTwoFields(){
|
||||
|
||||
public function testSelectSimpleTwoFields()
|
||||
{
|
||||
$query = Models::get('sqltable')->select('field1', 'field2');
|
||||
$this->assertEquals('SELECT field1, field2 FROM table', $query->getSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
* Delete.
|
||||
*/
|
||||
|
||||
public function testDeleteSimple(){
|
||||
|
||||
public function testDeleteSimple()
|
||||
{
|
||||
$query = Models::get('sqltable')->delete()->from('table');
|
||||
$this->assertEquals('DELETE FROM table', $query->getSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert
|
||||
* Insert.
|
||||
*/
|
||||
|
||||
public function testInsertSimple(){
|
||||
|
||||
public function testInsertSimple()
|
||||
{
|
||||
$query = Models::get('sqltable')->insert(array('field' => 'value'));
|
||||
$this->assertEquals('INSERT INTO table (field) VALUES (?)', $query->getSql());
|
||||
$this->assertEquals(array('value'), $query->getBinds());
|
||||
}
|
||||
|
||||
public function testInsertMultiple(){
|
||||
|
||||
public function testInsertMultiple()
|
||||
{
|
||||
$query = Models::get('sqltable')->insert(array('field1' => 'value1', 'field2' => 'value2'), 'table');
|
||||
$this->assertEquals('INSERT INTO table (field1,field2) VALUES (?,?)', $query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2'), $query->getBinds());
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace
|
||||
* Replace.
|
||||
*/
|
||||
|
||||
public function testReplaceSimple(){
|
||||
|
||||
public function testReplaceSimple()
|
||||
{
|
||||
$query = Models::get('sqltable')->replace(array('field' => 'value'));
|
||||
$this->assertEquals('REPLACE INTO table (field) VALUES (?)', $query->getSql());
|
||||
$this->assertEquals(array('value'), $query->getBinds());
|
||||
}
|
||||
|
||||
public function testReplaceMultiple(){
|
||||
|
||||
public function testReplaceMultiple()
|
||||
{
|
||||
$query = Models::get('sqltable')->replace(array('field1' => 'value1', 'field2' => 'value2'), 'table');
|
||||
$this->assertEquals('REPLACE INTO table (field1,field2) VALUES (?,?)', $query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2'), $query->getBinds());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,19 +20,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use \FuzeWorks\Modules;
|
||||
use \Module\DatabaseUtils\Query;
|
||||
|
||||
class QueryTests extends \CoreTestAbstract {
|
||||
|
||||
class QueryTests extends \CoreTestAbstract
|
||||
{
|
||||
/**
|
||||
* @var Query
|
||||
*/
|
||||
|
@ -43,16 +44,16 @@ class QueryTests extends \CoreTestAbstract {
|
|||
/**
|
||||
* @before
|
||||
*/
|
||||
protected function setUp(){
|
||||
protected function setUp()
|
||||
{
|
||||
Modules::get('core/databaseutils');
|
||||
$this->query = new Query();
|
||||
}
|
||||
|
||||
public function testConstructor(){
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$query = new Query('table');
|
||||
$this->assertEquals('table', $query->getTable());
|
||||
|
||||
}
|
||||
/*
|
||||
* Select
|
||||
|
@ -64,9 +65,9 @@ class QueryTests extends \CoreTestAbstract {
|
|||
$this->assertEquals('SELECT * FROM table', $this->query->getSql());
|
||||
}
|
||||
|
||||
public function testSelectSimpleDefaultTable(){
|
||||
|
||||
$this->query->setTable("table")->select()->from();
|
||||
public function testSelectSimpleDefaultTable()
|
||||
{
|
||||
$this->query->setTable('table')->select()->from();
|
||||
$this->assertEquals('SELECT * FROM table', $this->query->getSql());
|
||||
}
|
||||
|
||||
|
@ -88,14 +89,14 @@ class QueryTests extends \CoreTestAbstract {
|
|||
$this->assertEquals('SELECT * FROM table t, table2 t2', $this->query->getSql());
|
||||
}
|
||||
|
||||
public function testSelectSimpleOneField(){
|
||||
|
||||
public function testSelectSimpleOneField()
|
||||
{
|
||||
$this->query->select('field1')->from('table');
|
||||
$this->assertEquals('SELECT field1 FROM table', $this->query->getSql());
|
||||
}
|
||||
|
||||
public function testSelectSimpleTwoFields(){
|
||||
|
||||
public function testSelectSimpleTwoFields()
|
||||
{
|
||||
$this->query->select('field1', 'field2')->from('table');
|
||||
$this->assertEquals('SELECT field1, field2 FROM table', $this->query->getSql());
|
||||
}
|
||||
|
@ -104,36 +105,37 @@ class QueryTests extends \CoreTestAbstract {
|
|||
* Where
|
||||
*/
|
||||
|
||||
public function testSelectWhere(){
|
||||
|
||||
$this->query->select()->from('table')->where("field", "value");
|
||||
public function testSelectWhere()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field', 'value');
|
||||
$this->assertEquals('SELECT * FROM table WHERE field = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereLike(){
|
||||
|
||||
$this->query->select()->from('table')->where("field", "like", '%value%');
|
||||
public function testSelectWhereLike()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field', 'like', '%value%');
|
||||
$this->assertEquals('SELECT * FROM table WHERE field LIKE ?', $this->query->getSql());
|
||||
$this->assertEquals(array('%value%'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereBetween(){
|
||||
|
||||
$this->query->select()->from('table')->where("field", "between", array(2, 4));
|
||||
public function testSelectWhereBetween()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field', 'between', array(2, 4));
|
||||
$this->assertEquals('SELECT * FROM table WHERE field BETWEEN ? AND ?', $this->query->getSql());
|
||||
$this->assertEquals(array(2, 4), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereIn(){
|
||||
|
||||
$this->query->select()->from('table')->where("field", "in", array(2, 3, 4));
|
||||
public function testSelectWhereIn()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field', 'in', array(2, 3, 4));
|
||||
$this->assertEquals('SELECT * FROM table WHERE field IN (?,?,?)', $this->query->getSql());
|
||||
$this->assertEquals(array(2, 3, 4), $this->query->getBinds());
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Make this work!
|
||||
*
|
||||
* @return [type] [description]
|
||||
*/
|
||||
/*public function testSelectWhereInSubQuery(){
|
||||
|
@ -146,72 +148,72 @@ class QueryTests extends \CoreTestAbstract {
|
|||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}*/
|
||||
|
||||
public function testSelectWhereNot(){
|
||||
|
||||
$this->query->select()->from('table')->where("field", "<>", "value");
|
||||
public function testSelectWhereNot()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field', '<>', 'value');
|
||||
$this->assertEquals('SELECT * FROM table WHERE field <> ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereGreater(){
|
||||
|
||||
$this->query->select()->from('table')->where("field", ">", "value");
|
||||
public function testSelectWhereGreater()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field', '>', 'value');
|
||||
$this->assertEquals('SELECT * FROM table WHERE field > ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereGreaterEqual(){
|
||||
|
||||
$this->query->select()->from('table')->where("field", ">=", "value");
|
||||
public function testSelectWhereGreaterEqual()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field', '>=', 'value');
|
||||
$this->assertEquals('SELECT * FROM table WHERE field >= ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereSmaller(){
|
||||
|
||||
$this->query->select()->from('table')->where("field", "<", "value");
|
||||
public function testSelectWhereSmaller()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field', '<', 'value');
|
||||
$this->assertEquals('SELECT * FROM table WHERE field < ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereSmallerEqual(){
|
||||
|
||||
$this->query->select()->from('table')->where("field", "<=", "value");
|
||||
public function testSelectWhereSmallerEqual()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field', '<=', 'value');
|
||||
$this->assertEquals('SELECT * FROM table WHERE field <= ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereAnd(){
|
||||
|
||||
$this->query->select()->from('table')->where("field1", "value1")->and()->where("field2", "value2");
|
||||
public function testSelectWhereAnd()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field1', 'value1')->and()->where('field2', 'value2');
|
||||
$this->assertEquals('SELECT * FROM table WHERE field1 = ? AND field2 = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereAndOpen(){
|
||||
|
||||
$this->query->select()->from('table')->where("field1", "value1")->and()->open()->where("field2", "value2")->or()->where("field3", "value3")->close();
|
||||
public function testSelectWhereAndOpen()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field1', 'value1')->and()->open()->where('field2', 'value2')->or()->where('field3', 'value3')->close();
|
||||
$this->assertEquals('SELECT * FROM table WHERE field1 = ? AND ( field2 = ? OR field3 = ? )', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2', 'value3'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereOr(){
|
||||
|
||||
$this->query->select()->from('table')->where("field1", "value1")->or()->where("field2", "value2");
|
||||
public function testSelectWhereOr()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field1', 'value1')->or()->where('field2', 'value2');
|
||||
$this->assertEquals('SELECT * FROM table WHERE field1 = ? OR field2 = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectWhereOrOpen(){
|
||||
|
||||
$this->query->select()->from('table')->where("field1", "value1")->or()->open()->where("field2", "value2")->and()->where("field3", "value3")->close();
|
||||
public function testSelectWhereOrOpen()
|
||||
{
|
||||
$this->query->select()->from('table')->where('field1', 'value1')->or()->open()->where('field2', 'value2')->and()->where('field3', 'value3')->close();
|
||||
$this->assertEquals('SELECT * FROM table WHERE field1 = ? OR ( field2 = ? AND field3 = ? )', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2', 'value3'), $this->query->getBinds());
|
||||
}
|
||||
public function testSelectWhereOpen(){
|
||||
|
||||
public function testSelectWhereOpen()
|
||||
{
|
||||
$this->query->select()->from('table')
|
||||
->where()->open()->where("field1", "value1")->and()->where("field2", "value2")->close()
|
||||
->where()->open()->where('field1', 'value1')->and()->where('field2', 'value2')->close()
|
||||
->or()->where('field3', 'value3');
|
||||
$this->assertEquals('SELECT * FROM table WHERE ( field1 = ? AND field2 = ? ) OR field3 = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2', 'value3'), $this->query->getBinds());
|
||||
|
@ -221,20 +223,20 @@ class QueryTests extends \CoreTestAbstract {
|
|||
* Order by
|
||||
*/
|
||||
|
||||
public function testSelectOrderASC(){
|
||||
|
||||
public function testSelectOrderASC()
|
||||
{
|
||||
$this->query->select()->from('table')->order('field');
|
||||
$this->assertEquals('SELECT * FROM table ORDER BY field ASC', $this->query->getSql());
|
||||
}
|
||||
|
||||
public function testSelectOrderDESC(){
|
||||
|
||||
public function testSelectOrderDESC()
|
||||
{
|
||||
$this->query->select()->from('table')->order('-field');
|
||||
$this->assertEquals('SELECT * FROM table ORDER BY field DESC', $this->query->getSql());
|
||||
}
|
||||
|
||||
public function testSelectOrderMultiple(){
|
||||
|
||||
public function testSelectOrderMultiple()
|
||||
{
|
||||
$this->query->select()->from('table')->order('field1', '-field2');
|
||||
$this->assertEquals('SELECT * FROM table ORDER BY field1 ASC, field2 DESC', $this->query->getSql());
|
||||
}
|
||||
|
@ -247,107 +249,106 @@ class QueryTests extends \CoreTestAbstract {
|
|||
{
|
||||
$this->query->select()->from('table')->limit(5, 10);
|
||||
$this->assertEquals('SELECT * FROM table LIMIT 10, 5', $this->query->getSql());
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Having
|
||||
*/
|
||||
|
||||
public function testSelectHaving(){
|
||||
|
||||
$this->query->select()->from('table')->having("field", "value");
|
||||
public function testSelectHaving()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field', 'value');
|
||||
$this->assertEquals('SELECT * FROM table HAVING field = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingLike(){
|
||||
|
||||
$this->query->select()->from('table')->having("field", "like", '%value%');
|
||||
public function testSelectHavingLike()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field', 'like', '%value%');
|
||||
$this->assertEquals('SELECT * FROM table HAVING field LIKE ?', $this->query->getSql());
|
||||
$this->assertEquals(array('%value%'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingBetween(){
|
||||
|
||||
$this->query->select()->from('table')->having("field", "between", array(2, 4));
|
||||
public function testSelectHavingBetween()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field', 'between', array(2, 4));
|
||||
$this->assertEquals('SELECT * FROM table HAVING field BETWEEN ? AND ?', $this->query->getSql());
|
||||
$this->assertEquals(array(2, 4), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingIn(){
|
||||
|
||||
$this->query->select()->from('table')->having("field", "in", array(2, 3, 4));
|
||||
public function testSelectHavingIn()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field', 'in', array(2, 3, 4));
|
||||
$this->assertEquals('SELECT * FROM table HAVING field IN (?,?,?)', $this->query->getSql());
|
||||
$this->assertEquals(array(2, 3, 4), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingNot(){
|
||||
|
||||
$this->query->select()->from('table')->having("field", "<>", "value");
|
||||
public function testSelectHavingNot()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field', '<>', 'value');
|
||||
$this->assertEquals('SELECT * FROM table HAVING field <> ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingGreater(){
|
||||
|
||||
$this->query->select()->from('table')->having("field", ">", "value");
|
||||
public function testSelectHavingGreater()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field', '>', 'value');
|
||||
$this->assertEquals('SELECT * FROM table HAVING field > ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingGreaterEqual(){
|
||||
|
||||
$this->query->select()->from('table')->having("field", ">=", "value");
|
||||
public function testSelectHavingGreaterEqual()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field', '>=', 'value');
|
||||
$this->assertEquals('SELECT * FROM table HAVING field >= ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingSmaller(){
|
||||
|
||||
$this->query->select()->from('table')->having("field", "<", "value");
|
||||
public function testSelectHavingSmaller()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field', '<', 'value');
|
||||
$this->assertEquals('SELECT * FROM table HAVING field < ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingSmallerEqual(){
|
||||
|
||||
$this->query->select()->from('table')->having("field", "<=", "value");
|
||||
public function testSelectHavingSmallerEqual()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field', '<=', 'value');
|
||||
$this->assertEquals('SELECT * FROM table HAVING field <= ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingAnd(){
|
||||
|
||||
$this->query->select()->from('table')->having("field1", "value1")->and()->where("field2", "value2");
|
||||
public function testSelectHavingAnd()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field1', 'value1')->and()->where('field2', 'value2');
|
||||
$this->assertEquals('SELECT * FROM table HAVING field1 = ? AND field2 = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingAndOpen(){
|
||||
|
||||
$this->query->select()->from('table')->having("field1", "value1")->and()->open()->where("field2", "value2")->or()->where("field3", "value3")->close();
|
||||
public function testSelectHavingAndOpen()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field1', 'value1')->and()->open()->where('field2', 'value2')->or()->where('field3', 'value3')->close();
|
||||
$this->assertEquals('SELECT * FROM table HAVING field1 = ? AND ( field2 = ? OR field3 = ? )', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2', 'value3'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingOr(){
|
||||
|
||||
$this->query->select()->from('table')->having("field1", "value1")->or()->where("field2", "value2");
|
||||
public function testSelectHavingOr()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field1', 'value1')->or()->where('field2', 'value2');
|
||||
$this->assertEquals('SELECT * FROM table HAVING field1 = ? OR field2 = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testSelectHavingOrOpen(){
|
||||
|
||||
$this->query->select()->from('table')->having("field1", "value1")->or()->open()->where("field2", "value2")->and()->where("field3", "value3")->close();
|
||||
public function testSelectHavingOrOpen()
|
||||
{
|
||||
$this->query->select()->from('table')->having('field1', 'value1')->or()->open()->where('field2', 'value2')->and()->where('field3', 'value3')->close();
|
||||
$this->assertEquals('SELECT * FROM table HAVING field1 = ? OR ( field2 = ? AND field3 = ? )', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2', 'value3'), $this->query->getBinds());
|
||||
}
|
||||
public function testSelectHavingOpen(){
|
||||
|
||||
public function testSelectHavingOpen()
|
||||
{
|
||||
$this->query->select()->from('table')
|
||||
->having()->open()->where("field1", "value1")->and()->where("field2", "value2")->close()
|
||||
->having()->open()->where('field1', 'value1')->and()->where('field2', 'value2')->close()
|
||||
->or()->where('field3', 'value3');
|
||||
$this->assertEquals('SELECT * FROM table HAVING ( field1 = ? AND field2 = ? ) OR field3 = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2', 'value3'), $this->query->getBinds());
|
||||
|
@ -357,16 +358,16 @@ class QueryTests extends \CoreTestAbstract {
|
|||
* Update
|
||||
*/
|
||||
|
||||
public function testUpdateSimple(){
|
||||
|
||||
public function testUpdateSimple()
|
||||
{
|
||||
$this->query->setTable('table')->update()->set(array('field' => 'value'));
|
||||
$this->assertEquals('UPDATE table SET field=?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testUpdateMultiple(){
|
||||
|
||||
$this->query->setTable('table')->update()->set(array('field1' => 'value1', "field2" => 'value2'));
|
||||
public function testUpdateMultiple()
|
||||
{
|
||||
$this->query->setTable('table')->update()->set(array('field1' => 'value1', 'field2' => 'value2'));
|
||||
$this->assertEquals('UPDATE table SET field1=?, field2=?', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2'), $this->query->getBinds());
|
||||
}
|
||||
|
@ -375,8 +376,8 @@ class QueryTests extends \CoreTestAbstract {
|
|||
* Delete
|
||||
*/
|
||||
|
||||
public function testDeleteSimple(){
|
||||
|
||||
public function testDeleteSimple()
|
||||
{
|
||||
$this->query->setTable('table')->delete();
|
||||
$this->assertEquals('DELETE FROM table', $this->query->getSql());
|
||||
}
|
||||
|
@ -385,119 +386,114 @@ class QueryTests extends \CoreTestAbstract {
|
|||
* Insert
|
||||
*/
|
||||
|
||||
public function testInsertSimple(){
|
||||
|
||||
public function testInsertSimple()
|
||||
{
|
||||
$this->query->insert(array('field' => 'value'), 'table');
|
||||
$this->assertEquals('INSERT INTO table (field) VALUES (?)', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
|
||||
}
|
||||
|
||||
public function testInsertMultiple(){
|
||||
|
||||
public function testInsertMultiple()
|
||||
{
|
||||
$this->query->insert(array('field1' => 'value1', 'field2' => 'value2'), 'table');
|
||||
$this->assertEquals('INSERT INTO table (field1,field2) VALUES (?,?)', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2'), $this->query->getBinds());
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Replace
|
||||
*/
|
||||
|
||||
public function testReplaceSimple(){
|
||||
|
||||
public function testReplaceSimple()
|
||||
{
|
||||
$this->query->setTable('table')->replace(array('field' => 'value'));
|
||||
$this->assertEquals('REPLACE INTO table (field) VALUES (?)', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
|
||||
}
|
||||
|
||||
public function testReplaceMultiple(){
|
||||
|
||||
public function testReplaceMultiple()
|
||||
{
|
||||
$this->query->setTable('table')->replace(array('field1' => 'value1', 'field2' => 'value2'));
|
||||
$this->assertEquals('REPLACE INTO table (field1,field2) VALUES (?,?)', $this->query->getSql());
|
||||
$this->assertEquals(array('value1', 'value2'), $this->query->getBinds());
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Joins
|
||||
*/
|
||||
|
||||
public function testJoin(){
|
||||
|
||||
$this->query->select()->from('table')->join('other')->on("field", "value")->where("field", "value2");
|
||||
public function testJoin()
|
||||
{
|
||||
$this->query->select()->from('table')->join('other')->on('field', 'value')->where('field', 'value2');
|
||||
$this->assertEquals('SELECT * FROM table JOIN other ON field = ? WHERE field = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value', 'value2'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testJoinLeft(){
|
||||
|
||||
$this->query->select()->from('table')->left_join('other')->on("field", "value")->where("field", "value2");
|
||||
public function testJoinLeft()
|
||||
{
|
||||
$this->query->select()->from('table')->left_join('other')->on('field', 'value')->where('field', 'value2');
|
||||
$this->assertEquals('SELECT * FROM table LEFT JOIN other ON field = ? WHERE field = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value', 'value2'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testJoinRight(){
|
||||
|
||||
$this->query->select()->from('table')->right_join('other')->on("field", "value")->where("field", "value2");
|
||||
public function testJoinRight()
|
||||
{
|
||||
$this->query->select()->from('table')->right_join('other')->on('field', 'value')->where('field', 'value2');
|
||||
$this->assertEquals('SELECT * FROM table RIGHT JOIN other ON field = ? WHERE field = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value', 'value2'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testJoinFull(){
|
||||
|
||||
$this->query->select()->from('table')->full_join('other')->on("field", "value")->where("field", "value2");
|
||||
public function testJoinFull()
|
||||
{
|
||||
$this->query->select()->from('table')->full_join('other')->on('field', 'value')->where('field', 'value2');
|
||||
$this->assertEquals('SELECT * FROM table FULL JOIN other ON field = ? WHERE field = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value', 'value2'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testJoinAdvanced(){
|
||||
|
||||
public function testJoinAdvanced()
|
||||
{
|
||||
$this->query->select()->from('table')
|
||||
->left_join('other_a')->on("field", "value")
|
||||
->right_join('other_b')->on("field", "value2")
|
||||
->full_join('other_c')->on("field", "value3")
|
||||
->where("field", "value4");
|
||||
->left_join('other_a')->on('field', 'value')
|
||||
->right_join('other_b')->on('field', 'value2')
|
||||
->full_join('other_c')->on('field', 'value3')
|
||||
->where('field', 'value4');
|
||||
$this->assertEquals('SELECT * FROM table LEFT JOIN other_a ON field = ? RIGHT JOIN other_b ON field = ? FULL JOIN other_c ON field = ? WHERE field = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value', 'value2', 'value3', 'value4'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline joins
|
||||
* Inline joins.
|
||||
*/
|
||||
public function testJoinInline(){
|
||||
|
||||
$this->query->select()->from('table t', 'other o')->where("o.field", "value");
|
||||
public function testJoinInline()
|
||||
{
|
||||
$this->query->select()->from('table t', 'other o')->where('o.field', 'value');
|
||||
$this->assertEquals('SELECT * FROM table t, other o WHERE o.field = ?', $this->query->getSql());
|
||||
$this->assertEquals(array('value'), $this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testJoinInlineAdvanced(){
|
||||
|
||||
$this->query->select()->from('table t', 'other o')->where("o.field = t.field");
|
||||
public function testJoinInlineAdvanced()
|
||||
{
|
||||
$this->query->select()->from('table t', 'other o')->where('o.field = t.field');
|
||||
$this->assertEquals('SELECT * FROM table t, other o WHERE o.field = t.field', $this->query->getSql());
|
||||
$this->assertEmpty($this->query->getBinds());
|
||||
}
|
||||
|
||||
public function testJoinAllInOne(){
|
||||
|
||||
public function testJoinAllInOne()
|
||||
{
|
||||
$this->query->select()
|
||||
->from('table t', 'other o')
|
||||
->left_join('third th')->on('th.field = o.field')
|
||||
->where("o.field = t.field")
|
||||
->where('o.field = t.field')
|
||||
->and()->where('t.thing', '>', 25);
|
||||
$this->assertEquals('SELECT * FROM table t, other o LEFT JOIN third th ON th.field = o.field WHERE o.field = t.field AND t.thing > ?', $this->query->getSql());
|
||||
$this->assertEquals(array(25), $this->query->getBinds());
|
||||
}
|
||||
|
||||
/**
|
||||
* Group by
|
||||
* Group by.
|
||||
*/
|
||||
|
||||
public function testSelectGroupBy(){
|
||||
|
||||
public function testSelectGroupBy()
|
||||
{
|
||||
$this->query->groupBy('field1', 'field2');
|
||||
$this->assertEquals('GROUP BY field1, field2', $this->query->getSql());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,25 +20,26 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use \FuzeWorks\Core;
|
||||
use \FuzeWorks\Router;
|
||||
|
||||
/**
|
||||
* Class RouterTest
|
||||
* Class RouterTest.
|
||||
*
|
||||
* This test will test the router
|
||||
*/
|
||||
class RouterTest extends CoreTestAbstract
|
||||
class routerTest extends CoreTestAbstract
|
||||
{
|
||||
public function testParsePath(){
|
||||
public function testParsePath()
|
||||
{
|
||||
|
||||
// Act and assert
|
||||
Router::setPath('a/b/c/d/');
|
||||
|
@ -63,7 +64,8 @@ class RouterTest extends CoreTestAbstract
|
|||
/**
|
||||
* @depends testParsePath
|
||||
*/
|
||||
public function testDoRoute(){
|
||||
public function testDoRoute()
|
||||
{
|
||||
|
||||
// Act
|
||||
Router::setPath('a/b/c/d/');
|
||||
|
@ -71,7 +73,7 @@ class RouterTest extends CoreTestAbstract
|
|||
|
||||
// Assert
|
||||
// Whole route
|
||||
$this->assertEquals(array('a','b','c/d'), array(Router::getMatches()['controller'], Router::getMatches()['function'], Router::getMatches()['parameters']));
|
||||
$this->assertEquals(array('a', 'b', 'c/d'), array(Router::getMatches()['controller'], Router::getMatches()['function'], Router::getMatches()['parameters']));
|
||||
$this->assertEquals('a', Router::getMatches()['controller']);
|
||||
|
||||
// Parameters
|
||||
|
@ -85,7 +87,8 @@ class RouterTest extends CoreTestAbstract
|
|||
/**
|
||||
* @depends testDoRoute
|
||||
*/
|
||||
public function testOddRoutes(){
|
||||
public function testOddRoutes()
|
||||
{
|
||||
|
||||
// Empty path
|
||||
Router::setPath(null);
|
||||
|
@ -95,23 +98,23 @@ class RouterTest extends CoreTestAbstract
|
|||
// Double slashes
|
||||
Router::setPath('a///b');
|
||||
Router::route(false);
|
||||
$this->assertEquals(array('a','b'), array(Router::getMatches()['controller'], Router::getMatches()['function']));
|
||||
$this->assertEquals(array('a', 'b'), array(Router::getMatches()['controller'], Router::getMatches()['function']));
|
||||
|
||||
// Escaped path path
|
||||
Router::setPath('/a\/b\/c/');
|
||||
Router::route(false);
|
||||
$this->assertEquals(array('a\\','b\\','c'), array(Router::getMatches()['controller'], Router::getMatches()['function'], Router::getMatches()['parameters']));
|
||||
$this->assertEquals(array('a\\', 'b\\', 'c'), array(Router::getMatches()['controller'], Router::getMatches()['function'], Router::getMatches()['parameters']));
|
||||
$this->assertNotEquals('a', Router::getMatches()['controller']);
|
||||
}
|
||||
|
||||
public function testCustomRoute(){
|
||||
|
||||
public function testCustomRoute()
|
||||
{
|
||||
Router::addRoute('/test1\/test2/', 'callable');
|
||||
$this->assertArraySubset(array('/test1\/test2/' => 'callable'), Router::getRoutes());
|
||||
}
|
||||
|
||||
public function testCustomRouteWithParameters(){
|
||||
|
||||
public function testCustomRouteWithParameters()
|
||||
{
|
||||
Router::addRoute('/^b\/(?P<controller>[^\/]+)\/?(?P<function>.+?)$/', 'callable');
|
||||
Router::addRoute('/e\/(?P<function>[^\/]+)/', 'callable');
|
||||
Router::addRoute('/b\/b$/', 'callable');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,28 +20,29 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use \FuzeWorks\Core;
|
||||
use \FuzeWorks\Events;
|
||||
use \FuzeWorks\EventPriority;
|
||||
|
||||
/**
|
||||
* Class CoreStartEventTest
|
||||
* Class CoreStartEventTest.
|
||||
*/
|
||||
class CoreStartEventTest extends CoreTestAbstract
|
||||
class coreStartEventTest extends CoreTestAbstract
|
||||
{
|
||||
/**
|
||||
* Check if the event is fired when it should be
|
||||
* Check if the event is fired when it should be.
|
||||
*/
|
||||
public function testCoreStartEvent(){
|
||||
|
||||
public function testCoreStartEvent()
|
||||
{
|
||||
$mock = $this->getMock('MockEvent', array('mockMethod'));
|
||||
$mock->expects($this->once())->method('mockMethod');
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,28 +20,29 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use \FuzeWorks\Events;
|
||||
use \FuzeWorks\Layout;
|
||||
use \FuzeWorks\EventPriority;
|
||||
|
||||
/**
|
||||
* Class LayoutLoadViewEventTest
|
||||
* Class LayoutLoadViewEventTest.
|
||||
*/
|
||||
class LayoutLoadViewEventTest extends CoreTestAbstract{
|
||||
|
||||
class layoutLoadViewEventTest extends CoreTestAbstract
|
||||
{
|
||||
/**
|
||||
* Check if the event is fired when it should be
|
||||
* Check if the event is fired when it should be.
|
||||
*/
|
||||
public function test_basic(){
|
||||
|
||||
public function test_basic()
|
||||
{
|
||||
$mock = $this->getMock('MockEvent', array('mockMethod'));
|
||||
$mock->expects($this->once())->method('mockMethod');
|
||||
|
||||
|
@ -52,17 +53,19 @@ class LayoutLoadViewEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
/**
|
||||
* Intercept and change the event
|
||||
* Intercept and change the event.
|
||||
*
|
||||
* @expectedException \FuzeWorks\LayoutException
|
||||
*/
|
||||
public function test_change(){
|
||||
|
||||
public function test_change()
|
||||
{
|
||||
Events::addListener(array($this, 'listener_change'), 'layoutLoadViewEvent', EventPriority::NORMAL);
|
||||
Layout::get('home');
|
||||
}
|
||||
|
||||
// Change title from new to other
|
||||
public function listener_change($event){
|
||||
public function listener_change($event)
|
||||
{
|
||||
|
||||
// This controller should not exist
|
||||
$this->assertEquals('Application/Views/view.home.php', $event->file);
|
||||
|
@ -70,13 +73,15 @@ class LayoutLoadViewEventTest extends CoreTestAbstract{
|
|||
|
||||
// It should exist now
|
||||
$event->file = 'Application/Views/view.test.not_found';
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel events
|
||||
* Cancel events.
|
||||
*/
|
||||
public function test_cancel(){
|
||||
public function test_cancel()
|
||||
{
|
||||
|
||||
// Listen for the event and cancel it
|
||||
Events::addListener(array($this, 'listener_cancel'), 'layoutLoadViewEvent', EventPriority::NORMAL);
|
||||
|
@ -84,8 +89,8 @@ class LayoutLoadViewEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
// Cancel all calls
|
||||
public function listener_cancel($event){
|
||||
|
||||
public function listener_cancel($event)
|
||||
{
|
||||
$event->setCancelled(true);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,33 +20,37 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use \FuzeWorks\Events;
|
||||
use \FuzeWorks\Router;
|
||||
use \FuzeWorks\EventPriority;
|
||||
|
||||
/**
|
||||
* Class RouterLoadCallableEventTest
|
||||
* Class RouterLoadCallableEventTest.
|
||||
*/
|
||||
class RouterLoadCallableEventTest extends CoreTestAbstract{
|
||||
|
||||
class routerLoadCallableEventTest extends CoreTestAbstract
|
||||
{
|
||||
/**
|
||||
* Check if the event is fired when it should be
|
||||
* Check if the event is fired when it should be.
|
||||
*/
|
||||
public function test_basic(){
|
||||
|
||||
public function test_basic()
|
||||
{
|
||||
$mock = $this->getMock('MockEvent', array('mockMethod'));
|
||||
$mock->expects($this->once())->method('mockMethod');
|
||||
|
||||
Router::setPath('/');
|
||||
Events::addListener(function($event){$event->setCancelled(true);}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
|
||||
Events::addListener(function ($event) {
|
||||
$event->setCancelled(true);
|
||||
|
||||
}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
|
||||
Events::addListener(array($mock, 'mockMethod'), 'routerLoadCallableEvent', EventPriority::NORMAL);
|
||||
|
||||
//Prevent ouputting HTML
|
||||
|
@ -56,17 +60,23 @@ class RouterLoadCallableEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
/**
|
||||
* Intercept and change
|
||||
* Intercept and change.
|
||||
*/
|
||||
public function test_change(){
|
||||
public function test_change()
|
||||
{
|
||||
Events::addListener(function ($event) {
|
||||
$event->setCancelled(true);
|
||||
|
||||
Events::addListener(function($event){$event->setCancelled(true);}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
|
||||
}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
|
||||
Events::addListener(array($this, 'listener_change'), 'routerLoadCallableEvent', EventPriority::NORMAL);
|
||||
Router::setPath('x/y/z');
|
||||
Router::route(true);
|
||||
|
||||
Events::$listeners = array();
|
||||
Events::addListener(function($event){$event->setCancelled(true);}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
|
||||
Events::addListener(function ($event) {
|
||||
$event->setCancelled(true);
|
||||
|
||||
}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
|
||||
Events::addListener(array($this, 'listener_change'), 'routerLoadCallableEvent', EventPriority::NORMAL);
|
||||
Router::setPath('x/y/z');
|
||||
Router::route(true);
|
||||
|
@ -76,7 +86,8 @@ class RouterLoadCallableEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
// Change title from new to other
|
||||
public function listener_change($event){
|
||||
public function listener_change($event)
|
||||
{
|
||||
|
||||
// This controller should not exist
|
||||
$this->assertEquals('x', $event->matches['controller']);
|
||||
|
@ -85,14 +96,15 @@ class RouterLoadCallableEventTest extends CoreTestAbstract{
|
|||
// It should exist now
|
||||
$event->matches['controller'] = 'standard';
|
||||
$event->matches['function'] = 'index';
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel events
|
||||
* Cancel events.
|
||||
*/
|
||||
public function test_cancel(){
|
||||
|
||||
public function test_cancel()
|
||||
{
|
||||
ob_start();
|
||||
// When the callable may execute, the callable will change to the controller
|
||||
// (because '' will trigger the default callable)
|
||||
|
@ -105,7 +117,10 @@ class RouterLoadCallableEventTest extends CoreTestAbstract{
|
|||
// When disabled, the default controller will be loaded and the callable will be overwritten
|
||||
// Remove the listener
|
||||
Events::$listeners = array();
|
||||
Events::addListener(function($event){$event->setCancelled(true);}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
|
||||
Events::addListener(function ($event) {
|
||||
$event->setCancelled(true);
|
||||
|
||||
}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
|
||||
|
||||
Router::route();
|
||||
$this->assertFalse(is_callable(Router::getCallable()));
|
||||
|
@ -113,8 +128,8 @@ class RouterLoadCallableEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
// Cancel all calls
|
||||
public function listener_cancel($event){
|
||||
|
||||
public function listener_cancel($event)
|
||||
{
|
||||
$event->setCancelled(true);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,28 +20,29 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use \FuzeWorks\Events;
|
||||
use \FuzeWorks\Router;
|
||||
use \FuzeWorks\EventPriority;
|
||||
|
||||
/**
|
||||
* Class RouterRouteEventTest
|
||||
* Class RouterRouteEventTest.
|
||||
*/
|
||||
class RouterRouteEventTest extends CoreTestAbstract{
|
||||
|
||||
class routerRouteEventTest extends CoreTestAbstract
|
||||
{
|
||||
/**
|
||||
* Check if the event is fired when it should be
|
||||
* Check if the event is fired when it should be.
|
||||
*/
|
||||
public function test_basic(){
|
||||
|
||||
public function test_basic()
|
||||
{
|
||||
$mock = $this->getMock('MockEvent', array('mockMethod'));
|
||||
$mock->expects($this->once())->method('mockMethod');
|
||||
|
||||
|
@ -51,10 +52,10 @@ class RouterRouteEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
/**
|
||||
* Cancel events
|
||||
* Cancel events.
|
||||
*/
|
||||
public function test_cancel(){
|
||||
|
||||
public function test_cancel()
|
||||
{
|
||||
Router::setPath('x/y/z');
|
||||
|
||||
Events::addListener(array($this, 'listener_cancel'), 'routerRouteEvent', EventPriority::NORMAL);
|
||||
|
@ -66,8 +67,8 @@ class RouterRouteEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
// Cancel all calls
|
||||
public function listener_cancel($event){
|
||||
|
||||
public function listener_cancel($event)
|
||||
{
|
||||
$event->setCancelled(true);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
|
@ -20,28 +20,29 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://fuzeworks.techfuze.net
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use \FuzeWorks\Events;
|
||||
use \FuzeWorks\Router;
|
||||
use \FuzeWorks\EventPriority;
|
||||
|
||||
/**
|
||||
* Class RouterSetPathEventTest
|
||||
* Class RouterSetPathEventTest.
|
||||
*/
|
||||
class RouterSetPathEventTest extends CoreTestAbstract{
|
||||
|
||||
class routerSetPathEventTest extends CoreTestAbstract
|
||||
{
|
||||
/**
|
||||
* Check if the event is fired when it should be
|
||||
* Check if the event is fired when it should be.
|
||||
*/
|
||||
public function testRouterSetPathEvent(){
|
||||
|
||||
public function testRouterSetPathEvent()
|
||||
{
|
||||
$mock = $this->getMock('MockEvent', array('mockMethod'));
|
||||
$mock->expects($this->once())->method('mockMethod');
|
||||
|
||||
|
@ -50,10 +51,10 @@ class RouterSetPathEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
/**
|
||||
* Intercept and change
|
||||
* Intercept and change.
|
||||
*/
|
||||
public function testRouterSetPathEvent_change(){
|
||||
|
||||
public function testRouterSetPathEvent_change()
|
||||
{
|
||||
Events::addListener(array($this, 'listener_change'), 'routerSetPathEvent', EventPriority::NORMAL);
|
||||
Router::setPath('a/b/c');
|
||||
|
||||
|
@ -61,17 +62,17 @@ class RouterSetPathEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
// Change title from new to other
|
||||
public function listener_change($event){
|
||||
|
||||
public function listener_change($event)
|
||||
{
|
||||
$this->assertEquals('a/b/c', $event->path);
|
||||
$event->path = 'x/y/z';
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel events
|
||||
* Cancel events.
|
||||
*/
|
||||
public function testLayoutFunctionCallEvent_cancel(){
|
||||
|
||||
public function testLayoutFunctionCallEvent_cancel()
|
||||
{
|
||||
Router::setPath('a/b/c');
|
||||
|
||||
Events::addListener(array($this, 'listener_cancel'), 'routerSetPathEvent', EventPriority::NORMAL);
|
||||
|
@ -81,17 +82,16 @@ class RouterSetPathEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
// Cancel all calls
|
||||
public function listener_cancel($event){
|
||||
|
||||
public function listener_cancel($event)
|
||||
{
|
||||
$event->setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do not cancel events
|
||||
* Do not cancel events.
|
||||
*/
|
||||
public function testLayoutFunctionCallEvent_dontcancel(){
|
||||
|
||||
public function testLayoutFunctionCallEvent_dontcancel()
|
||||
{
|
||||
Router::setPath('a/b/c');
|
||||
|
||||
Events::addListener(array($this, 'listener_dontcancel'), 'routerSetPathEvent', EventPriority::NORMAL);
|
||||
|
@ -101,8 +101,8 @@ class RouterSetPathEventTest extends CoreTestAbstract{
|
|||
}
|
||||
|
||||
// Cancel all calls
|
||||
public function listener_dontcancel($event){
|
||||
|
||||
public function listener_dontcancel($event)
|
||||
{
|
||||
$event->setCancelled(false);
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
<?php echo "PHP Template Check"; ?>
|
||||
<?php echo 'PHP Template Check';
|
||||
|
|
Loading…
Reference in New Issue