zoukankan      html  css  js  c++  java
  • [CI]CodeIgniter系统流程

    ------------------------------------------------------------------------------------------------------

    进入框架入口文件index.php =>

    定义应用的当前环境(用于设置错误模式):define('ENVIRONMENT', 'development');

    设置系统文件目录名:$system_path = 'system';

    设置应用文件目录名:$application_folder = 'application';  //可自定义

    定义当前文件名常量:define('SELF', pathinfo(__FILE__, PATHINFO_BASEPATH));

    定义PHP文件后缀常量:define('EXT', '.php');  //这个全局常量不推荐使用

    定义系统目录路径常量:define('BASEPATH', str_replace('\', '/', $system_path));

    定义前端控制器文件路径常量:define('FCPATH', str_replace(SELF, '', __FILE__));

    定义系统目录名常量:define('SYSDIR', trim(strchr(trim(BASEPATH, '/'), '/'), '/'));

    定义应用目录路径常量:define('APPPATH', BASEPATH.$application_folder.'/');

    加载引导文件:require_once BASEPATH.'core/CodeIgniter.php';

    ---------------------------------@黑眼诗人 <www.farwish.com>---------------------------------

    进入系统初始化文件CodeIgniter.php =>

    define('CI_VERSION', '2.2.0');

    define('CI_CORE', FALSE);

    require(BASEPATH.'core/Common.php');   //引入公共函数库文件,包含load_class()等函数

    require(APPPATH.'config/'.ENVIRONMENT.'/constants.php'); //引入框架常量文件,文件和目录模式 & 文件流模式

    set_error_handler('_exception_handler');   //定义一个自定义错误处理程序以便记录PHP错误

    if ( ! is_php('5.3'))
    {
      @set_magic_quotes_runtime(0); // Kill magic quotes
    }

    if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')

    //设置子类前缀
    {
      get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
    }

    if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)

    //设置一个自由的脚本执行时间限制
    {
      @set_time_limit(300);
    }

    $BM =& load_class('Benchmark', 'core');

    //实例化Benchmark基准类,此类使你可以标记点并计算它们之间时间差,内存消耗也可以显示

    $BM->mark('total_execution_time_start');

    //基准标记,总执行时间开始:$this->marker['total_execution_time_start'] = microtime();
    $BM->mark('loading_time:_base_classes_start');

    //基准标记,加载的时间:$this->marker['loading_time:_base_classes_start'] = microtime();

    $EXT =& load_class('Hooks', 'core');    //实例化Hooks钩子类,提供一种不堆砌来扩展基础系统的机制

    $EXT->_call_hook('pre_system');     //调用指定钩子pre_system

    $CFG =& load_class('Config', 'core');   //实例化Config配置类,包含管理配置文件的方法

    if (isset($assign_to_config))
    {
      $CFG->_assign_to_config($assign_to_config);

      //调用Config.php中_assign_to_config方法,保证配置项通过变量被分配 和 重写
    }

    $UNI =& load_class('Utf8', 'core');    //实例化Utf8类,对UTF-8环境提供支持

    $URI =& load_class('URI', 'core');    //实例化URI类,解析URI 和 决定路由

    $RTR =& load_class('Router', 'core'); //实例化Router路由类,解析URI 和 决定路由

    $RTR->_set_routing();        //这个函数确定什么应该是基于URI请求,以及 路由配置文件中设置的路由

    if (isset($routing))
    {
      $RTR->_set_overrides($routing); //设置控制器覆盖
    }

    $OUT =& load_class('Output', 'core');  //实例化Output输出类,负责发送最终的输出到浏览器

    if ($EXT->_call_hook('cache_override') === FALSE)
    {
      if ($OUT->_display_cache($CFG, $URI) == TRUE)
      {
        exit;               //检测是否有缓存文件,如果有,直接退出当前脚本
      }
    }

    $SEC =& load_class('Security', 'core');  //实例化Security安全类

    $IN =& load_class('Input', 'core');    //实例化Input输入类,为了安全对全局输入数据预处理  

    $LANG =& load_class('Lang', 'core');   //实例化Lang语言类

    require BASEPATH.'core/Controller.php';, //引入 基础控制器类

    function &get_instance()
    {
      return CI_Controller::get_instance(); //返回静态变量$instance
    }

    if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
    {
      require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';

      //引入自定义扩展 基础控制器类
    }

    if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'))
    {
      show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
    }

    include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');

    //加载本地控制器

    $BM->mark('loading_time:_base_classes_end');

    //基准标记,加载的时间结束:$this->marker['loading_time:_base_classes_end'] = microtime();

    安全检查

    $EXT->_call_hook('pre_controller');  //调用"pre_controller" hook

    $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); //基准标记,控制器执行时间标记点

    $CI = new $class();  //实例化请求控制器

    $EXT->_call_hook('post_controller_constructor'); //调用"post_controller_constructor" hook

    调用请求的方法

    $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); //基准标记,控制器执行时间结束标记点

    $EXT->_call_hook('post_controller');  //调用"post_controller" hook

    if ($EXT->_call_hook('display_override') === FALSE)
    {
      $OUT->_display();      //发送最后的渲染输出到浏览器
    }

    $EXT->_call_hook('post_system');  //调用"post_system" hook

    if (class_exists('CI_DB') AND isset($CI->db))
    {
      $CI->db->close();        //关闭数据库连接
    }

    -------------------------------------------------------------------------------------------------

  • 相关阅读:
    Java I/O(二 使用)
    Java 基本I/O的学习总结(一 是什么)
    设计模式(一)
    浏览器输入一个网址(发生的过程)
    final关键字的4种用法
    JavaScript(4)——闭包与this对象以及window对象
    JavaScript(3)—— 正则表达式
    JavaScript(2)——对象属性、原型与原型链
    JavaScript(1)——变量、函数声明及作用域
    构建分布式配置中心阿波罗(Apollo)
  • 原文地址:https://www.cnblogs.com/farwish/p/3870712.html
Copyright © 2011-2022 走看看