Skip to content

Commit

Permalink
Test if REQUEST_URI exists
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevanzuydam committed Aug 28, 2024
1 parent e2fe7c2 commit 436d855
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Tina4/Initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Tina4\Debug;
use Tina4\Module;

if (isset($_SERVER) && strpos($_SERVER["REQUEST_URI"], "index.php") !== false )
if (isset($_SERVER, $_SERVER["REQUEST_URI"]) && strpos($_SERVER["REQUEST_URI"], "index.php") !== false)
{
http_response_code(403);
echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>';
Expand Down
22 changes: 16 additions & 6 deletions Tina4/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public static function add(string $routePath, $function, bool $inlineParamsToReq
"caller" => $caller];
}
}

return new static;
}

Expand All @@ -104,6 +103,7 @@ public static function get(string $routePath, $function): Route
{
self::$method = TINA4_GET;
list(, $caller) = debug_backtrace(false);

return self::add($routePath, $function, true, false, false, $caller);
}

Expand All @@ -117,6 +117,7 @@ public static function put(string $routePath, $function): Route
{
self::$method = TINA4_PUT;
list(, $caller) = debug_backtrace(false);

return self::add($routePath, $function, true, false, false, $caller);
}

Expand All @@ -130,6 +131,7 @@ public static function post(string $routePath, $function): Route
{
self::$method = TINA4_POST;
list(, $caller) = debug_backtrace(false);

return self::add($routePath, $function, true, false, false, $caller);
}

Expand All @@ -143,6 +145,7 @@ public static function patch(string $routePath, $function): Route
{
self::$method = TINA4_PATCH;
list(, $caller) = debug_backtrace(false);

return self::add($routePath, $function, true, false, false, $caller);
}

Expand All @@ -156,6 +159,7 @@ public static function delete(string $routePath, $function): Route
{
self::$method = TINA4_DELETE;
list(, $caller) = debug_backtrace(false);

return self::add($routePath, $function, true, false, false, $caller);
}

Expand All @@ -169,6 +173,7 @@ public static function any(string $routePath, $function): Route
{
self::$method = TINA4_ANY;
list(, $caller) = debug_backtrace(false);

return self::add($routePath, $function, true, false, false, $caller);
}

Expand All @@ -180,7 +185,8 @@ public static function any(string $routePath, $function): Route
public static function middleware(array $functionNames): Route
{
global $arrRoutes;
$arrRoutes[sizeof($arrRoutes)-1]["middleware"] = $functionNames;
$arrRoutes[count($arrRoutes)-1]["middleware"] = $functionNames;

return new static;
}

Expand All @@ -193,7 +199,8 @@ public static function middleware(array $functionNames): Route
public static function noCache(bool $default=false): Route
{
global $arrRoutes;
$arrRoutes[sizeof($arrRoutes)-1]["cached"] = $default;
$arrRoutes[count($arrRoutes)-1]["cached"] = $default;

return new static;
}

Expand All @@ -205,7 +212,8 @@ public static function noCache(bool $default=false): Route
public static function cache(bool $default=true): Route
{
global $arrRoutes;
$arrRoutes[sizeof($arrRoutes)-1]["cached"] = $default;
$arrRoutes[count($arrRoutes)-1]["cached"] = $default;

return new static;
}

Expand All @@ -217,7 +225,8 @@ public static function cache(bool $default=true): Route
public static function secure(bool $default=true): Route
{
global $arrRoutes;
$arrRoutes[sizeof($arrRoutes)-1]["secure"] = $default;
$arrRoutes[count($arrRoutes)-1]["secure"] = $default;

return new static;
}

Expand All @@ -228,8 +237,9 @@ public static function caller($caller=null): Route
{
global $arrRoutes;
if (!empty($caller)) {
$arrRoutes[sizeof($arrRoutes) - 1]["caller"] = $caller;
$arrRoutes[count($arrRoutes) - 1]["caller"] = $caller;
}

return new static;
}
}

0 comments on commit 436d855

Please sign in to comment.