Skip to content

Commit

Permalink
namespace modules names
Browse files Browse the repository at this point in the history
  • Loading branch information
bakeiro committed Dec 13, 2020
1 parent 292183f commit 18c1334
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
// AutoLoader
require "system/engine/AutoLoader.php";

// Basic namespace mapping
$loader = new AutoLoaderClass();
$loader->register();
$loader->addNamespace("Engine", "system/engine");
$loader->addNamespace("Library", "system/library");
$loader->addNamespace("Src", "src/");

// Environment
require "system/config/environment.php";
Expand Down
1 change: 1 addition & 0 deletions src/common/controller/commonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ public function pageNotFound(): void
$this->output->load("common/pageNotFound", $data);
}
}
// src\common\controller\CommonController.php
8 changes: 4 additions & 4 deletions src/common/view/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<span style="position: absolute;top: 35px;">Header: src/view/template/common/Header.php</span>

<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a class="black-text" href="index.php?route=index/index/samplePage">Sample</a></li>
<li><a class="black-text" href="index.php?route=index/index/test">Not found page</a></li>
<li><a class="black-text" href="index.php?route=product/product/samplePage">Sample</a></li>
<li><a class="black-text" href="index.php?route=product/product/sample">Not found page</a></li>
</ul>
</div>
</nav>
Expand All @@ -45,8 +45,8 @@
<br><br>
<li><a href="/welcome">Welcome</a></li>
<li><div class="divider"></div></li>
<li><a href="index.php?route=index/index/samplePage">Sample</a></li>
<li><a href="index.php?route=index/index/test">Not found page</a></li>
<li><a href="index.php?route=product/product/samplePage">Sample</a></li>
<li><a href="index.php?route=product/product/otherMethod">Not found page</a></li>
</ul>

<div class="container">
Expand Down
22 changes: 15 additions & 7 deletions system/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,31 @@
// Composer
require "system/composer/vendor/autoload.php";

// Config
$config_values = include "system/config/config.php";
$config_values = $config_values[getenv("ENVIRONMENT")];

// container entries
// Config class
$config = new Config();

foreach ($config_values as $key => $config_value) {
// Config values
$config_values = include "system/config/config.php";
foreach ($config_values[getenv("ENVIRONMENT")] as $key => $config_value) {
$config->set($key, $config_value);
}

// use INI_SET config
// Config PHP values
$ini_variables = include "system/config/ini.php";
foreach ($ini_variables[getenv("ENVIRONMENT")] as $ini_name => $ini_value) {
ini_set($ini_name, $ini_value);
}

// complete namespace mapping
$modules = scandir("src/");
array_shift($modules);
array_shift($modules);
foreach ($modules as $module) {
$loader->addNamespace(ucfirst($module), "src/" . $module . "/controller");
$loader->addNamespace(ucfirst($module), "src/" . $module . "/model");
}


$console = new Console();

$util = new Util();
Expand Down
8 changes: 3 additions & 5 deletions system/engine/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public function parsePath(): array
{
$url_split = explode('/', $this->path);

$file = "src/" . $url_split[0] . '/controller/' . $url_split[1] . 'Controller.php';
$class = "Controller\\" . $url_split[1] . 'Controller';
$file = "src/" . $url_split[0] . '/controller/' . ucfirst($url_split[1]) . 'Controller.php';
$class = ucfirst($url_split[1]) . "\\" . ucfirst($url_split[1]) . 'Controller';
$method = $url_split[2];

if (!$this->isValidPath($file, $class, $file)) {
if (!$this->isValidPath($file, $class, $method)) {
$file = 'src/common/controller/commonController.php';
$method = 'pageNotFound';
$class = "Common\\commonController";
Expand All @@ -66,8 +66,6 @@ private function isValidPath($file, $class, $method): bool
$is_controller_ok = false;
}

include_once $file;

if (method_exists($class, $method) === false) {
$is_controller_ok = false;
}
Expand Down

0 comments on commit 18c1334

Please sign in to comment.