d8入口文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?php
/**
* @file
* The PHP page that serves all page requests on a Drupal installation.
*
* All Drupal code is released under the GNU General Public License.
* See <a href="/project/copyright" class="alinks-link" title="模块介绍:可以设定网站整体和单篇内容的著作权/授权声明。管理者可以设定可选用的著作权种类,呈现在区块或页尾里。手册页面(Book)可以选择性地设定所有子页面为同一著作权声明,并让每一份手册或区域有其自己的著作权声明。">COPYRIGHT</a>.txt and LICENSE.txt files in the "core" directory.
*/
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once 'autoload.php';
$kernel = new DrupalKernel('prod', $autoloader);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
|
这一整套流程其实就是Symfony的运行机制
当然为了更好的了解这个运行过程,从网上找了个图片下

其实这里可以用自己的理解方式来理解上述问题,我做了如下方式,当然这只是粗糙的思路,并不是完美的代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
$request = ['http'=>$_SEVER,'params'=>$_GET,'params'=>$_POST] ;
$getrouter = $request['路由'];
$allrouter = ['router1'=>'file/class/action','路由2'=>'对应文件/对应类/对应方法'];
$router = separaterouter($allrouter['$getrouter']);
$file = 'file';
$class = 'class' ;
$action = 'action';
require_once($file);
$response = new $router.'()';
$page = $response->$action.'()';
echo $page;
watchdog($request,$response);
|
流程就到这里,下面来说说命名空间和autoload
熟悉这个的人就不用看了,5.3以前php的命名空间是不存在的,为啥后来有了
为了是区分两个相同类名,而不是同一个类的情况,比如在颜色的文件下有个green(绿色)类,定义了的色值、调色方法等,在姓氏里面定义了也green(格林)类,定义了历史、常用名等等。这两个在房屋装修中可能都会用到。
扯远了,回来继续
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
$autoloader = require_once 'autoload.php';
return require __DIR__ . '/vendor/autoload.php';
<?php
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInitDrupal8::getLoader();
|
composer这个工具大概的目的就是根据类名的及类的命名空间找到类文件所在位置,然后使用该类的时候自动加载这个类文件。相当于以前的require,只是变成自动的,当然它有自己的命名规范
想要了解的可以查看资料,之前找了一份,觉着挺好的,是个台湾人写的
http://blog.turn.tw/?p=1039