Skip to content

Commit

Permalink
Merge branch 'master' of github.com:davidjconnelly/trongate-framework
Browse files Browse the repository at this point in the history
  • Loading branch information
trongate committed Jun 24, 2022
2 parents a28c848 + 30da36a commit 9541541
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions engine/Core.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,33 @@ class Core {

public function __construct() {

$pos = strpos(ASSUMED_URL, MODULE_ASSETS_TRIGGER);

if (strpos(ASSUMED_URL, 'vendor/')) {
if (strpos(ASSUMED_URL, '/vendor/')) {
$this->serve_vendor_asset();
} elseif(strpos(ASSUMED_URL, MODULE_ASSETS_TRIGGER) === false) {
$this->serve_controller();
} else {
$this->serve_module_asset();
}

$vendor_file_path = explode('vendor/', ASSUMED_URL)[1];
$vendor_file_path = '../vendor/'.$vendor_file_path;
$content_type = mime_content_type($vendor_file_path);
}

private function serve_vendor_asset() {
$vendor_file_path = explode('/vendor/', ASSUMED_URL)[1];
$vendor_file_path = '../vendor/'.$vendor_file_path;
if (file_exists($vendor_file_path)) {
if (strpos($vendor_file_path, '.css')) {
$content_type = 'text/css';
} else {
$content_type == 'text/plain';
$content_type = 'text/plain';
}

header('Content-type: '.$content_type);
$contents = file_get_contents($vendor_file_path);
echo $contents;
die();

} elseif($pos === false) {

$this->serve_controller();
} else {
$this->serve_module_asset();
}else{
die('Vendor file not found.');
}

}

private function serve_module_asset() {
Expand All @@ -55,8 +56,8 @@ private function serve_module_asset() {
}
}

$asset_path = '../modules/'.strtolower($target_module).'/assets/'.$target_dir.'/'.$file_name;
$asset_path = '../modules/'.strtolower($target_module).'/assets/'.$target_dir.'/'.$file_name;

if (file_exists($asset_path)) {
$content_type = mime_content_type($asset_path);

Expand All @@ -66,12 +67,12 @@ private function serve_module_asset() {
if (is_numeric($pos2)) {
$content_type = 'text/css';
}

$pos2 = strpos($file_name, '.js');
if (is_numeric($pos2)) {
$content_type = 'text/javascript';
}

}

if ($content_type == 'image/svg') {
Expand All @@ -83,15 +84,15 @@ private function serve_module_asset() {
http_response_code(422);
die();
}

header('Content-type: '.$content_type);
$contents = file_get_contents($asset_path);
echo $contents;
die();
} else {
$this->serve_child_module_asset($asset_path, $file_name);
}
}
}
}

}
Expand Down Expand Up @@ -144,7 +145,7 @@ private function serve_child_module_asset($asset_path, $file_name) {
private function attempt_sql_transfer($controller_path) {
$ditch = 'controllers/'.$this->current_controller.'.php';
$dir_path = str_replace($ditch, '', $controller_path);

$files = array();
foreach (glob($dir_path."*.sql") as $file) {
$file = str_replace($controller_path, '', $file);
Expand All @@ -155,7 +156,7 @@ private function attempt_sql_transfer($controller_path) {
require_once('tg_transferer/index.php');
die();
}

}

private function serve_controller() {
Expand All @@ -168,7 +169,7 @@ private function serve_controller() {
$this->current_module = strtolower($module_with_no_params);
$this->current_controller = ucfirst($this->current_module);
}

if (isset($segments[2])) {
$method_with_no_params = $segments[2];
$method_with_no_params = explode('?',$segments[2])[0];
Expand All @@ -178,7 +179,7 @@ private function serve_controller() {
if ($str == '_') {
$this->draw_error_page();
}
}
}

if (isset($segments[3])) {
$value_with_no_params = $segments[3];
Expand Down Expand Up @@ -238,7 +239,7 @@ private function attempt_init_child_controller($controller_path) {

if (count($bits)==2) {
if (strlen($bits[1])>0) {

$parent_module = strtolower($bits[0]);
$child_module = strtolower($bits[1]);
$this->current_controller = ucfirst($bits[1]);
Expand Down

0 comments on commit 9541541

Please sign in to comment.