shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

framework.php (4501B)


      1 <?php
      2 // Registry
      3 $registry = new Registry();
      4 
      5 // Config
      6 $config = new Config();
      7 $config->load('default');
      8 $config->load($application_config);
      9 $registry->set('config', $config);
     10 
     11 // Log
     12 $log = new Log($config->get('error_filename'));
     13 $registry->set('log', $log);
     14 
     15 date_default_timezone_set($config->get('date_timezone'));
     16 
     17 set_error_handler(function($code, $message, $file, $line) use($log, $config) {
     18 	// error suppressed with @
     19 	if (error_reporting() === 0) {
     20 		return false;
     21 	}
     22 
     23 	switch ($code) {
     24 		case E_NOTICE:
     25 		case E_USER_NOTICE:
     26 			$error = 'Notice';
     27 			break;
     28 		case E_WARNING:
     29 		case E_USER_WARNING:
     30 			$error = 'Warning';
     31 			break;
     32 		case E_ERROR:
     33 		case E_USER_ERROR:
     34 			$error = 'Fatal Error';
     35 			break;
     36 		default:
     37 			$error = 'Unknown';
     38 			break;
     39 	}
     40 
     41 	if ($config->get('error_display')) {
     42 		echo '<b>' . $error . '</b>: ' . $message . ' in <b>' . $file . '</b> on line <b>' . $line . '</b>';
     43 	}
     44 
     45 	if ($config->get('error_log')) {
     46 		$log->write('PHP ' . $error . ':  ' . $message . ' in ' . $file . ' on line ' . $line);
     47 	}
     48 
     49 	return true;
     50 });
     51 
     52 // Event
     53 $event = new Event($registry);
     54 $registry->set('event', $event);
     55 
     56 // Event Register
     57 if ($config->has('action_event')) {
     58 	foreach ($config->get('action_event') as $key => $value) {
     59 		foreach ($value as $priority => $action) {
     60 			$event->register($key, new Action($action), $priority);
     61 		}
     62 	}
     63 }
     64 
     65 // Loader
     66 $loader = new Loader($registry);
     67 $registry->set('load', $loader);
     68 
     69 // Request
     70 $registry->set('request', new Request());
     71 
     72 // Response
     73 $response = new Response();
     74 $response->addHeader('Content-Type: text/html; charset=utf-8');
     75 $response->setCompression($config->get('config_compression'));
     76 $registry->set('response', $response);
     77 
     78 // Database
     79 if ($config->get('db_autostart')) {
     80 	$registry->set('db', new DB($config->get('db_engine'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port')));
     81 }
     82 
     83 // Session
     84 $session = new Session($config->get('session_engine'), $registry);
     85 $registry->set('session', $session);
     86 
     87 if ($config->get('session_autostart')) {
     88 	/*
     89 	We are adding the session cookie outside of the session class as I believe
     90 	PHP messed up in a big way handling sessions. Why in the hell is it so hard to
     91 	have more than one concurrent session using cookies!
     92 
     93 	Is it not better to have multiple cookies when accessing parts of the system
     94 	that requires different cookie sessions for security reasons.
     95 
     96 	Also cookies can be accessed via the URL parameters. So why force only one cookie
     97 	for all sessions!
     98 	*/
     99 
    100 	if (isset($_COOKIE[$config->get('session_name')])) {
    101 		$session_id = $_COOKIE[$config->get('session_name')];
    102 	} else {
    103 		$session_id = '';
    104 	}
    105 
    106 	$session->start($session_id);
    107 
    108 	setcookie($config->get('session_name'), $session->getId(), ini_get('session.cookie_lifetime'), ini_get('session.cookie_path'), ini_get('session.cookie_domain'));
    109 }
    110 
    111 // Cache
    112 $registry->set('cache', new Cache($config->get('cache_engine'), $config->get('cache_expire')));
    113 
    114 // Url
    115 if ($config->get('url_autostart')) {
    116 	$registry->set('url', new Url($config->get('site_url'), $config->get('site_ssl')));
    117 }
    118 
    119 // Language
    120 $language = new Language($config->get('language_directory'));
    121 $registry->set('language', $language);
    122 
    123 // OpenBay Pro
    124 $registry->set('openbay', new Openbay($registry));
    125 
    126 // Document
    127 $registry->set('document', new Document());
    128 
    129 // Config Autoload
    130 if ($config->has('config_autoload')) {
    131 	foreach ($config->get('config_autoload') as $value) {
    132 		$loader->config($value);
    133 	}
    134 }
    135 
    136 // Language Autoload
    137 if ($config->has('language_autoload')) {
    138 	foreach ($config->get('language_autoload') as $value) {
    139 		$loader->language($value);
    140 	}
    141 }
    142 
    143 // Library Autoload
    144 if ($config->has('library_autoload')) {
    145 	foreach ($config->get('library_autoload') as $value) {
    146 		$loader->library($value);
    147 	}
    148 }
    149 
    150 // Model Autoload
    151 if ($config->has('model_autoload')) {
    152 	foreach ($config->get('model_autoload') as $value) {
    153 		$loader->model($value);
    154 	}
    155 }
    156 
    157 // Route
    158 $route = new Router($registry);
    159 
    160 // Pre Actions
    161 if ($config->has('action_pre_action')) {
    162 	foreach ($config->get('action_pre_action') as $value) {
    163 		$route->addPreAction(new Action($value));
    164 	}
    165 }
    166 
    167 // Dispatch
    168 $route->dispatch(new Action($config->get('action_router')), new Action($config->get('action_error')));
    169 
    170 // Output
    171 $response->output();