-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.module
140 lines (120 loc) · 3.26 KB
/
kernel.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* @file
* Symfony Kernel module
*/
/**
* Implements hook_menu().
*/
function kernel_menu() {
$items = array();
$items['bundles'] = array(
'page callback' => 'kernel_assets_callback',
'access callback' => TRUE,
'file' => 'kernel.pages.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_service_provider().
*
* @param string $name
*
* @return array
*/
function kernel_service_provider($name = 'app') {
return array(
array(new DrupalKernelServiceProvider(), array('kernel.name' => $name)),
array(new DrushKernelServiceProvider())
);
}
/**
* Returns info about the registered kernels.
*
* @param string $name
* Kernel name (usually named for the directory)
*
* @return array
* Kernel info
*/
function kernel_info($name = 'app') {
// Use the advanced drupal_static() pattern, since this is called very often.
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast['cache'] = &drupal_static(__FUNCTION__);
}
$cache = &$drupal_static_fast['cache'];
if (!isset($cache)) {
$cache = module_invoke_all('kernel_info');
// Allow modules to alter the element type defaults.
drupal_alter('kernel_info', $cache);
}
return isset($cache[$name]) ? $cache[$name] : array();
}
/**
* Captures the response from the page callback for use in kernel_exit().
*/
function kernel_response(\Symfony\Component\HttpFoundation\Response $response = NULL) {
$static = &drupal_static('kernel_response');
if (isset($response)) {
$static = $response;
}
else {
return $static;
}
}
/**
* Implements hook_exit().
*/
function kernel_exit() {
$c = pimple_get_container('app');
$kernel = $c['kernel'];
$response = kernel_response();
if ($response && is_a($kernel, 'Symfony\Component\HttpKernel\TerminableInterface')) {
$router_item = menu_get_item();
$request = $router_item['page_arguments'][0];
/* @var \Symfony\Component\HttpKernel\TerminableInterface $kernel */
$kernel->terminate($request, $response);
}
}
/**
* Implements hook_init().
*/
function kernel_init() {
$c = pimple_get_container('app');
/* @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router */
$router = $c['router'];
try {
$path = current_path();
$router->match(base_path() . $path);
$router_item = $c['router.transformer']($path);
// If the desire is to output a whole Symfony response, use:
//
// $router_item['page_callback'] = array($kernel, 'handle');
// $router_item['page_arguments'] = array($request);
// $router_item['delivery_callback'] = 'kernel_deliver_response';
menu_set_item(NULL, $router_item);
}
catch (\Exception $e) {
}
}
/**
* Delivers the response and shuts down the kernel and Drupal.
*
* @see drupal_deliver_html_page()
*/
function kernel_deliver_response(\Symfony\Component\HttpFoundation\Response $response) {
$response->send();
module_invoke_all('exit');
// Commit the user session, if needed.
drupal_session_commit();
if (variable_get('cache', 0) && ($cache = drupal_page_set_cache())) {
drupal_serve_page_from_cache($cache);
}
_registry_check_code(REGISTRY_WRITE_LOOKUP_CACHE);
drupal_cache_system_paths();
module_implements_write_cache();
system_run_automated_cron();
exit();
}