search
HomeBackend DevelopmentPHP TutorialThinkPHP3.2 加载过程(2)

ThinkPHP3.2 加载过程(二)

回顾:

  上次介绍了 ThinkPHP 的 Index.PHP入口文件。但只是TP的入口前面的入口(刷boss总是要过好几关才能让你看到 ,不然boss都没面子啊),从Index.PHP最后一行把我们引路到了TP的大门前(ThinkPHP/ThinkPHP.php)

// 引入ThinkPHP入口文件require './ThinkPHP/ThinkPHP.php';

 

本次目标:

  查看TP的大门,同时稍微探索一下大门内部的东西

 

正文:

  先上代码

<span style="color: #008080;"> 1</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 记录开始运行时间</span><span style="color: #008080;"> 2</span> <span style="color: #800080;">$GLOBALS</span>['_beginTime'] = <span style="color: #008080;">microtime</span>(<span style="color: #0000ff;">TRUE</span><span style="color: #000000;">);</span><span style="color: #008080;"> 3</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 记录内存初始使用</span><span style="color: #008080;"> 4</span> <span style="color: #008080;">define</span>('MEMORY_LIMIT_ON',<span style="color: #008080;">function_exists</span>('memory_get_usage'<span style="color: #000000;">));</span><span style="color: #008080;"> 5</span> <span style="color: #0000ff;">if</span>(MEMORY_LIMIT_ON) <span style="color: #800080;">$GLOBALS</span>['_startUseMems'] =<span style="color: #000000;"> memory_get_usage();</span><span style="color: #008080;"> 6</span> <span style="color: #008080;"> 7</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 版本信息</span><span style="color: #008080;"> 8</span> <span style="color: #0000ff;">const</span> THINK_VERSION     =   '3.2.3'<span style="color: #000000;">;</span><span style="color: #008080;"> 9</span> <span style="color: #008080;">10</span> <span style="color: #008000;">//</span><span style="color: #008000;"> URL 模式定义</span><span style="color: #008080;">11</span> <span style="color: #0000ff;">const</span> URL_COMMON        =   0;  <span style="color: #008000;">//</span><span style="color: #008000;">普通模式</span><span style="color: #008080;">12</span> <span style="color: #0000ff;">const</span> URL_PATHINFO      =   1;  <span style="color: #008000;">//</span><span style="color: #008000;">PATHINFO模式</span><span style="color: #008080;">13</span> <span style="color: #0000ff;">const</span> URL_REWRITE       =   2;  <span style="color: #008000;">//</span><span style="color: #008000;">REWRITE模式</span><span style="color: #008080;">14</span> <span style="color: #0000ff;">const</span> URL_COMPAT        =   3;  <span style="color: #008000;">//</span><span style="color: #008000;"> 兼容模式</span><span style="color: #008080;">15</span> <span style="color: #008080;">16</span> <span style="color: #008000;">// 类文件后缀</span><span style="color: #008080;">17</span> <span style="color: #0000ff;">const</span> EXT               =   '.class.php'<span style="color: #000000;">; </span><span style="color: #008080;">18</span> <span style="color: #008080;">19</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 系统常量定义</span><span style="color: #008080;">20</span> <span style="color: #008080;">defined</span>('THINK_PATH')   or <span style="color: #008080;">define</span>('THINK_PATH',     __DIR__.'/'<span style="color: #000000;">);</span><span style="color: #008080;">21</span> <span style="color: #008080;">defined</span>('APP_PATH')     or <span style="color: #008080;">define</span>('APP_PATH',       <span style="color: #008080;">dirname</span>(<span style="color: #800080;">$_SERVER</span>['SCRIPT_FILENAME']).'/'<span style="color: #000000;">);</span><span style="color: #008080;">22</span> <span style="color: #008080;">defined</span>('APP_STATUS')   or <span style="color: #008080;">define</span>('APP_STATUS',     ''); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用状态 加载对应的配置文件</span><span style="color: #008080;">23</span> <span style="color: #008080;">defined</span>('APP_DEBUG')    or <span style="color: #008080;">define</span>('APP_DEBUG',      <span style="color: #0000ff;">false</span>); <span style="color: #008000;">//</span><span style="color: #008000;"> 是否调试模式</span><span style="color: #008080;">24</span> <span style="color: #008080;">25</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">function_exists</span>('saeAutoLoader')){<span style="color: #008000;">//</span><span style="color: #008000;"> 自动识别SAE环境</span><span style="color: #008080;">26</span>     <span style="color: #008080;">defined</span>('APP_MODE')     or <span style="color: #008080;">define</span>('APP_MODE',      'sae'<span style="color: #000000;">);</span><span style="color: #008080;">27</span>     <span style="color: #008080;">defined</span>('STORAGE_TYPE') or <span style="color: #008080;">define</span>('STORAGE_TYPE',  'Sae'<span style="color: #000000;">);</span><span style="color: #008080;">28</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;">29</span>     <span style="color: #008080;">defined</span>('APP_MODE')     or <span style="color: #008080;">define</span>('APP_MODE',       'common'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用模式 默认为普通模式    </span><span style="color: #008080;">30</span>     <span style="color: #008080;">defined</span>('STORAGE_TYPE') or <span style="color: #008080;">define</span>('STORAGE_TYPE',   'File'); <span style="color: #008000;">//</span><span style="color: #008000;"> 存储类型 默认为File    </span><span style="color: #008080;">31</span> <span style="color: #000000;">}</span><span style="color: #008080;">32</span> <span style="color: #008080;">33</span> <span style="color: #008080;">defined</span>('RUNTIME_PATH') or <span style="color: #008080;">define</span>('RUNTIME_PATH',   APP_PATH.'Runtime/');   <span style="color: #008000;">//</span><span style="color: #008000;"> 系统运行时目录</span><span style="color: #008080;">34</span> <span style="color: #008080;">defined</span>('LIB_PATH')     or <span style="color: #008080;">define</span>('LIB_PATH',       <span style="color: #008080;">realpath</span>(THINK_PATH.'Library').'/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 系统核心类库目录</span><span style="color: #008080;">35</span> <span style="color: #008080;">defined</span>('CORE_PATH')    or <span style="color: #008080;">define</span>('CORE_PATH',      LIB_PATH.'Think/'); <span style="color: #008000;">//</span><span style="color: #008000;"> Think类库目录</span><span style="color: #008080;">36</span> <span style="color: #008080;">defined</span>('BEHAVIOR_PATH')or <span style="color: #008080;">define</span>('BEHAVIOR_PATH',  LIB_PATH.'Behavior/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 行为类库目录</span><span style="color: #008080;">37</span> <span style="color: #008080;">defined</span>('MODE_PATH')    or <span style="color: #008080;">define</span>('MODE_PATH',      THINK_PATH.'Mode/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 系统应用模式目录</span><span style="color: #008080;">38</span> <span style="color: #008080;">defined</span>('VENDOR_PATH')  or <span style="color: #008080;">define</span>('VENDOR_PATH',    LIB_PATH.'Vendor/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 第三方类库目录</span><span style="color: #008080;">39</span> <span style="color: #008080;">defined</span>('COMMON_PATH')  or <span style="color: #008080;">define</span>('COMMON_PATH',    APP_PATH.'Common/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用公共目录</span><span style="color: #008080;">40</span> <span style="color: #008080;">defined</span>('CONF_PATH')    or <span style="color: #008080;">define</span>('CONF_PATH',      COMMON_PATH.'Conf/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用配置目录</span><span style="color: #008080;">41</span> <span style="color: #008080;">defined</span>('LANG_PATH')    or <span style="color: #008080;">define</span>('LANG_PATH',      COMMON_PATH.'Lang/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用语言目录</span><span style="color: #008080;">42</span> <span style="color: #008080;">defined</span>('HTML_PATH')    or <span style="color: #008080;">define</span>('HTML_PATH',      APP_PATH.'Html/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用静态目录</span><span style="color: #008080;">43</span> <span style="color: #008080;">defined</span>('LOG_PATH')     or <span style="color: #008080;">define</span>('LOG_PATH',       RUNTIME_PATH.'Logs/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用日志目录</span><span style="color: #008080;">44</span> <span style="color: #008080;">defined</span>('TEMP_PATH')    or <span style="color: #008080;">define</span>('TEMP_PATH',      RUNTIME_PATH.'Temp/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用缓存目录</span><span style="color: #008080;">45</span> <span style="color: #008080;">defined</span>('DATA_PATH')    or <span style="color: #008080;">define</span>('DATA_PATH',      RUNTIME_PATH.'Data/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用数据目录</span><span style="color: #008080;">46</span> <span style="color: #008080;">defined</span>('CACHE_PATH')   or <span style="color: #008080;">define</span>('CACHE_PATH',     RUNTIME_PATH.'Cache/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用模板缓存目录</span><span style="color: #008080;">47</span> <span style="color: #008080;">defined</span>('CONF_EXT')     or <span style="color: #008080;">define</span>('CONF_EXT',       '.php'); <span style="color: #008000;">//</span><span style="color: #008000;"> 配置文件后缀</span><span style="color: #008080;">48</span> <span style="color: #008080;">defined</span>('CONF_PARSE')   or <span style="color: #008080;">define</span>('CONF_PARSE',     '');    <span style="color: #008000;">//</span><span style="color: #008000;"> 配置文件解析方法</span><span style="color: #008080;">49</span> <span style="color: #008080;">defined</span>('ADDON_PATH')   or <span style="color: #008080;">define</span>('ADDON_PATH',     APP_PATH.'Addon'<span style="color: #000000;">);</span><span style="color: #008080;">50</span> <span style="color: #008080;">51</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 系统信息</span><span style="color: #008080;">52</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">version_compare</span>(<span style="color: #ff00ff;">PHP_VERSION</span>,'5.4.0',')) {<span style="color: #008080;">53</span>     <span style="color: #008080;">ini_set</span>('magic_quotes_runtime',0<span style="color: #000000;">);</span><span style="color: #008080;">54</span>     <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #008080;">get_magic_quotes_gpc</span>()? <span style="color: #0000ff;">true</span> : <span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;">55</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;">56</span>     <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;">57</span> <span style="color: #000000;">}</span><span style="color: #008080;">58</span> <span style="color: #008080;">define</span>('IS_CGI',(0 === <span style="color: #008080;">strpos</span>(PHP_SAPI,'cgi') || <span style="color: #0000ff;">false</span> !== <span style="color: #008080;">strpos</span>(PHP_SAPI,'fcgi')) ? 1 : 0<span style="color: #000000;"> );</span><span style="color: #008080;">59</span> <span style="color: #008080;">define</span>('IS_WIN',<span style="color: #008080;">strstr</span>(<span style="color: #ff00ff;">PHP_OS</span>, 'WIN') ? 1 : 0<span style="color: #000000;"> );</span><span style="color: #008080;">60</span> <span style="color: #008080;">define</span>('IS_CLI',PHP_SAPI=='cli'? 1   :   0<span style="color: #000000;">);</span><span style="color: #008080;">61</span> <span style="color: #008080;">62</span> <span style="color: #0000ff;">if</span>(!<span style="color: #000000;">IS_CLI) {</span><span style="color: #008080;">63</span>     <span style="color: #008000;">//</span><span style="color: #008000;"> 当前文件名</span><span style="color: #008080;">64</span>     <span style="color: #0000ff;">if</span>(!<span style="color: #008080;">defined</span>('_PHP_FILE_'<span style="color: #000000;">)) {</span><span style="color: #008080;">65</span>         <span style="color: #0000ff;">if</span><span style="color: #000000;">(IS_CGI) {</span><span style="color: #008080;">66</span>             <span style="color: #008000;">//</span><span style="color: #008000;">CGI/FASTCGI模式下</span><span style="color: #008080;">67</span>             <span style="color: #800080;">$_temp</span>  = <span style="color: #008080;">explode</span>('.php',<span style="color: #800080;">$_SERVER</span>['PHP_SELF'<span style="color: #000000;">]);</span><span style="color: #008080;">68</span>             <span style="color: #008080;">define</span>('_PHP_FILE_',    <span style="color: #008080;">rtrim</span>(<span style="color: #008080;">str_replace</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_HOST'],'',<span style="color: #800080;">$_temp</span>[0].'.php'),'/'<span style="color: #000000;">));</span><span style="color: #008080;">69</span>         }<span style="color: #0000ff;">else</span><span style="color: #000000;"> {</span><span style="color: #008080;">70</span>             <span style="color: #008080;">define</span>('_PHP_FILE_',    <span style="color: #008080;">rtrim</span>(<span style="color: #800080;">$_SERVER</span>['SCRIPT_NAME'],'/'<span style="color: #000000;">));</span><span style="color: #008080;">71</span> <span style="color: #000000;">        }</span><span style="color: #008080;">72</span> <span style="color: #000000;">    }</span><span style="color: #008080;">73</span>     <span style="color: #0000ff;">if</span>(!<span style="color: #008080;">defined</span>('__ROOT__'<span style="color: #000000;">)) {</span><span style="color: #008080;">74</span>         <span style="color: #800080;">$_root</span>  =   <span style="color: #008080;">rtrim</span>(<span style="color: #008080;">dirname</span>(_PHP_FILE_),'/'<span style="color: #000000;">);</span><span style="color: #008080;">75</span>         <span style="color: #008080;">define</span>('__ROOT__',  ((<span style="color: #800080;">$_root</span>=='/' || <span style="color: #800080;">$_root</span>=='\\')?'':<span style="color: #800080;">$_root</span><span style="color: #000000;">));</span><span style="color: #008080;">76</span> <span style="color: #000000;">    }</span><span style="color: #008080;">77</span> <span style="color: #000000;">}</span><span style="color: #008080;">78</span> <span style="color: #008080;">79</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 加载核心Think类</span><span style="color: #008080;">80</span> <span style="color: #0000ff;">require</span> CORE_PATH.'Think'.<span style="color: #000000;">EXT;</span><span style="color: #008080;">81</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 应用初始化 </span><span style="color: #008080;">82</span> Think\Think::start();

解释:

  1 - 5 行:初始化  运行的时间  内存之类的东东,给开发人员提供代码运行效率直观上的体现

  8       行:不猜也能知道  就是版本好的说明嘛

  11-14行:定义4个数据嘛,也就是浏览器地址的解析模式(等一下解释)

  17   行:这里不是看到是不是感觉到  我们如果加一个php时候的文件的后缀

 

    20-49行:定义各种变量  但是下面的这段代码  其中有一个函数  get_magic_quotes_gpc()  这个函数做什么用  我大致查选了一下  大致说法  参考。TP里面  能起到多大的作用  我也不是很清楚   如果谁知道  欢迎给大家说明一下

    PHP解析器就会自动为post、get、cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特别是数据库语句因为特殊字符引起的污染而出现致命的错误。

<span style="color: #008080;">1</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">version_compare</span>(<span style="color: #ff00ff;">PHP_VERSION</span>,'5.4.0',')) {<span style="color: #008080;">2</span>     <span style="color: #008080;">ini_set</span>('magic_quotes_runtime',0<span style="color: #000000;">);</span><span style="color: #008080;">3</span>     <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #008080;">get_magic_quotes_gpc</span>()? <span style="color: #0000ff;">true</span> : <span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;">4</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;">5</span>     <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;">6</span> }

  最后是加载核心Think类  和运行Think类中的start()这个方法

<span style="color: #008080;">1</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 加载核心Think类</span><span style="color: #008080;">2</span> <span style="color: #0000ff;">require</span> CORE_PATH.'Think'.<span style="color: #000000;">EXT;</span><span style="color: #008080;">3</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 应用初始化 </span><span style="color: #008080;">4</span> Think\Think::start();

 

说明一下TP中的URL的几个模式  资料

普通模式下 

 1 const URL_COMMON = 0; //普通模式 

   URL为  http://localhost/?m=home&c=user&a=login&var=value

      m参数表示模块,c参数表示控制器,a参数表示操作(当然这些参数都是可以配置的),后面的表示其他GET参数。

  'VAR_MODULE' => 'm', // 默认模块获取变量

  'VAR_CONTROLLER' => 'c', // 默认控制器获取变量

    'VAR_ACTION' => 'a', // 默认操作获取变量

  值的定义在ThinkPHP\Conf\Convention.php

  

<span style="color: #008080;"> 1</span>     <span style="color: #008000;">/*</span><span style="color: #008000;"> 系统变量名称设置 </span><span style="color: #008000;">*/</span><span style="color: #008080;"> 2</span>     'VAR_MODULE'            =>  'm',     <span style="color: #008000;">//</span><span style="color: #008000;"> 默认模块获取变量</span><span style="color: #008080;"> 3</span>     'VAR_ADDON'             =>  'addon',     <span style="color: #008000;">//</span><span style="color: #008000;"> 默认的插件控制器命名空间变量</span><span style="color: #008080;"> 4</span>     'VAR_CONTROLLER'        =>  'c',    <span style="color: #008000;">//</span><span style="color: #008000;"> 默认控制器获取变量</span><span style="color: #008080;"> 5</span>     'VAR_ACTION'            =>  'a',    <span style="color: #008000;">//</span><span style="color: #008000;"> 默认操作获取变量</span><span style="color: #008080;"> 6</span>     'VAR_AJAX_SUBMIT'       =>  'ajax',  <span style="color: #008000;">//</span><span style="color: #008000;"> 默认的AJAX提交变量</span><span style="color: #008080;"> 7</span>     'VAR_JSONP_HANDLER'     =>  'callback',<span style="color: #008080;"> 8</span>     'VAR_PATHINFO'          =>  's',    <span style="color: #008000;">//</span><span style="color: #008000;"> 兼容模式PATHINFO获取变量例如 ?s=/module/action/id/1 后面的参数取决于URL_PATHINFO_DEPR</span><span style="color: #008080;"> 9</span>     'VAR_TEMPLATE'          =>  't',    <span style="color: #008000;">//</span><span style="color: #008000;"> 默认模板切换变量</span><span style="color: #008080;">10</span>     'VAR_AUTO_STRING'        =>    <span style="color: #0000ff;">false</span>,    <span style="color: #008000;">//</span><span style="color: #008000;"> 输入变量是否自动强制转换为字符串 如果开启则数组变量需要手动传入变量修饰符获取变量</span>

 

PATHINFO模式

 1 const URL_PATHINFO = 1; //PATHINFO模式 该模式是默认模式

  URL: http://localhost/index.php/home/user/login/var/value/ 

  PATHINFO地址的前三个参数分别表示模块/控制器/操作。

  说白了就是把普通模式下的几个M  C  A 变量给省掉  使用斜杠来代替 

  好处:1.看上去很整齐   2.据说可以提高被搜索引擎抓住的几率哦!!!

  当然是斜杠还是别的是可以设置的在  ThinkPHP\Conf\Convention.php  文件中可以进行设置

   1 'URL_PATHINFO_DEPR' => '/', // PATHINFO模式下,各参数之间的分割符号 

 

REWRITE模式

 1 const URL_REWRITE = 2; //REWRITE模式 

  官方的原话  : REWRITE模式是在PATHINFO模式的基础上添加了重写规则的支持,可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则。

   如何是这样,那么我觉得应该就是  浏览器地址给重写以后在按照PATHINFO模式进行解析路由

 

兼容模式

 1 const URL_COMPAT = 3; // 兼容模式

  URL http://localhost/?s=/home/user/login/var/value

  看到这个地址  YII的人有木有感觉很熟悉

  为什么是S开头呢?是因为配置文件的设置   在 ThinkPHP\Conf\Convention.php

   1 'VAR_PATHINFO' => 's', // 兼容模式PATHINFO获取变量例如 ?s=/module/action/id/1 后面的参数取决于URL_PATHINFO_DEPR 

 

修改模式方法

  在配置文件 ThinkPHP\Conf\Convention.php

   1 'URL_MODEL' => 1, // URL访问模式,可选参数0、1、2、3,代表以下四种模式: 2 // 0 (普通模式); 1 (PATHINFO 模式); 2 (REWRITE 模式); 3 (兼容模式) 默认为PATHINFO 模式 

 

对于以上集中模式个人的小总结:  

  不管是那个  我们把URL中出了模块名称开始前都去掉,就是不同的几种取出模块、控制器、控制器其中的方法名。所以在不配置路由和不使用默认的情况下,我们都能看到这三个参数。

 

总结:

  ThinkPHP\ThinkPHP.php文件中  最主要的目的还是定义好各种目录的变量方便以后的调用

  如果你发现代码中有一个定义你不知道做什么,如果是_path结尾(关于目录的),就去ThinkPHP\ThinkPHP.php中找找,别的那么就去ThinkPHP\Conf\Convention.php下找找  基本都能找到

 

几个思考(个人在整理时候想到的):

  1.定义IS_CGI ,IS_WIN,IS_CLI,MAGIC_QUOTES_GPC干嘛用

<span style="color: #008080;"> 1</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 系统信息</span><span style="color: #008080;"> 2</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">version_compare</span>(<span style="color: #ff00ff;">PHP_VERSION</span>,'5.4.0',')) {<span style="color: #008080;"> 3</span>     <span style="color: #008080;">ini_set</span>('magic_quotes_runtime',0<span style="color: #000000;">);</span><span style="color: #008080;"> 4</span>     <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #008080;">get_magic_quotes_gpc</span>()? <span style="color: #0000ff;">true</span> : <span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;"> 5</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;"> 6</span>     <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">}</span><span style="color: #008080;"> 8</span> <span style="color: #008080;">define</span>('IS_CGI',(0 === <span style="color: #008080;">strpos</span>(PHP_SAPI,'cgi') || <span style="color: #0000ff;">false</span> !== <span style="color: #008080;">strpos</span>(PHP_SAPI,'fcgi')) ? 1 : 0<span style="color: #000000;"> );</span><span style="color: #008080;"> 9</span> <span style="color: #008080;">define</span>('IS_WIN',<span style="color: #008080;">strstr</span>(<span style="color: #ff00ff;">PHP_OS</span>, 'WIN') ? 1 : 0<span style="color: #000000;"> );</span><span style="color: #008080;">10</span> <span style="color: #008080;">define</span>('IS_CLI',PHP_SAPI=='cli'? 1   :   0);

  2.为什么我们刚下载的架构不需要输入模块、控制器、方法名也能正常跳出页面。

 

好了,下一次我们就拿上小米加步枪杀进TP大门

 1 // 应用初始化 2 Think\Think::start(); 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.