Exemplo n.º 1
0
 /**
  * Starts the application.
  * 
  * @return void
  */
 public static function run()
 {
     self::$starttime = microtime(true);
     error_reporting(config::ERROR_LEVEL);
     if (isset(config::$session_cookie_domain)) {
         ini_set('session.cookie_domain', config::$session_cookie_domain);
     }
     if (class_exists('formHelper')) {
         formHelper::fixArrays();
     }
     if (class_exists('csrfHelper')) {
         injector::register(array('csrfHelper', 'injector'));
     }
     if (is::ssl() && isset(config::$https_domain) && !isset(config::$http_domain)) {
         if (is::existset($_GET, 'r_domain')) {
             config::$http_domain = get::fulldomain($_GET['r_domain']);
         } else {
             config::$http_domain = get::fulldomain('www');
         }
     }
     session_start();
     if (config::$isolated_subdomains) {
         // find the domain
         $domain = isset(config::$http_domain) ? config::$http_domain : get::fulldomain();
         // kill any subdomain sessions that have been transfered to another subdomain
         $existing = array_keys($_SESSION);
         foreach ($existing as $d) {
             if (!is_array($_SESSION[$d])) {
                 continue;
             }
             if (array_key_exists('kill_munla_session', $_SESSION[$d]) && $_SESSION[$d]['kill_munla_session']) {
                 unset($_SESSION[$d]);
             }
         }
         // initialize and setup the session for this subdomain
         if (!array_key_exists($domain, $_SESSION)) {
             $_SESSION[$domain] = array();
         }
         munla::$session =& $_SESSION[$domain];
     } else {
         munla::$session =& $_SESSION;
     }
     if (class_exists('singleUseArray')) {
         if (!is::existset(munla::$session, 'MUNLA_SINGLE_USE')) {
             munla::$singleUse = new singleUseArray();
         } else {
             munla::$singleUse = unserialize(munla::$session['MUNLA_SINGLE_USE']);
         }
     }
     $route = get::route();
     if (is_array($route) && $route['controller'] == 'csrf' && $route['action'] == 'keepalive' && class_exists('csrfHelper') && is::existset($route, 'params') && count($route['params']) > 0) {
         if (isset($_POST['token'])) {
             echo csrfHelper::keepAlive($route['params'][0], $_POST['token']);
         }
         exit;
     }
     if (class_exists('user') && is_subclass_of('user', 'userBase')) {
         if (!is::existset(munla::$session, 'MUNLA_USER')) {
             munla::$session['MUNLA_USER'] = new userWrapper(new user());
         }
     }
     injector::start();
     if (class_exists('app') && is_callable(array('app', 'setup'))) {
         app::setup();
     }
     if (!isset(munla::$user) && is::existset(munla::$session, 'MUNLA_USER')) {
         munla::$user =& munla::$session['MUNLA_USER'];
     }
     if (!is::ajax()) {
         $submittedForm = formHelper::process();
         if (isset($submittedForm)) {
             formHelper::process($submittedForm);
         }
     }
     if (class_exists('app') && is_callable(array('app', 'start'))) {
         $route = app::start($route);
     }
     if ($route === null) {
         $route = array('controller' => 'index', 'action' => 'index', 'params' => null);
     }
     $controller = get::controller($route['controller']);
     if (!isset($controller) && $route['controller'] != 'index') {
         //push action to params, controller to action, and set controller to index and try again.
         if ($route['action'] != 'index') {
             if (!isset($route['params'])) {
                 $route['params'] = array();
             }
             array_unshift($route['params'], $route['action']);
         }
         $route['action'] = $route['controller'];
         $route['controller'] = 'index';
         $controller = get::controller('index');
     }
     $view = null;
     if (isset($controller)) {
         $action = $controller->getAction(array($route['action'], $route['params']));
         if (isset($action)) {
             try {
                 $viewParams = call_user_func_array(array($controller, $action['action']), $action['params']);
                 //various things could happen here...
                 if (!isset($viewParams)) {
                     $viewParams = array();
                 } elseif (!is_array($viewParams)) {
                     $viewParams = array($viewParams);
                 }
                 $view = get::view($route, $controller, $viewParams);
             } catch (SSLException $e) {
                 go::ssl(!is::ssl());
             } catch (PermissionException $e) {
                 munla::$nohistory = true;
                 if (isset(munla::$user) && !munla::$user->is_logged_in() && munla::$user->getLoginView()) {
                     $view = munla::$user->getLoginView();
                 } else {
                     $view = get::view('errors/generic', 'default', array('error_msg' => $e->getMessage()));
                 }
             } catch (Exception $e) {
                 munla::$nohistory = true;
                 $view = get::view('errors/generic', 'default', array('error_msg' => $e->getMessage()));
             }
         } else {
             $view = get::view($route, $controller);
         }
     } else {
         $view = get::view($route);
     }
     if ($view != null) {
         $view->render();
     } else {
         throw new Exception('View not found!');
     }
     if (class_exists('app', false)) {
         munla::$nohistory = app::finish(munla::$nohistory);
     }
     if (munla::$nohistory === false) {
         munla::$session['lastpage'] = get::url();
     }
     if (isset(munla::$singleUse)) {
         munla::$session['MUNLA_SINGLE_USE'] = serialize(munla::$singleUse);
     }
 }
Exemplo n.º 2
0
<?php

//loader
include 'component/loader/psr.php';
$loader = new component\loader\psr();
$loader->add(__DIR__, true);
$loader->register(true);
//locator
$classmap = new component\registry\apc('classmap');
$version = filemtime(__DIR__ . '/classmap.php');
if ($classmap->version != $version) {
    include __DIR__ . '/classmap.php';
    $classmap->version = $version;
}
$locator = new component\locator\_default($classmap);
//injector
class_alias('component\\injector\\_default', 'injector');
injector::inject($locator);
return $locator;