The following files are needed for this exercise..
In an application we only want 1 front controller, therefore the front controller will be a singleton.
namespace controllers;
use controllers\ApplicationController;
use base\Request;
require_once 'base/Request.php';
require_once 'ApplicationController.php';
class FrontController
{
static private $_instance;
private function __construct()
{
}
static function GetInstance()
{
if(!isset(self::$_instance))
{
self::$_instance = new Self();
ApplicationController::Init();
}
return self::$_instance;
}
As a central access point, the front controller uses a method called 'HandleRequest' to handle a request.
$frontController = FrontController::getInstance();
$request = Regsitry::getInstance()->getRequest();
$frontController->HandleRequest($request);
public function HandleRequest(Request $request)
{
}
Complete the HandleRequest() method in the Front Controller. This method should get the appropriate command, execute the command and render the appropriate view.