. * * @package NanoMvc * @author Nicolas Joseph * @copyright 2008 Nicolas Joseph * @license http://www.opensource.org/licenses/gpl-3.0.html GPL v3 * @filesource */ $_path = dirname (__FILE__); require_once ($_path .'/response.php'); require_once ($_path .'/request.php'); require_once ($_path .'/view.php'); /** * @note Classe singleton */ class Application { /** * @var Response */ private $response; /** * @var Request */ private $request; /** * @var Application */ private static $instance = null; private function __construct () { $this->request = Request::get_instance (); $this->response = Response::get_instance (); } /** * Obtenir l'unique instance de la classe. * * @return Application */ public static function get_instance () { if (is_null (self::$instance)) { self::$instance = new self (); } return self::$instance; } /** * Appel le controleur adequate en fonction de la requete de l'utilisateur. * * Cette fonction est le coeur de l'application, elle recupere la requete * de l'utilisateur, cree le controleur correspondant et demande son rendu * via la classe View pour enfin l'afficher. */ public function dispatch () { date_default_timezone_set ('Europe/Paris'); $this->request->parse (); $page = $this->request->page; $action = $this->request->action; if (file_exists ($path = 'pages/'. $page .'.php')) { require_once ($path); $class = $page .'Page'; $method = $action .'Action'; $controller = new $class (new View ($page)); $controller->execute ($action); $content = $controller->view->render ($this->request->get_env ()); $this->response->set_body ($content); } else { $this->response->not_found (); } $this->response->print_out (); } }