forked from janschumann/drupal-dic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdic.helper.inc
executable file
·75 lines (64 loc) · 1.94 KB
/
dic.helper.inc
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
<?php
/**
* Classloading might happen as recently as in @see _dic_get_helper().
*
* !! So do not use a "use" statement here !!
*/
/**
* Returns the dic helper
*
* @return \Drupal\Dic\DicHelper
*/
function _dic_get_helper($re_initialize = false) {
static $helper;
if (!($helper instanceof \Drupal\Dic\DicHelper) || $re_initialize) {
// load dic parameters @see dic_menu()
$rootDir = variable_get('dic_root_dir', '');
if ('' == $rootDir) {
$rootDir = DRUPAL_ROOT . '/' . variable_get('file_public_path', 'assets') . '/dic';
}
$environment = variable_get('dic_environment', 'prod');
$debug = (boolean) variable_get('dic_debug', 0);
$configDir = variable_get('dic_config_dir', '');
if ('' == $configDir) {
$configDir = DRUPAL_ROOT . '/sites/default';
}
if (function_exists('drupal_classloader')) {
$loader = drupal_classloader();
} else {
throw new \Exception('The classloader is necessary to load ProjectKernel and DicHelper.');
}
// initialize kernel and helper
$kernel = new \Drupal\Dic\ProjectKernel($environment, $debug, $rootDir, $configDir);
$helper = new \Drupal\Dic\DicHelper($kernel);
$helper->setClassLoader($loader);
// provide the dic with bundle info
$bundleInfo = _dic_get_bundle_info(!$kernel->isDebug());
if (!empty($bundleInfo)) {
$helper->setBundleInfo($bundleInfo);
}
}
return $helper;
}
/**
* Fetch bundle info from other modules
*
* @param boolean $debug
*
* @return array
*/
function _dic_get_bundle_info($load_from_cache = true) {
$bundle_info = array();
if ($load_from_cache) {
$cache = cache_get('dic:bundle_info');
if (is_object($cache)) {
$bundle_info = $cache->data;
}
}
if (empty($bundle_info)) {
// fetch bundle information from modules
$bundle_info = module_invoke_all('dic_bundle_info');
cache_set('dic:bundle_info', $bundle_info);
}
return $bundle_info;
}