Exemplo n.º 1
0
 public static function init()
 {
     /*
      * Zuordnung der Prozessart
      * -> Unterscheidung zwischen CLI-
      * und Browser-Aufruf
      */
     self::$proc = "browser";
     if (defined('STDIN')) {
         self::$proc = "cli";
     }
     self::$config_file = ROOT_DIR . "etc/config.php";
     if (!file_exists(self::$config_file)) {
         throw new Exception("Konfigurations-Datei " . self::$config_file . " nicht gefunden!");
     } else {
         require_once self::$config_file;
     }
     /*
      * Zuordnung der Konfigurations-Werte
      */
     self::$debug = $debug;
     self::$debug_file = $debug_file;
     self::$web_root = $web_root;
     self::$db_host = $db_host;
     self::$db_name = $db_name;
     self::$db_user = $db_user;
     self::$db_pass = $db_pass;
     debug::init();
     // debug::add_info("(" . __FILE__ . ")<b>" . __CLASS__ . "</b>::" . __FUNCTION__ . "(): Konfigurations-Datei eingelesen.");
 }
Exemplo n.º 2
0
 /**
  * Configure the system and display the theme
  * 
  * @param  string $config_file Custom path to the config file
  * @return void
  */
 public static function init($config_file = '')
 {
     if (empty($config_file)) {
         self::$config_file = __DIR__ . '/../config.php';
     }
     self::$error = new error();
     self::$config = self::_get_config($config_file);
     self::_check_config(self::$config);
     self::set_vars(self::$config);
     debug::init();
     self::update_check();
     theme::init();
     theme::display();
 }
Exemplo n.º 3
0
 /**
  * Run application
  * 
  * @param array $options
  *		string application_name
  *		string application_path
  *		string ini_folder
  *		boolean __run_only_bootstrap
  * @throws Exception
  */
 public static function run($options = [])
 {
     // fixing location paths
     $application_path = isset($options['application_path']) ? rtrim($options['application_path'], '/') . '/' : '../application/';
     $application_name = isset($options['application_name']) ? $options['application_name'] : 'default';
     $ini_folder = isset($options['ini_folder']) ? rtrim($options['ini_folder'], '/') . '/' : $application_path . 'config/';
     // working directory is location of the application
     chdir($application_path);
     $application_path_full = getcwd();
     // setting include_path
     $paths = [];
     $paths[] = $application_path_full;
     $paths[] = __DIR__;
     $paths[] = str_replace('/numbers/framework', '', __DIR__);
     set_include_path(implode(PATH_SEPARATOR, $paths));
     // support functions
     require "functions.php";
     // load ini settings
     self::$settings = system_config::load($ini_folder);
     // special handling of media files for development, so there's no need to redeploy application
     if (self::$settings['environment'] == 'development' && isset($_SERVER['REQUEST_URI'])) {
         system_media::serve_media_if_exists($_SERVER['REQUEST_URI'], $application_path);
     }
     // we need to solve chicken and egg problem so we load cache first and then run application
     //cache::create('php', array('type'=>'php', 'dir'=>'../application/cache'));
     // setting variables
     if (!isset(self::$settings['application']) || !is_array(self::$settings['application'])) {
         self::$settings['application'] = [];
     }
     self::$settings['application']['name'] = $application_name;
     self::$settings['application']['path'] = $application_path;
     self::$settings['application']['path_full'] = $application_path_full . '/';
     self::$settings['application']['loaded_classes'] = [];
     // class paths
     self::$settings['layout'] = [];
     // layout settings
     // flags
     self::$settings['flag'] = isset(self::$settings['flag']) && is_array(self::$settings['flag']) ? self::$settings['flag'] : [];
     self::$settings['flag']['global']['__run_only_bootstrap'] = !empty($options['__run_only_bootstrap']);
     // magic variables processed here
     self::$settings['flag']['global']['__content_type'] = 'text/html';
     self::process_magic_variables();
     // processing php settings
     if (isset(self::$settings['php'])) {
         foreach (self::$settings['php'] as $k => $v) {
             if (is_array($v)) {
                 foreach ($v as $k2 => $v2) {
                     if (is_numeric($v2)) {
                         $v2 = $v2 * 1;
                     }
                     ini_set($k . '.' . $k2, $v2);
                 }
             } else {
                 if (is_numeric($v)) {
                     $v = $v * 1;
                 }
                 ini_set($k, $v);
             }
         }
     }
     // Destructor
     register_shutdown_function(array('bootstrap', 'destroy'));
     // error handler first
     error_base::init();
     // debug after error handler
     debug::init(self::get('debug'));
     // Bootstrap Class
     $bootstrap = new bootstrap();
     $bootstrap_methods = get_class_methods($bootstrap);
     foreach ($bootstrap_methods as $method) {
         if (strpos($method, 'init') === 0) {
             call_user_func(array($bootstrap, $method), $options);
         }
     }
     // if we are calling application from the command line
     if (!empty($options['__run_only_bootstrap'])) {
         // dispatch before, in case if we open database connections in there
         if (!empty(self::$settings['application']['dispatch']['before_controller'])) {
             call_user_func(self::$settings['application']['dispatch']['before_controller']);
         }
         return;
     }
     // processing mvc settings
     self::set_mvc();
     // check if controller exists
     if (!file_exists(self::$settings['mvc']['controller_file'])) {
         throw new Exception('Resource not found!', -1);
     }
     // initialize the controller
     $controller_class = self::$settings['mvc']['controller_class'];
     $controller = new $controller_class();
     self::$settings['controller'] = get_object_vars($controller);
     // dispatch before, we need some settings from the controller
     if (!empty(self::$settings['application']['dispatch']['before_controller'])) {
         call_user_func(self::$settings['application']['dispatch']['before_controller']);
     }
     // singleton start
     if (!empty(self::$settings['controller']['singleton_flag'])) {
         $message = !empty(self::$settings['controller']['singleton_message']) ? self::$settings['controller']['singleton_message'] : 'This script is being run by another user!';
         $lock_id = "singleton_" . $controller_class;
         if (lock::process($lock_id) === false) {
             throw new Exception($message);
         }
     }
     // process parameters and provide output
     self::process();
     // release singleton lock
     if (!empty(self::$settings['controller']['singleton_flag'])) {
         lock::release($lock_id);
     }
     // dispatch after controller
     if (!empty(self::$settings['application']['dispatch']['after_controller'])) {
         call_user_func(self::$settings['application']['dispatch']['after_controller']);
     }
     // headers
     if (!empty(self::$settings['header']) && !headers_sent()) {
         foreach (self::$settings['header'] as $k => $v) {
             header($v);
         }
     }
 }