@@ -53,22 +53,24 @@ public function onPreConfiguration(Event $event)
53
53
*/
54
54
public function onKernelRequestEarly (GetResponseEvent $ event )
55
55
{
56
+ if (HttpKernelInterface::MASTER_REQUEST === $ event ->getRequestType ()) {
56
57
57
- $ request = $ event ->getRequest ();
58
+ $ request = $ event ->getRequest ();
58
59
59
- // When clean URLs are enabled, emulate ?q=foo/bar using REQUEST_URI. It is
60
- // not possible to append the query string using mod_rewrite without the B
61
- // flag (this was added in Apache 2.2.8), because mod_rewrite unescapes the
62
- // path before passing it on to PHP. This is a problem when the path contains
63
- // e.g. "&" or "%" that have special meanings in URLs and must be encoded.
64
- //
65
- // @see drupal_environment_initialize();
66
- $ path = $ _GET ['q ' ] = urldecode (substr ($ request ->getPathInfo (), 1 ));
67
- $ request ->query ->set ('q ' , $ path );
60
+ // When clean URLs are enabled, emulate ?q=foo/bar using REQUEST_URI. It is
61
+ // not possible to append the query string using mod_rewrite without the B
62
+ // flag (this was added in Apache 2.2.8), because mod_rewrite unescapes the
63
+ // path before passing it on to PHP. This is a problem when the path contains
64
+ // e.g. "&" or "%" that have special meanings in URLs and must be encoded.
65
+ //
66
+ // @see drupal_environment_initialize();
67
+ $ path = $ _GET ['q ' ] = urldecode (substr ($ request ->getPathInfo (), 1 ));
68
+ $ request ->query ->set ('q ' , $ path );
68
69
69
- $ GLOBALS ['base_url ' ] = $ request ->getSchemeAndHttpHost ();
70
+ $ GLOBALS ['base_url ' ] = $ request ->getSchemeAndHttpHost ();
70
71
71
- drupal_bootstrap (DRUPAL_BOOTSTRAP_VARIABLES );
72
+ drupal_bootstrap (DRUPAL_BOOTSTRAP_VARIABLES );
73
+ }
72
74
}
73
75
74
76
/**
@@ -78,7 +80,9 @@ public function onKernelRequestEarly(GetResponseEvent $event)
78
80
*/
79
81
public function onKernelRequestBeforeSession (GetResponseEvent $ event )
80
82
{
81
- drupal_bootstrap (DRUPAL_BOOTSTRAP_SESSION );
83
+ if (HttpKernelInterface::MASTER_REQUEST === $ event ->getRequestType ()) {
84
+ drupal_bootstrap (DRUPAL_BOOTSTRAP_SESSION );
85
+ }
82
86
}
83
87
84
88
/**
@@ -88,14 +92,16 @@ public function onKernelRequestBeforeSession(GetResponseEvent $event)
88
92
*/
89
93
public function onKernelRequestAfterSession (GetResponseEvent $ event )
90
94
{
91
- if (empty ($ GLOBALS ['user ' ])) {
92
- $ GLOBALS ['user ' ] = drupal_anonymous_user ();
93
- date_default_timezone_set (drupal_get_user_timezone ());
94
- }
95
+ if (HttpKernelInterface::MASTER_REQUEST === $ event ->getRequestType ()) {
96
+ if (empty ($ GLOBALS ['user ' ])) {
97
+ $ GLOBALS ['user ' ] = drupal_anonymous_user ();
98
+ date_default_timezone_set (drupal_get_user_timezone ());
99
+ }
95
100
96
- // This is basically noop.
97
- drupal_bootstrap (DRUPAL_BOOTSTRAP_PAGE_HEADER );
101
+ // This is basically noop.
102
+ drupal_bootstrap (DRUPAL_BOOTSTRAP_PAGE_HEADER );
98
103
104
+ }
99
105
}
100
106
101
107
/**
@@ -105,35 +111,37 @@ public function onKernelRequestAfterSession(GetResponseEvent $event)
105
111
*/
106
112
public function onKernelRequestBeforeRouter (GetResponseEvent $ event )
107
113
{
108
- drupal_bootstrap (DRUPAL_BOOTSTRAP_FULL );
109
-
110
- $ request = $ event ->getRequest ();
111
- if (!$ request ->attributes ->get ('_drupal ' , false ) && !empty ($ request ->query ->get ('q ' , '' ))) {
112
-
113
- // The 'q' variable is pervasive in Drupal, so it's best to just keep
114
- // it even though it's very un-Symfony.
115
- $ path = drupal_get_normal_path ($ _GET ['q ' ]);
116
-
117
- if (variable_get ('menu_rebuild_needed ' , FALSE ) || !variable_get ('menu_masks ' , array ())) {
118
- menu_rebuild ();
119
- }
120
- $ original_map = arg (NULL , $ path );
121
-
122
- $ parts = array_slice ($ original_map , 0 , MENU_MAX_PARTS );
123
- $ ancestors = menu_get_ancestors ($ parts );
124
- $ router_item = db_query_range ('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC ' , 0 , 1 , array (':ancestors ' => $ ancestors ))->fetchAssoc ();
125
-
126
- if ($ router_item ) {
127
- // Allow modules to alter the router item before it is translated and
128
- // checked for access.
129
- drupal_alter ('menu_get_item ' , $ router_item , $ path , $ original_map );
130
-
131
- // The requested path is an unalaised Drupal route.
132
- $ request ->attributes ->add (array (
133
- '_drupal ' => true ,
134
- '_controller ' => $ router_item ['page_callback ' ],
135
- '_route ' => $ router_item ['path ' ],
136
- ));
114
+ if (HttpKernelInterface::MASTER_REQUEST === $ event ->getRequestType ()) {
115
+ drupal_bootstrap (DRUPAL_BOOTSTRAP_FULL );
116
+
117
+ $ request = $ event ->getRequest ();
118
+ if (!$ request ->attributes ->get ('_drupal ' , false ) && !empty ($ request ->query ->get ('q ' , '' ))) {
119
+
120
+ // The 'q' variable is pervasive in Drupal, so it's best to just keep
121
+ // it even though it's very un-Symfony.
122
+ $ path = drupal_get_normal_path ($ _GET ['q ' ]);
123
+
124
+ if (variable_get ('menu_rebuild_needed ' , FALSE ) || !variable_get ('menu_masks ' , array ())) {
125
+ menu_rebuild ();
126
+ }
127
+ $ original_map = arg (NULL , $ path );
128
+
129
+ $ parts = array_slice ($ original_map , 0 , MENU_MAX_PARTS );
130
+ $ ancestors = menu_get_ancestors ($ parts );
131
+ $ router_item = db_query_range ('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC ' , 0 , 1 , array (':ancestors ' => $ ancestors ))->fetchAssoc ();
132
+
133
+ if ($ router_item ) {
134
+ // Allow modules to alter the router item before it is translated and
135
+ // checked for access.
136
+ drupal_alter ('menu_get_item ' , $ router_item , $ path , $ original_map );
137
+
138
+ // The requested path is an unalaised Drupal route.
139
+ $ request ->attributes ->add (array (
140
+ '_drupal ' => true ,
141
+ '_controller ' => $ router_item ['page_callback ' ],
142
+ '_route ' => $ router_item ['path ' ],
143
+ ));
144
+ }
137
145
}
138
146
}
139
147
}
@@ -145,7 +153,9 @@ public function onKernelRequestBeforeRouter(GetResponseEvent $event)
145
153
*/
146
154
public function onKernelRequestAfterLocale (GetResponseEvent $ event )
147
155
{
148
- drupal_bootstrap (DRUPAL_BOOTSTRAP_LANGUAGE );
156
+ if (HttpKernelInterface::MASTER_REQUEST === $ event ->getRequestType ()) {
157
+ drupal_bootstrap (DRUPAL_BOOTSTRAP_LANGUAGE );
158
+ }
149
159
}
150
160
151
161
/**
@@ -156,15 +166,17 @@ public function onKernelRequestAfterLocale(GetResponseEvent $event)
156
166
*/
157
167
public function onKernelRequestAfterFirewall (GetResponseEvent $ event )
158
168
{
159
- // Prior to invoking hook_init(), initialize the theme (potentially a custom
160
- // one for this page), so that:
161
- // - Modules with hook_init() implementations that call theme() or
162
- // theme_get_registry() don't initialize the incorrect theme.
163
- // - The theme can have hook_*_alter() implementations affect page building
164
- // (e.g., hook_form_alter(), hook_node_view_alter(), hook_page_alter()),
165
- // ahead of when rendering starts.
166
- menu_set_custom_theme ();
167
- drupal_theme_initialize ();
168
- module_invoke_all ('init ' );
169
+ if (HttpKernelInterface::MASTER_REQUEST === $ event ->getRequestType ()) {
170
+ // Prior to invoking hook_init(), initialize the theme (potentially a custom
171
+ // one for this page), so that:
172
+ // - Modules with hook_init() implementations that call theme() or
173
+ // theme_get_registry() don't initialize the incorrect theme.
174
+ // - The theme can have hook_*_alter() implementations affect page building
175
+ // (e.g., hook_form_alter(), hook_node_view_alter(), hook_page_alter()),
176
+ // ahead of when rendering starts.
177
+ menu_set_custom_theme ();
178
+ drupal_theme_initialize ();
179
+ module_invoke_all ('init ' );
180
+ }
169
181
}
170
182
}
0 commit comments