From fc7f42b79ded82cd9a20ff801e7e51fa362360f8 Mon Sep 17 00:00:00 2001 From: Sander van Dragt Date: Wed, 1 Jul 2020 08:04:19 +0100 Subject: [PATCH] Pass App's namespace into request. --- src/App.php | 6 ++++-- src/Request.php | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/App.php b/src/App.php index 5201414..6461eee 100644 --- a/src/App.php +++ b/src/App.php @@ -7,9 +7,11 @@ class App public $Security; public $Cache; public $Environment; + public $app_namespace; - public function __construct() + public function __construct($app_namespace = '') { + $this->app_namespace = $app_namespace; $this->Cache = new Cache(); if ($this->Cache->hasExistingCachefile()) { $bytes = readfile($this->Cache->convertUrlpathToFilepath()); @@ -32,7 +34,7 @@ public function run() // Process request if not statically cached. $this->Cache->start(); - new Request(); + new Request($this->app_namespace); $this->Cache->end(); } } diff --git a/src/Request.php b/src/Request.php index d3c5ed7..20bf3d3 100644 --- a/src/Request.php +++ b/src/Request.php @@ -15,12 +15,15 @@ class Request { protected $Controller; - public function __construct() + public function __construct($app_namespace) { // Route to controller $args = explode("/", $this->pathInfo()); $controller_class = 'Controller' . ucfirst($args[1]); + if (!empty($app_namespace)) { + $controller_class = $app_namespace . '\\' . $controller_class; + } $controller_arguments = array_slice($args, 2); if (class_exists($controller_class, true)) { $this->Controller = new $controller_class($this, $controller_arguments);