Skip to content
Snippets Groups Projects
Commit c036e117 authored by AustinPardosi's avatar AustinPardosi
Browse files

Merge branch 'develop' of...

Merge branch 'develop' of https://gitlab.informatika.org/if3110-2023-k02-01-02/tugas-besar-1 into feat-navbar
parents 9325c5dc f460c7f9
No related merge requests found
......@@ -4,6 +4,7 @@ namespace app;
use app\Router;
use app\base\BaseController;
use app\controllers\LoginController;
use app\controllers\MainController;
use app\repositories\UserRepository;
use app\services\UserService;
......@@ -21,7 +22,9 @@ class App
function init_router()
{
$this->router->addRoute('/', MainController::getInstance());
$this->router->addRoute('/', MainController::class);
$this->router->addRoute('/login', LoginController::class);
// $this->router->addRoute('/', new BaseController(new UserService(new UserRepository())));
}
}
......@@ -11,6 +11,7 @@ class Router
function addRoute(string $route, $controller)
{
var_dump($controller);
$this->routes[$route] = $controller;
}
......@@ -20,8 +21,12 @@ class Router
$method = AppRequest::getMethod();
$params = AppRequest::getParams();
var_dump($this->routes);
if (isset($this->routes[$uri])) {
return $this->routes[$uri]->handle($method, $params);
// var_dump($this->routes[$uri]);
$controllerClass = $this->routes[$uri];
$class = new $controllerClass();
return $class->handle($method, $params);
}
}
}
......
......@@ -6,9 +6,6 @@ use app\exceptions\MethodNotAllowedException;
abstract class BaseController
{
// ngasih tau layoutnya pake apa
protected static $instance;
protected $service;
protected function __construct($service)
......@@ -16,14 +13,6 @@ abstract class BaseController
$this->service = $service;
}
public static function getInstance()
{
if (!isset(self::$instance)) {
self::$instance = new static(null);
}
return self::$instance;
}
protected function get($urlParams)
{
throw new MethodNotAllowedException("Method not allowed");
......
<?php
namespace app\controllers;
use app\base\BaseController;
use app\services\UserService;
use Exception;
class LoginController extends BaseController
{
public function __construct()
{
parent::__construct(null);
}
protected function get($urlParams)
{
try {
parent::render($urlParams, "login", "layouts/base");
} catch (Exception $e) {
echo $e;
}
}
protected function post($urlParams)
{
try {
parent::put($urlParams);
} catch (Exception $e) {
echo $e;
}
}
protected function put($urlParams)
{
try {
parent::put($urlParams);
} catch (Exception $e) {
echo $e;
}
}
protected function delete($urlParams)
{
try {
parent::delete($urlParams);
} catch (Exception $e) {
echo $e;
}
}
}
......@@ -3,13 +3,12 @@
namespace app\controllers;
use app\base\BaseController;
use app\exceptions\MethodNotAllowedException;
use Exception;
class MainController extends BaseController
{
protected function __construct()
public function __construct()
{
parent::__construct(null);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment