Exemplo n.º 1
0
 /**
  * End session
  */
 public static function end()
 {
     foreach ($_SESSION['flashdata'] as $name => $data) {
         unset($_SESSION['flashdata'][$name]);
     }
     WFEsession::setFlashdata(array('last_page_uri' => WFERouter::getCurrentRequest()->getURI()));
 }
Exemplo n.º 2
0
 /**
  * Instanciate a new WFERequest
  * @param String $method Whether GET or POST
  * @param String $routeName Route's name corresponding to the request
  * @param Array $params Paramters of the request
  * @param Boolean $forceNesting Allows to force a request to be send inside the corresponding route controller (May produce an infinit loop)
  * @throws WFERequestException
  */
 function __construct($method = null, $routeName = null, $params = null, $forceNesting = false)
 {
     if (is_string($method)) {
         $this->method = $method;
     } else {
         $this->method = $_SERVER['REQUEST_METHOD'];
     }
     if (is_string($routeName)) {
         $this->route = WFERoute::get($routeName);
     } else {
         switch ($this->method) {
             case 'POST':
                 self::initPOST();
                 break;
             case 'GET':
                 self::initGET();
                 break;
             default:
                 break;
         }
     }
     if (!$forceNesting && $this->route != null && $this->route->getName() == WFERouter::getCurrentRoute()) {
         throw new WFERequestException('You cannot request a route inside the controller\'s action linked to this route (avoid infinit loop)');
     }
     if (is_array($params)) {
         $this->params = $params;
     }
 }
Exemplo n.º 3
0
 public function home()
 {
     $response = WFERouter::run(new WFERequest('GET', 'do', array('parameter' => 'BLA')));
     $response = new WFEResponse();
     $response->setContent(WFETemplate::render());
     return $response;
 }
Exemplo n.º 4
0
 public function img($img)
 {
     $response = new WFEResponse();
     try {
         $response->setContent(WFELoader::content('public/img/' . $img));
     } catch (WFEFileNotFoundException $e) {
         WFERouter::run404();
     }
     $response->setFormat('image/' . pathinfo($img, PATHINFO_EXTENSION));
     return $response;
 }
 public static function getCurrentRoutePath($array, $smarty)
 {
     $route = WFERouter::getCurrentRequest()->getRoute();
     return $route->injectParams(WFERouter::getCurrentRequest()->getArguments());
 }
Exemplo n.º 6
0
 /**
  * Alias to re-routes to a 500 error page
  */
 public static function run500()
 {
     $response = WFERouter::run(new WFERequest('GET', 'WFE500'));
     $response->send();
 }
Exemplo n.º 7
0
 /**
  * Get default template
  * @return String
  */
 private static function defaultTemplate()
 {
     $controller_segs = explode('/', WFERouter::getCurrentController());
     $dir = $controller_segs[sizeof($controller_segs) - 1];
     return $dir . '/' . WFERouter::getCurrentAction() . '.tpl';
 }
Exemplo n.º 8
0
set_exception_handler(function (Exception $e) {
    if (WFEConfig::get('env') == 'dev') {
        exit($e->getMessage());
    } elseif (WFEConfig::get('env') == 'prod') {
        $response = WFERouter::run(new WFERequest('GET', 'WFE500'));
        $response->send();
    }
});
// Register autoload
WFEAutoload::register(__NAMESPACE__);
// Load main config
WFELoader::load('app/config/config.php');
// Load Database
\core\ORM\WFEDb::connect();
// Load smarty
WFELoader::load('core/libs/smarty/Smarty.class.php');
// set environment spec
if (WFEConfig::get('env') == 'dev') {
    error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE | E_ALL);
} elseif (WFEConfig::get('env') == 'prod') {
    error_reporting(0);
} else {
    throw new WFEDefinitionException('Config settings env is not set properly (must be dev or prod)');
}
// init session
WFEsession::init();
// init request data
$request = new WFERequest();
// Routes request and get response
WFERouter::run($request);