@@ -17,11 +17,21 @@ class Bootstrap
17
17
*/
18
18
private $ drupalRoot ;
19
19
20
+ /**
21
+ * @var \PHPStan\Drupal\ExtensionDiscovery
22
+ */
23
+ private $ extensionDiscovery ;
24
+
20
25
/**
21
26
* @var array
22
27
*/
23
28
private $ modules = [];
24
29
30
+ /**
31
+ * @var array
32
+ */
33
+ private $ themes = [];
34
+
25
35
public function __construct ()
26
36
{
27
37
$ autoload_file = $ GLOBALS ['autoloaderInWorkingDirectory ' ];
@@ -51,16 +61,28 @@ public function __construct()
51
61
52
62
public function register (): void
53
63
{
64
+ $ this ->extensionDiscovery = new ExtensionDiscovery ($ this ->drupalRoot );
65
+ $ this ->extensionDiscovery ->setProfileDirectories ([]);
66
+ $ profiles = $ this ->extensionDiscovery ->scan ('profile ' );
67
+ $ profile_directories = array_map (function ($ profile ) {
68
+ return $ profile ->getPath ();
69
+ }, $ profiles );
70
+ $ this ->extensionDiscovery ->setProfileDirectories ($ profile_directories );
71
+
72
+ $ this ->modules = $ this ->extensionDiscovery ->scan ('module ' );
73
+ $ this ->themes = $ this ->extensionDiscovery ->scan ('theme ' );
74
+
54
75
require $ this ->drupalRoot . '/core/includes/bootstrap.inc ' ;
55
76
require $ this ->drupalRoot . '/core/includes/common.inc ' ;
56
77
require $ this ->drupalRoot . '/core/includes/entity.inc ' ;
57
78
require $ this ->drupalRoot . '/core/includes/menu.inc ' ;
58
79
require $ this ->drupalRoot . '/core/includes/database.inc ' ;
59
80
require $ this ->drupalRoot . '/core/includes/file.inc ' ;
60
81
$ core_namespaces = $ this ->getCoreNamespaces ();
61
- $ module_namespaces = $ this ->loadModules ();
82
+ $ module_namespaces = $ this ->getModuleNamespaces ();
83
+ $ theme_namespaces = $ this ->getThemeNamespaces ();
62
84
63
- $ namespaces = array_merge ($ core_namespaces , $ module_namespaces );
85
+ $ namespaces = array_merge ($ core_namespaces , $ module_namespaces, $ theme_namespaces );
64
86
65
87
foreach ($ namespaces as $ prefix => $ paths ) {
66
88
if (is_array ($ paths )) {
@@ -78,6 +100,9 @@ public function register(): void
78
100
$ this ->autoloader ->add ('Drupal \\KernelTests ' , $ core_tests_dir );
79
101
$ this ->autoloader ->add ('Drupal \\FunctionalTests ' , $ core_tests_dir );
80
102
$ this ->autoloader ->add ('Drupal \\FunctionalJavascriptTests ' , $ core_tests_dir );
103
+
104
+ $ this ->loadModules ();
105
+ $ this ->loadThemes ();
81
106
}
82
107
83
108
/**
@@ -106,17 +131,8 @@ protected function getCoreNamespaces(): array
106
131
return $ namespaces ;
107
132
}
108
133
109
- protected function loadModules (): array
134
+ protected function getModuleNamespaces (): array
110
135
{
111
- $ listing = new ExtensionDiscovery ($ this ->drupalRoot );
112
- $ listing ->setProfileDirectories ([]);
113
- $ profiles = $ listing ->scan ('profile ' );
114
- $ profile_directories = array_map (function ($ profile ) {
115
- return $ profile ->getPath ();
116
- }, $ profiles );
117
- $ listing ->setProfileDirectories ($ profile_directories );
118
-
119
- $ this ->modules = $ listing ->scan ('module ' );
120
136
$ namespaces = [];
121
137
foreach ($ this ->modules as $ module_name => $ module ) {
122
138
$ module_dir = $ this ->drupalRoot . '/ ' . $ module ->getPath ();
@@ -141,6 +157,25 @@ protected function loadModules(): array
141
157
}
142
158
}
143
159
}
160
+ }
161
+
162
+ return $ namespaces ;
163
+ }
164
+
165
+ protected function getThemeNamespaces (): array
166
+ {
167
+ $ namespaces = [];
168
+ foreach ($ this ->themes as $ theme_name => $ theme ) {
169
+ $ theme_dir = $ this ->drupalRoot . '/ ' . $ theme ->getPath ();
170
+ $ namespaces ["Drupal \\$ theme_name " ] = $ theme_dir . '/src ' ;
171
+ }
172
+ return $ namespaces ;
173
+ }
174
+
175
+ protected function loadModules (): void
176
+ {
177
+ foreach ($ this ->modules as $ module_name => $ module ) {
178
+ $ module_dir = $ this ->drupalRoot . '/ ' . $ module ->getPath ();
144
179
// Need to ensure .module is enabled.
145
180
if ($ module ->getExtensionFilename () !== null ) {
146
181
require $ module_dir . '/ ' . $ module ->getExtensionFilename ();
@@ -163,7 +198,19 @@ protected function loadModules(): array
163
198
}
164
199
}
165
200
}
201
+ }
166
202
167
- return $ namespaces ;
203
+ protected function loadThemes (): void
204
+ {
205
+ foreach ($ this ->themes as $ theme_name => $ theme ) {
206
+ if ($ theme_name === 'bootstrap ' ) {
207
+ continue ;
208
+ }
209
+ $ theme_dir = $ this ->drupalRoot . '/ ' . $ theme ->getPath ();
210
+ // Need to ensure .theme is enabled.
211
+ if ($ theme ->getExtensionFilename () !== null ) {
212
+ require $ theme_dir . '/ ' . $ theme ->getExtensionFilename ();
213
+ }
214
+ }
168
215
}
169
216
}
0 commit comments