-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make this repo submodule compatible, remove app/, move sys/* to /
- Loading branch information
1 parent
c8a4882
commit dc280e9
Showing
17 changed files
with
105 additions
and
164 deletions.
There are no files selected for viewing
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,107 @@ | ||
<?php | ||
// On developement | ||
ini_set('display_errors', 1); | ||
// On production | ||
//ini_set('display_errors', 0); | ||
error_reporting(E_ALL); | ||
|
||
require('sys/index.php'); | ||
if (!defined('APPPATH')) { | ||
define('APPPATH', realpath(dirname(__FILE__) . '/../app' ). '/'); | ||
} | ||
define('SYSPATH', realpath(dirname(__FILE__) . '/') . '/'); | ||
|
||
/* | ||
* Require app config | ||
*/ | ||
$app_cfg_file = APPPATH . 'config.php'; | ||
if (is_file($app_cfg_file)) { | ||
include(APPPATH . 'config.php'); | ||
} | ||
|
||
/* | ||
* Set unset configs | ||
*/ | ||
if (!isset($cfg) || !is_array($cfg)) { | ||
$cfg = array(); | ||
} | ||
$default_cfg = array( | ||
'default_controller' => 'hello', | ||
'default_method' => 'index', | ||
|
||
'base_url' => '', | ||
|
||
'db_host' => '', | ||
'db_user' => '', | ||
'db_pass' => '', | ||
'db_name' => '', | ||
); | ||
foreach ($default_cfg as $key => $value) { | ||
if (empty($cfg[$key])) { | ||
$cfg[$key] = $value; | ||
} | ||
} | ||
|
||
/* | ||
* Set $_base_url | ||
*/ | ||
if (empty($cfg['base_url'])) { | ||
$_REQUEST_SCHEME = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') ? 'https' : 'http'; | ||
$_PATH = dirname($_SERVER['SCRIPT_NAME']); | ||
if (substr($_PATH, -1) != '/') $_PATH .= '/'; | ||
$_base_url = $_REQUEST_SCHEME.'://'.$_SERVER['HTTP_HOST'].$_PATH; | ||
} | ||
else { | ||
$_base_url = $cfg['base_url']; | ||
} | ||
|
||
/* | ||
* Helper implementation | ||
*/ | ||
function load_helper($helper) { | ||
$helper_file = APPPATH . 'helpers/'.$helper.'.php'; | ||
if (is_file($helper_file)) { | ||
include_once($helper_file); | ||
} | ||
else { | ||
include_once(SYSPATH . 'helpers/'.$helper.'.php'); | ||
} | ||
} | ||
|
||
/* | ||
* Load common helpers | ||
*/ | ||
load_helper('base_url'); | ||
|
||
/* | ||
* Load system | ||
*/ | ||
require(SYSPATH . 'router.php'); | ||
require(SYSPATH . 'controller.php'); | ||
require(SYSPATH . 'model.php'); | ||
require(SYSPATH . 'library.php'); | ||
|
||
/* | ||
* Understand URL and decompose route | ||
*/ | ||
$router = new Router(empty($_SERVER['PATH_INFO']) ? '' : $_SERVER['PATH_INFO']); | ||
$controller = $router->get_controller(); | ||
$method = $router->get_method(); | ||
$args = $router->get_args(); | ||
|
||
/* | ||
* Load requested controller | ||
*/ | ||
$not_found = true; | ||
|
||
$controller_file = APPPATH . 'controllers/'.$controller.'.php'; | ||
if (file_exists($controller_file) && is_readable($controller_file)) { | ||
include($controller_file); | ||
$a=new $controller; | ||
|
||
if (method_exists($a, $method)) { | ||
$not_found = false; | ||
call_user_func_array( array( $a, $method ), $args ); | ||
} | ||
} | ||
|
||
if ($not_found) { | ||
header('HTTP/1.0 404 Not Found'); | ||
new View('404'); | ||
exit(); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.