示例#1
0
 private static function initialize()
 {
     $config_path = \My\Env::get('config_path') . 'config.php';
     if (!file_exists($config_path)) {
         throw new Exception_config_file_not_found('File not found: ' . $config_path);
     }
     include $config_path;
     if (isset($configuration) && is_array($configuration)) {
         self::$data = $configuration;
     } else {
         throw new Exception_config_empty('Configfile has no $configuration array set');
     }
     // domain specific configuration
     $config_path = \My\Env::get('config_path') . 'config.' . \My\Env::get('domain') . '.php';
     if (file_exists($config_path)) {
         unset($configuration);
         include $config_path;
         if (isset($configuration) && is_array($configuration)) {
             foreach ($configuration as $key => $value) {
                 self::$data[$key] = $value;
             }
         }
     }
     self::$initialized = true;
 }
示例#2
0
 public static function run()
 {
     // default request when no path information is provided
     $request = ['http_method' => strtolower($_SERVER['REQUEST_METHOD']), 'class' => 'index', 'method' => 'index', 'params' => []];
     // extract request routing
     if (array_key_exists('PATH_INFO', $_SERVER)) {
         $path_tmp = $_SERVER['PATH_INFO'];
         if (substr($path_tmp, 0, 1) == '/') {
             $path_tmp = substr($path_tmp, 1);
         }
         $path = explode('/', $path_tmp);
         if (isset($path[0])) {
             $request['class'] = $path[0];
         }
         if (isset($path[1])) {
             $request['method'] = $path[1];
         }
         if (count($path > 2)) {
             $request['params'] = array_slice($path, 2);
         }
     }
     \My\Env::set('request', $request);
     // find controller class path and check if it exists
     $class_path = \My\Env::get('controller_path') . $request['class'] . '.ctrl.php';
     #@TODO replace with nice 404 handling
     if (!file_exists($class_path)) {
         die('404 controller "' . $request['class'] . '" not found');
     }
     // load class
     require_once $class_path;
     $class_name = '\\My\\Controller\\' . $request['class'];
     $controller_instance = new $class_name();
     // check if method exists
     $method_name = $request['http_method'] . '_' . $request['method'];
     #@TODO replace with nice 404 handling
     if (!method_exists($controller_instance, $method_name)) {
         die('404 method "' . $class_name . '::' . $method_name . '" not found');
     }
     // call method as defined by the request
     $result = call_user_func_array([$controller_instance, $method_name], $request['params']);
     // if response is an instance of \My\Response_html execute it
     if ($result instanceof \My\Response_html) {
         $result->exec();
         die;
     } else {
         die($class_name . '::' . $method_name . ' returned something which I have no clue how to handle.');
     }
 }
示例#3
0
文件: main.php 项目: DerBunman/bun-fw
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
		<meta name="description" content="">
		<meta name="author" content="">

		<base href="<?php 
echo \My\Env::get('base_href');
?>
">

		<link rel="icon" href="vendor/bootstrap/favicon.ico">

		<title>Blog Template for Bootstrap</title>

		<!-- Bootstrap core CSS -->
		<link href="vendor/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
		<link href="vendor/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet">

		<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
		<link href="vendor/bootstrap/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

		<!-- Custom styles for this template -->
		<link href="theme.css" rel="stylesheet">

		<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
		<!--[if lt IE 9]><script src="vendor/bootstrap/assets/js/ie8-responsive-file-warning.js"></script><![endif]-->