Structuring the framework + startkit
This commit is contained in:
parent
ebbdb40cd3
commit
2400f8bd21
|
@ -0,0 +1,2 @@
|
|||
vendor
|
||||
composer.lock
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
use sealandia\framework\Template;
|
||||
|
||||
class Welcome{
|
||||
|
||||
public function index(){
|
||||
$template = new Template();
|
||||
return $template->render('welcome', []);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"sealandia\\": "./"
|
||||
"sealandia\\": "./",
|
||||
"sealandia\\framework\\": "framework/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace sealandia\framework;
|
||||
|
||||
class Router{
|
||||
|
||||
private $uri;
|
||||
|
||||
/**
|
||||
* Constructor method
|
||||
* Executed when an instance of the Router class is created
|
||||
*/
|
||||
|
||||
public function __construct(){
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];
|
||||
$this->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);
|
||||
|
||||
?>
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace sealandia\framework;
|
||||
|
||||
class Template{
|
||||
|
||||
/**
|
||||
|
@ -15,7 +17,7 @@ class Template{
|
|||
*/
|
||||
|
||||
extract($args, EXTR_SKIP);
|
||||
require "views/{$code}.view.php";
|
||||
require "views/{$tmpname}.view.php";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,5 +5,5 @@ namespace sealandia;
|
|||
session_start();
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
require __DIR__ . '/routes/routes.php';
|
||||
?>
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
use sealandia\framework\Router;
|
||||
|
||||
$routes = [
|
||||
'/' => 'Welcome@index',
|
||||
];
|
||||
|
||||
$router = (new Router)->routeToController($routes);
|
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Sealandia framework</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Page not found</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Sealandia framework</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to Sealandia</h1>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue