<?php class Router { private $routeList; public function addRoute($url, $callback){ $this->routeList[$url] = $callback; } public function route($url){ $this->routeList[$url]->call($this, $url); } } class HomeController { public function __construct($router){ $router->addRoute('/', function(){ return $this->doHomePage(); }); } private function doHomePage(){ $quote = $this->getRandomQuote(); return new Response('home.html', ['quote' => $quote]); } private function getRandomQuote(){ $quotes = ['You can do anything, but not everything.—David Allen', ' The richest man is not he who has the most, but he who needs the least. —Unknown Author','You miss 100 percent of the shots you never take.—Wayne Gretzky']; return $quotes[array_rand($quotes)]; } } class Response { public function __construct($template, $data){ } } $router = new Router(); $controller = new HomeController($router); $router->route('/');
You have javascript disabled. You will not be able to edit any code.