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

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

本书共88小节:

评论 (写第一个评论)