@@ -45,63 +45,66 @@ class ClassLoader
45
45
/** @var \Closure(string):void */
46
46
private static $ includeFile ;
47
47
48
- /** @var string|null */
48
+ /** @var ? string */
49
49
private $ vendorDir ;
50
50
51
51
// PSR-4
52
52
/**
53
- * @var array<string, array<string, int>>
53
+ * @var array[]
54
+ * @psalm-var array<string, array<string, int>>
54
55
*/
55
56
private $ prefixLengthsPsr4 = array ();
56
57
/**
57
- * @var array<string, list<string>>
58
+ * @var array[]
59
+ * @psalm-var array<string, array<int, string>>
58
60
*/
59
61
private $ prefixDirsPsr4 = array ();
60
62
/**
61
- * @var list<string>
63
+ * @var array[]
64
+ * @psalm-var array<string, string>
62
65
*/
63
66
private $ fallbackDirsPsr4 = array ();
64
67
65
68
// PSR-0
66
69
/**
67
- * List of PSR-0 prefixes
68
- *
69
- * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
70
- *
71
- * @var array<string, array<string, list<string>>>
70
+ * @var array[]
71
+ * @psalm-var array<string, array<string, string[]>>
72
72
*/
73
73
private $ prefixesPsr0 = array ();
74
74
/**
75
- * @var list<string>
75
+ * @var array[]
76
+ * @psalm-var array<string, string>
76
77
*/
77
78
private $ fallbackDirsPsr0 = array ();
78
79
79
80
/** @var bool */
80
81
private $ useIncludePath = false ;
81
82
82
83
/**
83
- * @var array<string, string>
84
+ * @var string[]
85
+ * @psalm-var array<string, string>
84
86
*/
85
87
private $ classMap = array ();
86
88
87
89
/** @var bool */
88
90
private $ classMapAuthoritative = false ;
89
91
90
92
/**
91
- * @var array<string, bool>
93
+ * @var bool[]
94
+ * @psalm-var array<string, bool>
92
95
*/
93
96
private $ missingClasses = array ();
94
97
95
- /** @var string|null */
98
+ /** @var ? string */
96
99
private $ apcuPrefix ;
97
100
98
101
/**
99
- * @var array<string, self>
102
+ * @var self[]
100
103
*/
101
104
private static $ registeredLoaders = array ();
102
105
103
106
/**
104
- * @param string|null $vendorDir
107
+ * @param ? string $vendorDir
105
108
*/
106
109
public function __construct ($ vendorDir = null )
107
110
{
@@ -110,7 +113,7 @@ public function __construct($vendorDir = null)
110
113
}
111
114
112
115
/**
113
- * @return array< string, list<string>>
116
+ * @return string[]
114
117
*/
115
118
public function getPrefixes ()
116
119
{
@@ -122,39 +125,44 @@ public function getPrefixes()
122
125
}
123
126
124
127
/**
125
- * @return array<string, list<string>>
128
+ * @return array[]
129
+ * @psalm-return array<string, array<int, string>>
126
130
*/
127
131
public function getPrefixesPsr4 ()
128
132
{
129
133
return $ this ->prefixDirsPsr4 ;
130
134
}
131
135
132
136
/**
133
- * @return list<string>
137
+ * @return array[]
138
+ * @psalm-return array<string, string>
134
139
*/
135
140
public function getFallbackDirs ()
136
141
{
137
142
return $ this ->fallbackDirsPsr0 ;
138
143
}
139
144
140
145
/**
141
- * @return list<string>
146
+ * @return array[]
147
+ * @psalm-return array<string, string>
142
148
*/
143
149
public function getFallbackDirsPsr4 ()
144
150
{
145
151
return $ this ->fallbackDirsPsr4 ;
146
152
}
147
153
148
154
/**
149
- * @return array<string, string> Array of classname => path
155
+ * @return string[] Array of classname => path
156
+ * @psalm-return array<string, string>
150
157
*/
151
158
public function getClassMap ()
152
159
{
153
160
return $ this ->classMap ;
154
161
}
155
162
156
163
/**
157
- * @param array<string, string> $classMap Class to filename map
164
+ * @param string[] $classMap Class to filename map
165
+ * @psalm-param array<string, string> $classMap
158
166
*
159
167
* @return void
160
168
*/
@@ -171,25 +179,24 @@ public function addClassMap(array $classMap)
171
179
* Registers a set of PSR-0 directories for a given prefix, either
172
180
* appending or prepending to the ones previously set for this prefix.
173
181
*
174
- * @param string $prefix The prefix
175
- * @param list< string> |string $paths The PSR-0 root directories
176
- * @param bool $prepend Whether to prepend the directories
182
+ * @param string $prefix The prefix
183
+ * @param string[] |string $paths The PSR-0 root directories
184
+ * @param bool $prepend Whether to prepend the directories
177
185
*
178
186
* @return void
179
187
*/
180
188
public function add ($ prefix , $ paths , $ prepend = false )
181
189
{
182
- $ paths = (array ) $ paths ;
183
190
if (!$ prefix ) {
184
191
if ($ prepend ) {
185
192
$ this ->fallbackDirsPsr0 = array_merge (
186
- $ paths ,
193
+ ( array ) $ paths ,
187
194
$ this ->fallbackDirsPsr0
188
195
);
189
196
} else {
190
197
$ this ->fallbackDirsPsr0 = array_merge (
191
198
$ this ->fallbackDirsPsr0 ,
192
- $ paths
199
+ ( array ) $ paths
193
200
);
194
201
}
195
202
@@ -198,19 +205,19 @@ public function add($prefix, $paths, $prepend = false)
198
205
199
206
$ first = $ prefix [0 ];
200
207
if (!isset ($ this ->prefixesPsr0 [$ first ][$ prefix ])) {
201
- $ this ->prefixesPsr0 [$ first ][$ prefix ] = $ paths ;
208
+ $ this ->prefixesPsr0 [$ first ][$ prefix ] = ( array ) $ paths ;
202
209
203
210
return ;
204
211
}
205
212
if ($ prepend ) {
206
213
$ this ->prefixesPsr0 [$ first ][$ prefix ] = array_merge (
207
- $ paths ,
214
+ ( array ) $ paths ,
208
215
$ this ->prefixesPsr0 [$ first ][$ prefix ]
209
216
);
210
217
} else {
211
218
$ this ->prefixesPsr0 [$ first ][$ prefix ] = array_merge (
212
219
$ this ->prefixesPsr0 [$ first ][$ prefix ],
213
- $ paths
220
+ ( array ) $ paths
214
221
);
215
222
}
216
223
}
@@ -219,28 +226,27 @@ public function add($prefix, $paths, $prepend = false)
219
226
* Registers a set of PSR-4 directories for a given namespace, either
220
227
* appending or prepending to the ones previously set for this namespace.
221
228
*
222
- * @param string $prefix The prefix/namespace, with trailing '\\'
223
- * @param list< string> |string $paths The PSR-4 base directories
224
- * @param bool $prepend Whether to prepend the directories
229
+ * @param string $prefix The prefix/namespace, with trailing '\\'
230
+ * @param string[] |string $paths The PSR-4 base directories
231
+ * @param bool $prepend Whether to prepend the directories
225
232
*
226
233
* @throws \InvalidArgumentException
227
234
*
228
235
* @return void
229
236
*/
230
237
public function addPsr4 ($ prefix , $ paths , $ prepend = false )
231
238
{
232
- $ paths = (array ) $ paths ;
233
239
if (!$ prefix ) {
234
240
// Register directories for the root namespace.
235
241
if ($ prepend ) {
236
242
$ this ->fallbackDirsPsr4 = array_merge (
237
- $ paths ,
243
+ ( array ) $ paths ,
238
244
$ this ->fallbackDirsPsr4
239
245
);
240
246
} else {
241
247
$ this ->fallbackDirsPsr4 = array_merge (
242
248
$ this ->fallbackDirsPsr4 ,
243
- $ paths
249
+ ( array ) $ paths
244
250
);
245
251
}
246
252
} elseif (!isset ($ this ->prefixDirsPsr4 [$ prefix ])) {
@@ -250,18 +256,18 @@ public function addPsr4($prefix, $paths, $prepend = false)
250
256
throw new \InvalidArgumentException ("A non-empty PSR-4 prefix must end with a namespace separator. " );
251
257
}
252
258
$ this ->prefixLengthsPsr4 [$ prefix [0 ]][$ prefix ] = $ length ;
253
- $ this ->prefixDirsPsr4 [$ prefix ] = $ paths ;
259
+ $ this ->prefixDirsPsr4 [$ prefix ] = ( array ) $ paths ;
254
260
} elseif ($ prepend ) {
255
261
// Prepend directories for an already registered namespace.
256
262
$ this ->prefixDirsPsr4 [$ prefix ] = array_merge (
257
- $ paths ,
263
+ ( array ) $ paths ,
258
264
$ this ->prefixDirsPsr4 [$ prefix ]
259
265
);
260
266
} else {
261
267
// Append directories for an already registered namespace.
262
268
$ this ->prefixDirsPsr4 [$ prefix ] = array_merge (
263
269
$ this ->prefixDirsPsr4 [$ prefix ],
264
- $ paths
270
+ ( array ) $ paths
265
271
);
266
272
}
267
273
}
@@ -270,8 +276,8 @@ public function addPsr4($prefix, $paths, $prepend = false)
270
276
* Registers a set of PSR-0 directories for a given prefix,
271
277
* replacing any others previously set for this prefix.
272
278
*
273
- * @param string $prefix The prefix
274
- * @param list< string> |string $paths The PSR-0 base directories
279
+ * @param string $prefix The prefix
280
+ * @param string[] |string $paths The PSR-0 base directories
275
281
*
276
282
* @return void
277
283
*/
@@ -288,8 +294,8 @@ public function set($prefix, $paths)
288
294
* Registers a set of PSR-4 directories for a given namespace,
289
295
* replacing any others previously set for this namespace.
290
296
*
291
- * @param string $prefix The prefix/namespace, with trailing '\\'
292
- * @param list< string> |string $paths The PSR-4 base directories
297
+ * @param string $prefix The prefix/namespace, with trailing '\\'
298
+ * @param string[] |string $paths The PSR-4 base directories
293
299
*
294
300
* @throws \InvalidArgumentException
295
301
*
@@ -423,8 +429,7 @@ public function unregister()
423
429
public function loadClass ($ class )
424
430
{
425
431
if ($ file = $ this ->findFile ($ class )) {
426
- $ includeFile = self ::$ includeFile ;
427
- $ includeFile ($ file );
432
+ (self ::$ includeFile )($ file );
428
433
429
434
return true ;
430
435
}
@@ -475,9 +480,9 @@ public function findFile($class)
475
480
}
476
481
477
482
/**
478
- * Returns the currently registered loaders keyed by their corresponding vendor directories.
483
+ * Returns the currently registered loaders indexed by their corresponding vendor directories.
479
484
*
480
- * @return array<string, self>
485
+ * @return self[]
481
486
*/
482
487
public static function getRegisteredLoaders ()
483
488
{
@@ -555,10 +560,7 @@ private function findFileWithExtension($class, $ext)
555
560
return false ;
556
561
}
557
562
558
- /**
559
- * @return void
560
- */
561
- private static function initializeIncludeClosure ()
563
+ private static function initializeIncludeClosure (): void
562
564
{
563
565
if (self ::$ includeFile !== null ) {
564
566
return ;
@@ -572,8 +574,8 @@ private static function initializeIncludeClosure()
572
574
* @param string $file
573
575
* @return void
574
576
*/
575
- self ::$ includeFile = \Closure:: bind ( static function ($ file ) {
577
+ self ::$ includeFile = static function ($ file ) {
576
578
include $ file ;
577
- }, null , null ) ;
579
+ };
578
580
}
579
581
}
0 commit comments