Refactor some if/else checks

This commit is contained in:
Maarten 2024-11-27 20:07:22 +01:00
parent 1ace4c95b5
commit a763bf1d8c
3 changed files with 5 additions and 29 deletions

View file

@ -15,14 +15,11 @@ class HtmlEngine extends Render
$basePath = $_SERVER['DOCUMENT_ROOT'];
$viewsPath = app()->resourcePath('views/' . str_replace('.', '/', $this->view) . '.php');
if (file_exists($viewsPath)) {
extract($this->data);
include $viewsPath;
return;
}
if (!file_exists($viewsPath)) {
throw new \Exception('View not found');
}
extract($this->data);
include $viewsPath;
}
}

View file

@ -71,6 +71,7 @@ class RouteCollection
fn($key) => !is_numeric($key),
ARRAY_FILTER_USE_KEY
);
return $route;
}
}

View file

@ -1,22 +0,0 @@
<?php
namespace Core\Routing;
use Core\Http\Request;
class Router
{
/**
* Dispatch router and run application
*
* @return void
*/
public static function dispatch(): void
{
// Create request
$request = new Request($_POST + $_FILES);
// Dispatch router
RouteDispatcher::dispatch($request, RouteCollection::retrieve());
}
}