fixing stuff

This commit is contained in:
2026-04-21 14:03:37 +02:00
parent 3de979fc65
commit 7ee3d6441a
5 changed files with 16 additions and 7 deletions

View File

@@ -1,2 +1,4 @@
<?php
$router->get('/', '/', [new HomeController(), 'home']);
use src\Controller\HomeController;
$router->get('/', [new HomeController(), 'index']);

View File

@@ -1,6 +1,8 @@
<?php
require_once __DIR__ . '/../src/Autoloader.php';
use src\Router;
$autoloader = new Autoloader();
$autoloader->addNamespace('src', __DIR__ . '/../src');
$autoloader->register();

View File

@@ -1,11 +1,13 @@
<?php
namespace src\Controller;
abstract class BaseController
{
protected function render(string $view, array $data = []): void
{
extract($data);
$viewPath = __DIR__ . '/../../views/' . $view . '.php';
$viewPath = __DIR__ . '/../../templates/' . $view . '.php';
if (!file_exists($viewPath)) {
http_response_code(500);

View File

@@ -1,4 +1,6 @@
<?php
namespace src\Controller;
class HomeController extends BaseController
{
public function index(): void

View File

@@ -1,11 +1,11 @@
<?php
namespace src
namespace src;
public class Router
class Router
{
private array $routes = [];
public function get(string $path, cllable $handler): void
public function get(string $path, callable $handler): void
{
$this->routes['GET'][$path] = $handler;
}
@@ -17,7 +17,8 @@ public class Router
public function dispatch(string $method, string $uri): void
{
$handler = $this->routes[$method][$uri] ?? null;
$path = parse_url($uri, PHP_URL_PATH) ?? '/';
$handler = $this->routes[$method][$path] ?? null;
if ($handler === null) {
http_response_code(404);