From 5b66dd5f29e3fef05fdbf144cdd7803cf02801f7 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Mon, 11 Feb 2019 19:47:24 +0100 Subject: [PATCH] Changed which properties Models, Views and Controllers contain. They no longer share the Factory. Fixes #5 --- src/FuzeWorks/Controller.php | 45 ++++++++++++++++++++++++++++++++++-- src/FuzeWorks/Model.php | 32 +++++++++++++++++++++++-- src/FuzeWorks/Router.php | 6 +++++ src/FuzeWorks/View.php | 32 +++++++++++++++++++++++-- 4 files changed, 109 insertions(+), 6 deletions(-) diff --git a/src/FuzeWorks/Controller.php b/src/FuzeWorks/Controller.php index 3d61683..4b1acef 100644 --- a/src/FuzeWorks/Controller.php +++ b/src/FuzeWorks/Controller.php @@ -39,11 +39,52 @@ namespace FuzeWorks; /** * Abstract class Controller. * - * Extends all controllers to use the Factory. + * Extends all controllers to use useful classes * * @author Abel Hoogeveen * @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; + } + + } \ No newline at end of file diff --git a/src/FuzeWorks/Model.php b/src/FuzeWorks/Model.php index 483cfd0..4c14fdd 100644 --- a/src/FuzeWorks/Model.php +++ b/src/FuzeWorks/Model.php @@ -40,11 +40,39 @@ namespace FuzeWorks; /** * Abstract class Model. * - * Extends all models to use the Factory. + * Extends all models to use useful classes * * @author Abel Hoogeveen * @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; + } + } diff --git a/src/FuzeWorks/Router.php b/src/FuzeWorks/Router.php index 37fbc01..0ac6b26 100644 --- a/src/FuzeWorks/Router.php +++ b/src/FuzeWorks/Router.php @@ -189,6 +189,7 @@ class Router * @return mixed * @throws NotFoundException * @throws RouterException + * @throws HaltException */ public function route(string $path) { @@ -251,6 +252,7 @@ class Router * @param string $route * @return mixed * @throws RouterException + * @throws HaltException */ 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()."'"); } + // Halt if cancelled + if ($event->isCancelled()) + throw new HaltException("Will not load callable. Cancelled by routerLoadCallableEvent."); + // Invoke callable $output = call_user_func_array($event->callable, [$event->matches, $event->route]); Logger::stopLevel(); diff --git a/src/FuzeWorks/View.php b/src/FuzeWorks/View.php index ccb5a81..f8d05a5 100644 --- a/src/FuzeWorks/View.php +++ b/src/FuzeWorks/View.php @@ -40,14 +40,34 @@ namespace FuzeWorks; /** * Abstract class View. * - * Extends all views to use the Factory. + * Extends all views to use useful classes * * @author Abel Hoogeveen * @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 * @@ -65,4 +85,12 @@ abstract class View extends Factory $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; + } + } \ No newline at end of file