Changed which properties Models, Views and Controllers contain.

They no longer share the Factory.

Fixes #5
This commit is contained in:
Abel Hoogeveen 2019-02-11 19:47:24 +01:00
parent d8acd801d2
commit 5b66dd5f29
No known key found for this signature in database
GPG Key ID: 96C2234920BF4292
4 changed files with 109 additions and 6 deletions

View File

@ -39,11 +39,52 @@ namespace FuzeWorks;
/** /**
* Abstract class Controller. * Abstract class Controller.
* *
* Extends all controllers to use the Factory. * Extends all controllers to use useful classes
* *
* @author Abel Hoogeveen <abel@techfuze.net> * @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net) * @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
*/ */
abstract class Controller extends Factory abstract class Controller
{ {
/**
* @var Plugins
*/
public $plugins;
/**
* @var Libraries
*/
public $libraries;
/**
* @var Helpers
*/
public $helpers;
/**
* @var Config
*/
public $config;
/**
* @var Controllers
*/
public $controllers;
/**
* @var Models
*/
public $models;
public function __construct()
{
$this->plugins = Factory::getInstance()->plugins;
$this->libraries = Factory::getInstance()->libraries;
$this->helpers = Factory::getInstance()->helpers;
$this->config = Factory::getInstance()->config;
$this->controllers = Factory::getInstance()->controllers;
$this->models = Factory::getInstance()->models;
}
} }

View File

@ -40,11 +40,39 @@ namespace FuzeWorks;
/** /**
* Abstract class Model. * Abstract class Model.
* *
* Extends all models to use the Factory. * Extends all models to use useful classes
* *
* @author Abel Hoogeveen <abel@techfuze.net> * @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net) * @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
*/ */
abstract class Model extends Factory abstract class Model
{ {
/**
* @var Plugins
*/
public $plugins;
/**
* @var Libraries
*/
public $libraries;
/**
* @var Helpers
*/
public $helpers;
/**
* @var Config
*/
public $config;
public function __construct()
{
$this->plugins = Factory::getInstance()->plugins;
$this->libraries = Factory::getInstance()->libraries;
$this->helpers = Factory::getInstance()->helpers;
$this->config = Factory::getInstance()->config;
}
} }

View File

@ -189,6 +189,7 @@ class Router
* @return mixed * @return mixed
* @throws NotFoundException * @throws NotFoundException
* @throws RouterException * @throws RouterException
* @throws HaltException
*/ */
public function route(string $path) public function route(string $path)
{ {
@ -251,6 +252,7 @@ class Router
* @param string $route * @param string $route
* @return mixed * @return mixed
* @throws RouterException * @throws RouterException
* @throws HaltException
*/ */
protected function loadCallable(callable $callable, array $matches, string $route) protected function loadCallable(callable $callable, array $matches, string $route)
{ {
@ -272,6 +274,10 @@ class Router
throw new RouterException("Could not load callable. routerLoadCallableEvent threw exception: '".$e->getMessage()."'"); throw new RouterException("Could not load callable. routerLoadCallableEvent threw exception: '".$e->getMessage()."'");
} }
// Halt if cancelled
if ($event->isCancelled())
throw new HaltException("Will not load callable. Cancelled by routerLoadCallableEvent.");
// Invoke callable // Invoke callable
$output = call_user_func_array($event->callable, [$event->matches, $event->route]); $output = call_user_func_array($event->callable, [$event->matches, $event->route]);
Logger::stopLevel(); Logger::stopLevel();

View File

@ -40,14 +40,34 @@ namespace FuzeWorks;
/** /**
* Abstract class View. * Abstract class View.
* *
* Extends all views to use the Factory. * Extends all views to use useful classes
* *
* @author Abel Hoogeveen <abel@techfuze.net> * @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net) * @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
*/ */
abstract class View extends Factory abstract class View
{ {
/**
* @var Plugins
*/
public $plugins;
/**
* @var Libraries
*/
public $libraries;
/**
* @var Helpers
*/
public $helpers;
/**
* @var Config
*/
public $config;
/** /**
* The controller associated with this view * The controller associated with this view
* *
@ -65,4 +85,12 @@ abstract class View extends Factory
$this->controller = $controller; $this->controller = $controller;
} }
public function __construct()
{
$this->plugins = Factory::getInstance()->plugins;
$this->libraries = Factory::getInstance()->libraries;
$this->helpers = Factory::getInstance()->helpers;
$this->config = Factory::getInstance()->config;
}
} }