Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit adfe9c7

Browse files
committed
update something. update readme
1 parent 2775307 commit adfe9c7

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/AutoLoader.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ public static function getLoader(): self
7777
$loader->register(true);
7878

7979
foreach (self::$files as $fileIdentifier => $file) {
80-
globalIncludeFile($fileIdentifier, $file);
80+
_globalIncludeFile($fileIdentifier, $file);
8181
}
8282

8383
return $loader;
8484
}
8585

86-
//////////////////////////////////////////////////////
87-
/// independent files
88-
//////////////////////////////////////////////////////
86+
/**************************************************************************
87+
* independent files
88+
*************************************************************************/
8989

9090
/**
9191
* @return array
@@ -115,15 +115,15 @@ public static function addFiles(array $files)
115115
}
116116
}
117117

118-
//////////////////////////////////////////////////////
119-
/// class loader
120-
//////////////////////////////////////////////////////
118+
/**************************************************************************
119+
* class loader
120+
*************************************************************************/
121121

122122
/**
123123
* @param string $prefix
124124
* @param string $path
125125
*/
126-
public function addPsr0($prefix, $path)
126+
public function addPsr0(string $prefix, string $path)
127127
{
128128
$this->psr0Map[$prefix] = $path;
129129
}
@@ -145,7 +145,7 @@ public function addPsr0Map(array $psr0Map)
145145
* @param string $path
146146
* @throws \InvalidArgumentException
147147
*/
148-
public function addPsr4($prefix, $path)
148+
public function addPsr4(string $prefix, string $path)
149149
{
150150
// Register directories for a new namespace.
151151
$length = \strlen($prefix);
@@ -217,7 +217,7 @@ public function addClassMap(array $classMap)
217217
* Registers this instance as an autoloader.
218218
* @param bool $prepend Whether to prepend the autoloader or not
219219
*/
220-
public function register($prepend = false)
220+
public function register(bool $prepend = false)
221221
{
222222
\spl_autoload_register(array($this, 'loadClass'), true, $prepend);
223223
}
@@ -238,7 +238,7 @@ public function unRegister()
238238
public function loadClass($class)
239239
{
240240
if ($file = $this->findFile($class)) {
241-
includeClassFile($file);
241+
_includeClassFile($file);
242242

243243
return true;
244244
}
@@ -273,7 +273,12 @@ public function findFile($class)
273273
return $file;
274274
}
275275

276-
private function findFileWithExtension($class, $ext)
276+
/**
277+
* @param string $class
278+
* @param string $ext
279+
* @return bool|string
280+
*/
281+
private function findFileWithExtension(string $class, string $ext)
277282
{
278283
// PSR-4 lookup
279284
$logicalPathPsr4 = \str_replace('\\', DIRECTORY_SEPARATOR, $class) . $ext;
@@ -294,7 +299,9 @@ private function findFileWithExtension($class, $ext)
294299

295300
foreach ($this->psr0Map as $prefix => $dir) {
296301
if (0 === \strpos($class, $prefix)) {
297-
if (\file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
302+
$file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0;
303+
304+
if (\file_exists($file)) {
298305
return $file;
299306
}
300307
}
@@ -312,7 +319,7 @@ public function getMissingClasses(): array
312319
}
313320
}
314321

315-
function globalIncludeFile($fileIdentifier, $file)
322+
function _globalIncludeFile($fileIdentifier, $file)
316323
{
317324
if (empty($GLOBALS['__global_autoload_files'][$fileIdentifier])) {
318325
require $file;
@@ -326,7 +333,7 @@ function globalIncludeFile($fileIdentifier, $file)
326333
* Prevents access to $this/self from included files.
327334
* @param $file
328335
*/
329-
function includeClassFile($file)
336+
function _includeClassFile($file)
330337
{
331338
include $file;
332339
}

0 commit comments

Comments
 (0)