1、Web 服务器配置
PHP 支持
URL Rewrite、PATH_INFO
2、环境需求
PHP 7.2+
扩展:gettext
3、目录结构
+ src
| - autoload.php
| + Astrology
| - Start.php
| - Kernel.php
| - Controller.php
| - Database.php
| - View.php
| + Anfora
| - Autoload.php
| + Autoload
| - ClassLoader.php
| + DbTable
| + Extension
+ app
| - bootstrap.php
| - config.php
| + Index
| + _App
| + Controller
| - _Controller.php
| - Index.php
| + Model
| + View
| + _Controller
| - _NotFound.php
| - index.mobi..php
| - index.php
| + _helper
| - footer.php
| + _layout
| - default.mobi..php
| - default.php
| + Index
+ web
| - .htaccess
| - index.php
4、入口文件
web/index.php
require_once __DIR__ . '/../app/bootstrap.php';new \Astrology\Start();
5、引导文件
app/bootstrap.php
define('APP_ROOT', realpath(__DIR__));define('ANFORA_AUTOLOAD', 0);if(ANFORA_AUTOLOAD) {require APP_ROOT . '/../src/autoload.php';
}else{require APP_ROOT . '/../vendor/autoload.php';
}include_once 'function.php';
6、自动加载类
src/autoload.php
require_once __DIR__ . '/Anfora/Autoload.php';return Anfora_Autoload::getLoader();
7、运行
src/Astrology/Start.php
class Start extendsKernel
{public function__construct()
{$this->loadConfig();$this->initRoute();$this->loadController();
}public functionloadConfig()
{$GLOBALS['CONFIG'] = include_once APP_ROOT . '/config.php';/*这里获取配置中的默认语言、客户端语言...*/
/*使用 gettext 扩展、没有的话用 PHP 数组代替*/@$GLOBALS['LANG'] = include_once $directory . "/$locale/LC_MESSAGES/$text_domain.php";
}
}
8、主内核
classKernel
{public function__construct()
{/*REQUEST_URI 修正*/
/*开启缓存、php_errormsg 和 php.ini 信息、客户端设备检测*/}public functioninitRoute()
{/*默认路由设置*/
/*从 REQUEST_URI、PATH_INFO、QUERY_STRING(m, c, a 或 r)获取路由信息*/
/*匹配路由规则*/
/*模块和控制器异常处理*/}public functionloadController()
{/*添加 Composer 加载规则*/
/*检测模块和控制器、引入控制器*/}
}
9、控制器原型
classController
{public function__construct()
{/*设置动作方法*/
/*是否开启 session*/}public function run($method = null)
{/*执行方法*/}public function_NotFound()
{/*全局未找到动作*/}public function _redirect($url = '/', $second = null, $prefix = null)
{/*几种重定向*/}public function__destruct()
{/*是否自动运行*/
/*是否渲染页面*/
/*输出格式*/}
}