Refactor some if/else checks
This commit is contained in:
parent
1ace4c95b5
commit
a763bf1d8c
3 changed files with 5 additions and 29 deletions
|
@ -15,14 +15,11 @@ class HtmlEngine extends Render
|
||||||
$basePath = $_SERVER['DOCUMENT_ROOT'];
|
$basePath = $_SERVER['DOCUMENT_ROOT'];
|
||||||
$viewsPath = app()->resourcePath('views/' . str_replace('.', '/', $this->view) . '.php');
|
$viewsPath = app()->resourcePath('views/' . str_replace('.', '/', $this->view) . '.php');
|
||||||
|
|
||||||
if (file_exists($viewsPath)) {
|
if (!file_exists($viewsPath)) {
|
||||||
extract($this->data);
|
|
||||||
|
|
||||||
include $viewsPath;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Exception('View not found');
|
throw new \Exception('View not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extract($this->data);
|
||||||
|
include $viewsPath;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -71,6 +71,7 @@ class RouteCollection
|
||||||
fn($key) => !is_numeric($key),
|
fn($key) => !is_numeric($key),
|
||||||
ARRAY_FILTER_USE_KEY
|
ARRAY_FILTER_USE_KEY
|
||||||
);
|
);
|
||||||
|
|
||||||
return $route;
|
return $route;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue