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

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

本书共78小节:

评论 (写第一个评论)