/**
  * Framework entry point
  *
  * @return void.
  */
 public function dispatch()
 {
     include_once 'action/controller/http/HTTPResponse.php';
     include_once 'action/controller/http/HTTPRequest.php';
     $request = new HTTPRequest();
     $response = new HTTPResponse();
     try {
         $configurator = $this->manager->getConfigurator();
         Registry::put($configurator, '__configurator');
         Registry::put($logger = new Logger($configurator), '__logger');
         $ap = $configurator->getApplicationPath();
         // application path
         $an = $configurator->getApplicationName();
         // application name
         $logger->debug('[Medick] >> version: ' . Medick::getVersion() . ' ready for ' . $an);
         $logger->debug('[Medick] >> Application path ' . $ap);
         $routes_path = $ap . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR . $an . '.routes.php';
         include_once $routes_path;
         // load routes
         $logger->debug('[Medick] >> Config File: ' . str_replace($ap, '${' . $an . '}', $configurator->getConfigFile()));
         $logger->debug('[Medick] >> Routes loaded from: ' . str_replace($ap, '${' . $an . '}', $routes_path));
         ActionControllerRouting::recognize($request)->process($request, $response)->dump();
     } catch (Exception $ex) {
         ActionController::process_with_exception($request, $response, $ex)->dump();
         $logger->warn($ex->getMessage());
     }
 }
Example #2
0
 /**
  * Recognize a Route Based on the Request.
  *
  * @param Request request the Request
  * @return ActionController
  * @throws RoutingEception
  */
 public static function recognize(Request $request)
 {
     $r = new ActionControllerRouting($request);
     try {
         $route = $r->findRoute($request);
         return $route->createControllerInstance($request);
     } catch (RoutingException $rEx) {
         // exception thrown by findRoute if we dont match any of the registered route.
         // load 404 route, if fails too try the default route, this are named routes.
         // echo $rEx;
         try {
             return Map::getInstance()->getRouteByName(Route::NOTFOUND)->createControllerInstance($request);
         } catch (RoutingException $rEx2) {
             return Map::getInstance()->getRouteByName(Route::WELCOME)->createControllerInstance($request);
         }
     }
 }