예제 #1
0
 /**
  * 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());
     }
 }
예제 #2
0
 /**
  * Act as an internal constructor.
  * 
  * @param Request request, the request
  * @param Response response, the response
  */
 private function instantiate(Request $request, Response $response)
 {
     // class memebers
     $this->request = $request;
     $this->response = $response;
     $this->params = $request->getParameters();
     $this->logger = Registry::get('__logger');
     $this->injector = Registry::get('__injector');
     $this->config = Registry::get('__configurator');
     $this->session = $request->getSession();
     $this->app_path = $this->injector->getPath('__base');
     $this->template_root = $this->injector->getPath('views') . $this->params['controller'] . DIRECTORY_SEPARATOR;
     $this->template = ActionView::factory('php');
     // register session container if any
     // TODO: this should be moved elsewhere
     if ($this->config->getWebContext()->session !== NULL && $this->config->getWebContext()->session->container !== NULL) {
         // container location.
         $c_location = str_replace('.', DIRECTORY_SEPARATOR, (string) $this->config->getWebContext()->session->container) . '.php';
         include_once $c_location;
         // container class name.
         $e = explode('.', (string) $this->config->getWebContext()->session->container);
         // reflect on container.
         $container = new ReflectionClass(end($e));
         if ($container->implementsInterface('ISessionContainer')) {
             $this->session->setContainer($container->newInstance());
         }
     }
     // predefined variables:
     // TODO: check if we have a / at the end, if not, add one
     $this->template->assign('__base', (string) $this->config->getWebContext()->document_root);
     $this->template->assign('__server', (string) $this->config->getWebContext()->server_name);
     $this->template->assign('__controller', $this->params['controller']);
     $this->template->assign('__version', Medick::getVersion());
     $this->template->assign('__self', $this->__base . $this->request->getRequestUri());
     $this->logger->debug($this->request->toString());
 }