Skip to content

Commit

Permalink
Merge pull request #8 from eneioarzew/v0.2.1
Browse files Browse the repository at this point in the history
V0.2.1
  • Loading branch information
astralicht authored May 9, 2021
2 parents b394b14 + a0e2695 commit 04cdb16
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# Egg Framework
*A lightweight PHP framework for quick project creation by Julac Ontina.*
*A lightweight PHP framework for quick project creation.*

# Installation
**Install using Composer**
Expand Down
5 changes: 3 additions & 2 deletions chalaza
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class $controllerClassName"."Controller {
fclose($view);

$file = fopen("routes.php", "a");
fwrite($file, "\n".'$ROUTE["'.$viewFolderName.'"] = "'.$viewFolderName.'/index";');
fwrite($file, "\n".'$ROUTE["'.$viewFolderName.'/index"] = "'.$viewFolderName.'/index";');
fclose($file);

Expand Down Expand Up @@ -293,6 +294,6 @@ if(isset($argv[1])) {
}
}
else{
echo "\n\033[33m Chalaza \033[0m v1.0";
echo "\nby Julac Ontina\n\n";
echo "\n\033[33m Chalaza";
echo "\n\033[0m by EneioArzew\n\n";
}
96 changes: 48 additions & 48 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,69 @@
include_once 'config.php';
include_once 'routes.php';

function showErrorPage()
{
$instance = new Error404Controller();
include_once $instance->index();
}

$original_URI = $_SERVER['REQUEST_URI'];
$exploded_URI = explode("/", $original_URI);
$json_string = file_get_contents("php://input");
$URI_offset = 2;

if ($ENVIRONMENT === "LOCAL") {
foreach (range(0, $URI_offset - 1) as $i) {
array_shift($exploded_URI);
}
$URI_offset = ['LOCAL' => 2, 'PRODUCTION' => 1];
$offset = $URI_offset[$ENVIRONMENT];

$final_URI = implode("/", $exploded_URI);
$URI_length = 0;
foreach (range(0, $offset - 1) as $i) {
array_shift($exploded_URI);
}

if (implode("", $exploded_URI) !== "") {
$URI_length = count($exploded_URI);
}
$final_URI = implode("/", $exploded_URI);
$URI_length = 0;

if ($URI_length === 0) {
$route = $ROUTE['/'];
$route = explode('/', $route);
$controller = $route[0];
$function = $route[1];
if (implode("", $exploded_URI) !== "") {
$URI_length = count($exploded_URI);
}

header("Location: $controller/$function");
} else {
$controller = $exploded_URI[0];
$function = $exploded_URI[1];
if ($URI_length === 0) {
$route = $ROUTE['/'];
$route = explode('/', $route);
$controller = $route[0];
$function = $route[1];

header("Location: $controller/$function");
} else {
$obj = json_decode($json_string, true);
$URI_route = $ROUTE[$final_URI];
if (isset($URI_route)) {
$URI_route = explode('/', $URI_route);
$controller = $URI_route[0];
$function = $URI_route[1];
$data = $exploded_URI[2];

if (!$exploded_URI[1]) {
header("Location: $controller/$function");
}

$controller[0] = strtoupper($controller[0]);
$controller .= "Controller";

$instance = new $controller();

$obj = json_decode($json_string, true);

if (isset($ROUTE[$final_URI])) {
if ($obj) {
$response = $instance->$function($obj);
if ($obj) {
$response = $instance->$function($obj);
if ($response !== null) {
echo json_encode($response);
} else {
$response = $instance->$function($data);
} else if ($response === null) {
echo json_encode(["body" => null]);
}
} else {
$response = $instance->$function($data);
if ($response !== null) {
include_once $response;
} else if ($response === null) {
showErrorPage();
}
}

if ($response !== null) {
include_once $response;
}
}
} else if ($ENVIRONMENT === "PRODUCTION") {
$URI_offset = 1;

foreach (range(0, $URI_offset - 1) as $i) {
array_shift($exploded_URI);
} else {
showErrorPage();
}

$final_URI = implode("/", $exploded_URI);
$URI_length = 0;
}

function showErrorPage()
{
$instance = new Error404Controller();
include_once $instance->index();
die;
}

0 comments on commit 04cdb16

Please sign in to comment.