CogdIgniter4

CodeIgniter4 - 启动流程

2019-06-23  本文已影响0人  三笠丶阿尔曼

CodeIgniter 是一个小巧但功能强大的 PHP 框架,作为一个简单而“优雅”的工具包,它可以为开发者们建立功能完善的 Web 应用程序。
来自CodeIgniter中国的介绍

CodeIgniter 是一个轻量级、快速、灵活和安全的PHP全栈Web框架。
CodeIgniter4 是一个完整的重写,将质量和代码带入一个更现代的版本,同时仍然保持着许多完整的东西
来自CodeIgniter4 Github的介绍


CodeIgniter4 启动流程分析

个人阅读笔记,仅作参考,若有错误后续改正

简要说明

  1. 入口文件index.php进行一些初始化动作
  2. 调用框架引导文件System\bootstrap.php预定义常量及加载相关类库,然后对CodeIgniter\CodeIgniter进行初始化并返回
  3. 调用CodeIgniter\CodeIgniter->run()执行主流程并返回响应结果

入口文件 - public\index.php

框架引导文件 - System\bootstrap.php

引导文件主要做了以下几件事

预定义常量

路径相关常量
项目常量

加载类库

初始化核心框架类CI

        return static::getSharedInstance('exceptions', $config, $request, $response);
        //Set the Exception Handler
        set_exception_handler([$this, 'exceptionHandler']);

        // Set the Error Handler
        set_error_handler([$this, 'errorHandler']);

        // Set the handler for shutdown to catch Parse errors
        // Do we need this in PHP7?
        register_shutdown_function([$this, 'shutdownHandler']);

执行主流程 - CI->run()

        $this->handleRequest($routes, $cacheConfig, $returnResponse);

处理请求 - CI->handleRequest()

$_SESSION['_ci_previous_url'] = (string) $uri;
上一篇 下一篇

猜你喜欢

热点阅读