Skip to content

Commit

Permalink
Pass App's namespace into request.
Browse files Browse the repository at this point in the history
  • Loading branch information
svandragt committed Jul 1, 2020
1 parent 71b2f9a commit fc7f42b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();
}
}
5 changes: 4 additions & 1 deletion src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fc7f42b

Please sign in to comment.