wudi

Astrology PHP 框架

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 extends Kernel
{
    public function __construct()
    {
        $this->loadConfig();    
        $this->initRoute();     
        $this->loadController();
    }
 
    public function loadConfig()
    {
        $GLOBALS['CONFIG'] = include_once APP_ROOT . '/config.php';
 
        /* 这里获取配置中的默认语言、客户端语言... */
        /* 使用 gettext 扩展、没有的话用 PHP 数组代替 */
         
        @$GLOBALS['LANG'] = include_once $directory . "/$locale/LC_MESSAGES/$text_domain.php";
    }
}

 

8、主内核

class Kernel
{
    public function __construct()
    {
        /* REQUEST_URI 修正 */
        /* 开启缓存、php_errormsg 和 php.ini 信息、客户端设备检测 */
    }

public function initRoute() { /* 默认路由设置 */ /* 从 REQUEST_URI、PATH_INFO、QUERY_STRING(m, c, a 或 r)获取路由信息 */ /* 匹配路由规则 */ /* 模块和控制器异常处理 */ } public function loadController() { /* 添加 Composer 加载规则 */ /* 检测模块和控制器、引入控制器 */ } }

 

9、控制器原型

class Controller
{
    public function __construct()
    {
        /* 设置动作方法 */
        /* 是否开启 session */
    }

    public function run($method = null)
    {
        /* 执行方法 */
    }

    public function _NotFound()
    {
        /* 全局未找到动作 */
    }

    public function _redirect($url = '/', $second = null, $prefix = null)
    {
        /* 几种重定向 */
    }

    public function __destruct()
    {
        /* 是否自动运行 */
        /* 是否渲染页面 */
        /* 输出格式 */
    }
}

 

posted on 2018-03-04 22:06  wudi  阅读(275)  评论(0编辑  收藏  举报

导航