13. 核心处理流程HttpKernel(drupal8执行流程)

龻龺龹龸龴龱 drupal8 龛龚龙龘龖龔龓龑龻龍龉龈龅龁齾齻齷齶齲齮龻齬齪齧齣齡齠齝齜齚齖齮齔齑 drupal 齷齏齍齉齈龙齄齂齀齍齷鼼鼻鼹鼵鼱鼼鼰鼮鼫鼨 12 齡鼤鼼鼡鼞鼚齮鼘鼕 drupal8 齷齏齍齉齈齀齍鼒鼐鼍鼌齷鼼鼊鼈鼅鼁龓龑黿黽黼黹黵黳黱鼕鼚齷黭黵黩黧鼚黣齠齣鼁黢點齷龸齂鼼 drupal 黚黖鼼鼹黕黚黑鼼龻黎黍鼚黌黊黉黆黼黹齣黄黁黀齷麼麸鼼麷鼹麶龻麵黑麲黀齷麯麮麬麨鼼麦黄鼅鼁黭黵黩麢麡黹鼅麞黵麝齷鼚麛鼊鼈麚麗鼼麔麓麒麎齖鼼麌麉麈麄龚鼼鼅麁鹾鹻龻黖鹹鼼鹵鹴鹲鹮鹪鹩鹦黚鹣齠鼫鹟鼍鼌齣鹞龖鹛黎鹘鹖鼘鼕麄龚齏齍齉齈麡鼼鼡鼞鼚鹕齮鼼鼊鼈黹鼅鹔齻黚鹑鹐齷鹌鹉鼚鹇鹄鹃齡齬鼚鸿鼤齣鹞黖黼鼼黹鼅鹔鼚鸽麈鸿鸼鹞龖鹛齄鸻齏齍齉齈齷鸺鸷齬鸳鼼鼹齣鹞黖黼麔麓齮鸲鸮齷鸬鸨鼼鸥鸣鼮鸢 HttpKernel 鸓鸏鹻齣鸍齣鸍鸊鸈鸄鹾齷齏齍鸿鸃鼅鹔鷿鼅齮鸓鸏鹻鷻鸣齣鹞鸊鸈鸄鹾鼼鹕齮龖鹛鷻齄鷸齷鸄鹾鼼鷴鷱鷰龻齷鷬鷩鷦黹鼅鹞鸄鹾鹔鷢齀齍鼼鹃齡黿齮鷟鷝鼅鹞鸄鹾齷鹦

鷰鷚黖鷖鷒鷐鼼鷌黹鼅鹔齮麌鷉鹲麛鸢鼤鼼鹃鸄鹾黹鸲鸮鹻齷鷅鷁鶽齮 http_kernel.basic 鼼齄鸻齈龉鶥鶣鷐鶡鼼鶟鶜鸺鶚鷌 Symfony HTTP 鸄鹾鶇鶃鹇 Symfony\Component\HttpKernel\HttpKernel 鼼鼅鹞鶇鶃齷鵻黕龓鵷鵶麈鼅鹔鹇 http://symfony.com/doc/2.8/components/http_kernel.html 鼼龛麄龚鵭鵫鹇 \vendor\symfony\http-kernel\HttpKernel.php

Symfony 鸊鸈鸄鹾鵠鵝鼤齣鹞鸊鸈齉齈鹇鵶鵙齠齝鵕鵔龘鵐鸿鵍鵌鸮鵕鵉鵆鵍鵌鸮鵕鵔龘鵍鵌鸮鵄鵃鵕齏齍鵍鵌鸮鵕鵀鴾鵍鵌鸮鴻齶鴸鴶鹇鷸鼈鴳鴰鼤鴯麔鼼鷸鼈鵐鸿鴬鴫鵃鶇麉齠鴨鴧鴥黭鴡鴬鴫齣鹞鴯麔鵕鷻鸣鼫鴞鴯麔鷿

鼅鹞鸢齈黌黊鴝鴙鴗鶣鼊鼈黿鸊鸈鴗鶣鴳鴰齣鹞鴯麔鼼鸼鹞鸢齈黌黊鴓鴐黚鹣鴎齜鵐鸿鷻鴋鴯麔鴇鴆鴎鵐鸿齣鹞鴃鸲鴁鳽鹦

Symfony 鸊鸈鸄鹾鶚鷌鳻鶃鳸鼫鳶鵌鼼鼅齮齣鹞鶥鶣鳳黖鳲鳰齷鳶鵌鼼黹鳭鶃鳩鳦鴧鳢鹻鳟鳛鳘鳕鹟鴧鳢鹦龻齣鹞鳻鶃鳸鼫鸮鼼鶟鴃鳑鳍鳊鼕麛鳆齷鳻鶃鼼鳄鳁麔鲾鷸鴨鹐齷齈龉鼼鼅鼁齈龉鳟鳛鳘鳕鹟鼼鲺鲸麝鷢鵠鵝齷鸊鸈齉齈鼼黹鴆齣鹞鲷鳸鼫鳁麔齷鳻鶃鼼鼅鼁鳘鳕鹟齈龉鲶鴾鲲麒鲱鲶鲮鲬鵐鳻鶃鳁鲫鲨齏齍鴇鳻鶃鳁鲫鲦鲤鼕黖鲣鵃鴾鳽鼼齪鲠麢鲟鹣齷齈龉鵄鲛鸿鼅鹞齄鸻齉齈鹻齚鷿 drupal 齷齏齍齉齈黿黽齣麞黖鲚鼼鷻齠齝鴳鴰齷鵶鵙鳁鲫黿黽齣鲖鲕鲑鼼鲏鲏鲍鲍龍齉鲠鲉鼼鸿鼅鹔鴆齣鹞鳘鳕鹟齈龉黿齮齣麞鲕鲕齷鲅齉鼼鼅麞鲑黌黊黹鼅鼁鲅齉鹻齀齀鴝鴝鼼麛鲁鱽麁鼅鼁鲅齉鷻鴋鹮鱻鱺鸿齄鸻鼼鷻鴋齣鹞鴯麔鳁鲫鴳鴰鲨鼫鴞鱸龱鱴鱲鷿鼅麈鱯齚黽麛黽齣鱫鱧鱦鲲鱢鲠鱡袤齷鱛鱗鱔鱑齾

鲉鷢麈齣麈麄龚鱐鴙鹇

Symfony 鸊鸈鸄鹾齷龛龚龓鶃齮 \vendor\symfony\http-kernel\HttpKernel.php, 鼅鹞鸄鹾鱈鱄鱁鱀鹞鵄鵃鹇鳻鶃鳸鼫鸮鳁鲫鰽鵔龘鸮鳁鲫鰽鵶鵙鸓鸏鷿

鼅鹞 HttpKernel 鱈鲨麛鰻鰷鼼齄鷸齉齈鵠鵝黹 handleRaw 黕鰭鹻鼼黹鼅鹞黕鰭鹔鼚黌齜鰩鰥齷麈鸿鼹龓鰣鰠齷齉齈鵠鵝鼼鼅鹔鰝齷鰜鲷齮鳻鶃鳸鼫鸮鼼齮鶟麢鲟鹣齷齈龉鵄鲛鸿鼅鹞齄鸻齉齈鹻齚鹦

drupal8 鰘龻鶚鷌 Symfony 鰖鰕齷鳻鶃鳸鼫鸮鼼鲠齮鰔齪 Symfony 鵠鵝齷鳻鶃鳸鼫鸮鱄鰒鰑鰏鱐鴙鼤齣鹞龻鸲鸮鰌鰉齷鳻鶃鳸鼫鸮鴇黿齮鴃鳑鰅鰄鸲鸮鳁鲫齷鳻鶃鳸鼫鸮鳽鼼鶟鹔鷢鲁鸈鼕鳻鶃鶽鰀鳁麔齷鲾鷸鴯麔鼅鼁鳻鶃齷鸲鸮鷅鷁鴇鳘鳕鹟鳽鹦

Symfony 鸊鸈鸄鹾鹻鵠鵝鼤鯾鯺鸄鹾鳻鶃鼼鯸鯶鵭鵫 \vendor\symfony\http-kernel\KernelEvents.php 鹻鼼鼡鲉鹇

const REQUEST = 'kernel.request'; 黹鸄鹾鱄鸿鵶鵙鯤鰘鯢鯡鹐鷩黎鳸鼫鼅鹞鳻鶃

const CONTROLLER = 'kernel.controller'; 鵔龘鸮鵐鸿鵍鵌鸮鸣鳸鼫麓鳻鶃鼼鯘鯗鳘鳕鹟鵉鯔鷸齏齍齷鵍鵌鸮

const VIEW = 'kernel.view'; 鵍鵌鸮鴻齶鴬鴫鵃鶇鼼鲾鷸鴨鹐鴧鴥黭鴡黎鳸鼫鼅鹞鳻鶃鼼鴧鴥黭鴡黿齮齣鹞鳘鳕鹟

const RESPONSE = 'kernel.response'; 鵐鸿鴯麔鸣鳸鼫麓鳻鶃鼼鯘鯗鳘鳕鹟鵉鯔鴯麔

const FINISH_REQUEST = 'kernel.finish_request'; 鶜鸨鴯麔鸣鳸鼫鼼鯘鯗鳘鳕鹟鰜鯅鸺鹹鴐鯁黱鹐鷩

const TERMINATE = 'kernel.terminate'; 鴯麔鮺鼫鴞鸣鳸鼫麓鳻鶃鼼齏齍齣鼁鮹鰜齷鯢鷁鼼鮸鼡鸊鸈 POST 鵃鴾

const EXCEPTION = 'kernel.exception'; 鴳鴰鴗鶣黎鳸鼫鼅鹞鳻鶃

齜麝齮鸄鹾鮰鳸鼫齷鯾鯺鳻鶃鼼黹 drupal8 鹻鳘鳕鹟鯤黌齜鮬鮪鳸鼫鰑鰏齷鳻鶃鼼鼅鲤齚鮦黖齷鳲鳰鮣鼼鼡鯡鮟鷩鮛鲉龓鹇

drupal 齷鮚鮘鼫齍鮗鹃鹻鮔鮓齷鳻鶃鶽鮛鮐鮌鴃鸲鮋鹇

鼅鼁鳻鶃鳁麔齷鳘鳕鹟鷅鷁黖鮈龻齣鮆鹞鼼鼅鼁鳘鳕鹟鰀鳻鶃齮鮅鼈黎黍鮔鮓鸿鳻鶃鳸鼫鸮齷鮃齾

齮黹鸲鸮鮁鮀魽魼鼼鳁麔齷鮁鮀鸮齮鹇 \core\lib\Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass.php

鼅鹞鮁鮀鸮魳鱺鷰龻魯魬 event_subscriber 魪魦齷鷅鷁鳁鲫鼼魤鯸鯶鳛鸨鵠鵝鵃鶇魠魜鱸鳻鶃鳸鼫鸮

鼅鼁魯魬 event_subscriber 魪魦齷鷅鷁鳁鲫魙魖鱐鴙魒魑鹟鱄鰒鹇

\vendor\symfony\event-dispatcher\EventSubscriberInterface.php

Array
(
    [0] => routing.route_finished
    [1] => config.save
    [2] => config.delete
    [3] => config.importer.missing_content
    [4] => routing.route_dynamic
    [5] => config.importer.validate
    [6] => routing.route_alter
    [7] => kernel.request
    [8] => kernel.response
    [9] => kernel.exception
    [10] => kernel.view
    [11] => kernel.finish_request
    [12] => kernel.controller
    [13] => kernel.terminate
    [14] => config.importer.import
    [15] => render.page_display_variant.select
    [16] => config.collection_info
    [17] => config.rename
    [18] => language.save_override
    [19] => language.delete_override
    [20] => locale.save_translation
    [21] => entity_type.definition.create
    [22] => entity_type.definition.update
    [23] => entity_type.definition.delete
)

鷰齜黹鴧鴁鹻鷸鵠鵝齣鹞魒魑鹟鷅鷁麶鲾鷸魐麝 event_subscriber 魪魦魏黌鼼鮸鼡鹇

  options_request_listener:
    class: Drupal\Core\EventSubscriber\OptionsRequestSubscriber
    arguments: ['@router.route_provider']
    tags:
      - { name: event_subscriber }

黹魒魑鸮齷 getSubscribedEvents() 黕鰭鹻黌齜鴻齶鲾鷸鳘鳕齷鳻鶃鶽鰀鲲麒鲱鼼齮齜鲉鵃鶇鬶齣鹇

array('eventName' => 'methodName') //默认优先级为0
array('eventName' => array('methodName', $priority)) //指定优先级
array('eventName' => array(array('methodName1', $priority), array('methodName2'))) //指定多个监听者
//可以指定多个事件名 一起返回 每个事件名对应的监听者使用如上格式

鱽鼈齠鼫齣鹞魒魑鹟齾鵄齑鹇 \core\lib\Drupal\Core\EventSubscriber 鼅鹞龓鶃鬩鲉鬥鬣鹣鹞鸄鹾魒魑鹟鹦

齜麝齮齜鷅鷁黕鳢鬟鬜鵠鵝鳻鶃鰀鳘鳕鹟鼼黹鬙齍鹻鯤黌齜鹐鬜鵠鵝鼼麶鲾鷸鬗鷌鳻鶃鳸鼫鸮齷鬕麔黕鰭魏黌鼼鼡鲉鹇

\Drupal::service("event_dispatcher")->addListener($event_name, $listener, $priority = 0);//添加监听者
\Drupal::service("event_dispatcher")->addSubscriber(EventSubscriberInterface $subscriber);//添加订阅者

鬌鹣鳁鳻鶃鳸鼫鸮齷鮟鷩鵶麈龛麄龚鹇 \core\lib\Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher.php

鳘鳕鹟鰀魒魑鹟齷鮋鬊齮鹇魒魑鹟鷌齚鮔鮓鳘鳕鹟鼼鶟黌齜鰅鰄鯗鹣鳘鳕鹟鹦

鼡鼞鼚鬆鬂鷖鼚齷龖鹛鹻鬟鬜鵠鵝鼤鹣髾鳘鳕鹟鼼鵶齔齑鸲鸮鷟鷝鹻齷黕鰭鸿鵃鴾髽鹻鲉髹鸲鸮鵠鵝鵃鴾鼼鸥鸣齏齍鲉龔麄龚鹇

$c=unserialize(file_get_contents("下载的容器定义数据yunke_cache_container-data.bin"));
$c=unserialize($c["services"]["event_dispatcher"]);
$c=$c["arguments"]->value;
$c=$c[1];
$event_name=array_keys($c);
$listeners=[];
foreach($c as  $key=>$value)
{
    foreach($value as  $k=>$v)
    {
        foreach($v as  $listener)
        {
            $listeners[]=$listener["service"];
        }
    }
}
print_r($event_name);
print_r($listeners);

好了,以上就是本主题的全部。

到这里你已经看到了整个drupal系统主干流程的全貌,本系列后续主题讲解每个分支流程,也就是监听者。

由于它们可能会交叉执行,所以不一定就是按执行流程来发布了,但主题是明确的,一个主题一个知识点。

本书共71小节:

评论 (写第一个评论)