Esempio n. 1
0
 /**
  * Instanciator for the singleton
  *
  * @param string $route_file
  * @param Application $app;
  * @return Router
  */
 public static function getInstance($route_file = null, $app = null)
 {
     if (!self::$_instance) {
         if (!$app) {
             throw new \Exception("Router needs an Application instance to be initialized.");
         }
         self::$_instance = new Router($app);
         if ($route_file) {
             self::$_instance->load($route_file);
         }
     }
     return self::$_instance;
 }
Esempio n. 2
0
 /**
  * Application constructor. This is the entry point of Calmacil/Mf.
  * @param string $root
  * @param string $env
  */
 public function __construct($root, $env = 'prod')
 {
     parent::__construct($root);
     define('ROOT', $root);
     $this->env = $env;
     $this->cfile = "settings_" . $this->env;
     Config::init(ROOT . '/config/');
     // Loggers
     $rotateHandler = new RotatingFileHandler(ROOT . Config::get($this->cfile)->log->logfile, 10, Config::get($this->cfile)->log->loglevel);
     $processor = new PsrLogMessageProcessor();
     $this->loggers['core'] = new Logger('core');
     $this->loggers['app'] = new Logger('app');
     $this->loggers['core']->pushHandler($rotateHandler);
     $this->loggers['app']->pushHandler($rotateHandler);
     $this->loggers['core']->pushProcessor($processor);
     $this->loggers['app']->pushProcessor($processor);
     if (Config::get($this->cfile)->debug) {
         $browserHandler = new BrowserConsoleHandler();
         $this->loggers['core']->pushHandler($browserHandler);
         $this->loggers['app']->pushHandler($browserHandler);
     }
     $this->coreLogger()->addNotice("============================================================");
     // Session service handling
     if (session_status() !== PHP_SESSION_DISABLED) {
         $this["session"] = new SessionPlugin($this);
     }
     $this->router = Router::getInstance(ROOT . Config::get($this->cfile)->paths->routing_file, $this);
     $this->request = new Request($this, $_SERVER['REQUEST_URI']);
     $this->response = new Response($this);
     $this->coreLogger()->addNotice("------------------------------------------------------------");
     $this->coreLogger()->addNotice("Application initialized.");
 }
Esempio n. 3
0
 public function url($route_name, $params = array())
 {
     return Router::getInstance()->generateRoute($route_name, $params);
 }
Esempio n. 4
0
 /**
  * Redirects the request to the given route. Internal redirect only.
  *
  * @param string $route
  * @param array $options
  * @return bool
  */
 public function redirect($route, $options = array())
 {
     $url = Router::getInstance()->generateRoute($route, $options);
     $this->app->coreLogger()->notice("Redirecting current request to route {route}", ['route' => $route]);
     ob_clean();
     ob_start();
     header("HTTP/1.1 " . self::STATUS_FOUND);
     header("Location: " . $url);
     ob_end_flush();
     return self::TYPE_EXIT;
 }
Esempio n. 5
0
 /**
  * @param \Twig_Environment $env
  * @param mixed $route_name
  * @param mixed $params
  * @return string
  */
 public static function url(\Twig_Environment $env, $route_name, $params = null)
 {
     return Router::getInstance()->generateRoute($route_name, $params);
 }