<?php
/**
* 主入口文件后台和前台必须先进入这个文件
* 载入启动类(/system/startup.php)
*/
// Error Reporting 错误报告
error_reporting(E_ALL);
// Check Version 检查php版本
if (version_compare(phpversion(), '5.4.0', '<') == true) {
exit('PHP5.4+ Required');
}
// Magic Quotes Fix 魔术引号修复
if (ini_get('magic_quotes_gpc')) {
function clean($data) {
if (is_array($data)) {
foreach ($data as $key => $value) {
$data[clean($key)] = clean($value);
}
} else {
$data = stripslashes($data);
}
return $data;
}
$_GET = clean($_GET);
$_POST = clean($_POST);
$_COOKIE = clean($_COOKIE);
}
/**
* ini_get 检查环境变量值
* date_default_timezone_set设置默认时区
*/
if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
/**
* Windows IIS Compatibility iis兼容设置
* ($_SERVER['DOCUMENT_ROOT']:获取当前运行脚本所在的文档根目录
* $_SERVER['SCRIPT_FILENAME']指向当前执行脚本的绝对路径
* ($_SERVER['PHP_SELF']:获取当前页面地址
*/
if (!isset($_SERVER['DOCUMENT_ROOT'])) {
if (isset($_SERVER['SCRIPT_FILENAME'])) {
$_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF'])));
}
}
/**
* $_SERVER['PATH_TRANSLATED']
* 当前 PHP 程序所在文件系统(不是文档根目录)的基本路径
*/
if (!isset($_SERVER['DOCUMENT_ROOT'])) {
if (isset($_SERVER['PATH_TRANSLATED'])) {
$_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 - strlen($_SERVER['PHP_SELF'])));
}
}
/**
* $_SERVER['REQUEST_URI']
*访问此页面所需的 URI
* $_SERVER['QUERY_STRING']
* 获取查询 语句,实例中可知,获取的是?后面的值
*/
if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);
if (isset($_SERVER['QUERY_STRING'])) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
}
/**
*$_SERVER['HTTP_HOST']
* 来获得URL中网站的域名或者ip地址
* getenv('HTTP_HOST')
* 从主机获取域名,
*/
if (!isset($_SERVER['HTTP_HOST'])) {
$_SERVER['HTTP_HOST'] = getenv('HTTP_HOST');
}
// Check if SSL
/**
* 判断是否启用ssl访问
* $_SERVER['HTTPS']
* 如果通过https访问,则被设为一个非空的值(on),否则返回off
* $_SERVER['SERVER_PORT']
* 服务器所使用的端口
* $_SERVER['HTTP_X_FORWARDED_PROTO']
* 判断http头还是https头
*/
if ((isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) || $_SERVER['SERVER_PORT'] == 443) {
$_SERVER['HTTPS'] = true;
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$_SERVER['HTTPS'] = true;
} else {
$_SERVER['HTTPS'] = false;
}
// Modification Override
/**
* 重写修改
* @param $filename 完整路径
* @return string 返回
* defined 定义常量
* is_file() 函数检查指定的文件名是否是正常的文件
*/
function modification($filename) {
if (defined('DIR_CATALOG')) {
$file = DIR_MODIFICATION . 'admin/' . substr($filename, strlen(DIR_APPLICATION));
} elseif (defined('DIR_OPENCART')) {
$file = DIR_MODIFICATION . 'install/' . substr($filename, strlen(DIR_APPLICATION));
} else {
$file = DIR_MODIFICATION . 'catalog/' . substr($filename, strlen(DIR_APPLICATION));
}
if (substr($filename, 0, strlen(DIR_SYSTEM)) == DIR_SYSTEM) {
$file = DIR_MODIFICATION . 'system/' . substr($filename, strlen(DIR_SYSTEM));
}
if (is_file($file)) {
return $file;
}
return $filename;
}
// Autoloader 自动加载文件
if (is_file(DIR_SYSTEM . '../../vendor/autoload.php')) {
require_once(DIR_SYSTEM . '../../vendor/autoload.php');
}
/**
* @param $class
* @return bool
* 加载类文件函数
*/
function library($class) {
$file = DIR_SYSTEM . 'library/' . str_replace('\\', '/', strtolower($class)) . '.php';
if (is_file($file)) {
include_once(modification($file));
return true;
} else {
return false;
}
}
/*
* spl_autoload_register注册给定的函数作为 __autoload 的实现
* spl_autoload_extensions声明查找的文件的扩展名列表
* 核心类system/library /
*/
spl_autoload_register('library');
spl_autoload_extensions('.php');
// Engine 封装使用函数类 程序引擎system/engine /
require_once(modification(DIR_SYSTEM . 'engine/action.php')); //
require_once(modification(DIR_SYSTEM . 'engine/controller.php')); //
require_once(modification(DIR_SYSTEM . 'engine/event.php')); //
require_once(modification(DIR_SYSTEM . 'engine/front.php'));
require_once(modification(DIR_SYSTEM . 'engine/loader.php'));
require_once(modification(DIR_SYSTEM . 'engine/model.php'));
require_once(modification(DIR_SYSTEM . 'engine/registry.php'));
require_once(modification(DIR_SYSTEM . 'engine/proxy.php'));
// Helper 帮助类型加载
require_once(DIR_SYSTEM . 'helper/general.php'); // 其他处理
require_once(DIR_SYSTEM . 'helper/utf8.php'); //转码使用的
require_once(DIR_SYSTEM . 'helper/json.php'); //处理json字符串
//进入system/framework.php
function start($application_config) {
require_once(DIR_SYSTEM . 'framework.php');
}