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系统主干流程的全貌,本系列后续主题讲解每个分支流程,也就是监听者。

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

本书共63小节:

评论 (写第一个评论)