diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88e99d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor +composer.lock \ No newline at end of file diff --git a/app/controllers/welcome.php b/app/controllers/welcome.php new file mode 100644 index 0000000..ed7fc2f --- /dev/null +++ b/app/controllers/welcome.php @@ -0,0 +1,11 @@ +render('welcome', []); + } + +} \ No newline at end of file diff --git a/composer.json b/composer.json index 6d03609..00b02b2 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { "autoload": { "psr-4": { - "sealandia\\": "./" + "sealandia\\": "./", + "sealandia\\framework\\": "framework/" } }, "require": { diff --git a/framework/router.php b/framework/router.php index 372b6ba..1c3934d 100644 --- a/framework/router.php +++ b/framework/router.php @@ -1,14 +1,18 @@ uri = parse_url($_SERVER['REQUEST_URI'])['path']; } /** @@ -24,7 +28,22 @@ class Router{ */ if(array_key_exists($this->uri, $routes)){ - require $routes[$uri]; + list($controller, $method) = explode('@', $routes[$this->uri]); + + $controllerPath = __DIR__ . '/../app/controllers/' . $controller . '.php'; + + if(file_exists($controllerPath)){ + require_once $controllerPath; + $controller = new $controller(); + + if(method_exists($controller, $method)){ + $controller->$method(); + }else{ + $this->abort(); + } + }else{ + $this->abort(); + } }else{ $this->abort(); } @@ -46,13 +65,4 @@ class Router{ die(); } } - -// $routes = [ -// '/' => 'controllers/index.php', -// '/about' => 'controllers/about.php', -// '/contact' => 'controllers/contact.php', -// ]; - -// $router = Router::routeToController($routes); - ?> \ No newline at end of file diff --git a/framework/template.php b/framework/template.php index 55fab29..862e3ea 100644 --- a/framework/template.php +++ b/framework/template.php @@ -1,5 +1,7 @@ \ No newline at end of file diff --git a/routes/routes.php b/routes/routes.php index e69de29..ac7bea7 100644 --- a/routes/routes.php +++ b/routes/routes.php @@ -0,0 +1,9 @@ + 'Welcome@index', +]; + +$router = (new Router)->routeToController($routes); \ No newline at end of file diff --git a/views/404.php b/views/404.php new file mode 100644 index 0000000..797c401 --- /dev/null +++ b/views/404.php @@ -0,0 +1,8 @@ + + + Sealandia framework + + +

Page not found

+ + \ No newline at end of file diff --git a/views/welcome.view.php b/views/welcome.view.php new file mode 100644 index 0000000..97702d2 --- /dev/null +++ b/views/welcome.view.php @@ -0,0 +1,8 @@ + + + Sealandia framework + + +

Welcome to Sealandia

+ + \ No newline at end of file