改名
This commit is contained in:
+58
-7
@@ -28,6 +28,9 @@ class Loader extends BaseObject
|
|||||||
private array $_fileMap = [];
|
private array $_fileMap = [];
|
||||||
|
|
||||||
|
|
||||||
|
private array $_directoryMap = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $path
|
* @param $path
|
||||||
* @param $namespace
|
* @param $namespace
|
||||||
@@ -119,6 +122,7 @@ class Loader extends BaseObject
|
|||||||
*/
|
*/
|
||||||
public function _scanDir(DirectoryIterator $paths, $namespace)
|
public function _scanDir(DirectoryIterator $paths, $namespace)
|
||||||
{
|
{
|
||||||
|
$DIRECTORY = $this->createDirectoryMap($paths);
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
if ($path->getFilename() === '.' || $path->getFilename() === '..') {
|
if ($path->getFilename() === '.' || $path->getFilename() === '..') {
|
||||||
continue;
|
continue;
|
||||||
@@ -130,19 +134,17 @@ class Loader extends BaseObject
|
|||||||
$this->_scanDir(new DirectoryIterator($path->getRealPath()), $namespace);
|
$this->_scanDir(new DirectoryIterator($path->getRealPath()), $namespace);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($path->getExtension() !== 'php') {
|
if ($path->getExtension() !== 'php') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$replace = str_replace(APP_PATH . '/', '', $path->getRealPath());
|
if (!in_array($path->getRealPath(), $this->_directoryMap[$DIRECTORY])) {
|
||||||
|
$this->_directoryMap[$DIRECTORY][] = $path->getRealPath();
|
||||||
$replace = str_replace('.php', '', $replace);
|
}
|
||||||
$replace = str_replace(DIRECTORY_SEPARATOR, '\\', $replace);
|
|
||||||
$explode = explode('\\', $replace);
|
|
||||||
array_shift($explode);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$replace = Snowflake::getDi()->getReflect($namespace . implode('\\', $explode));
|
$replace = Snowflake::getDi()->getReflect($this->explodeFileName($path, $namespace));
|
||||||
if (empty($replace) || !$replace->isInstantiable()) {
|
if (empty($replace) || !$replace->isInstantiable()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -190,6 +192,55 @@ class Loader extends BaseObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param DirectoryIterator $path
|
||||||
|
* @param string $namespace
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function explodeFileName(DirectoryIterator $path, string $namespace): string
|
||||||
|
{
|
||||||
|
$replace = str_replace(APP_PATH . '/', '', $path->getRealPath());
|
||||||
|
|
||||||
|
$replace = str_replace('.php', '', $replace);
|
||||||
|
$replace = str_replace(DIRECTORY_SEPARATOR, '\\', $replace);
|
||||||
|
$explode = explode('\\', $replace);
|
||||||
|
array_shift($explode);
|
||||||
|
|
||||||
|
return $namespace . implode('\\', $explode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param DirectoryIterator $directoryIterator
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function createDirectoryMap(DirectoryIterator $directoryIterator): string
|
||||||
|
{
|
||||||
|
$DIRECTORY = explode(DIRECTORY_SEPARATOR, $directoryIterator->getRealPath());
|
||||||
|
array_pop($DIRECTORY);
|
||||||
|
|
||||||
|
$DIRECTORY = implode(DIRECTORY_SEPARATOR, $DIRECTORY);
|
||||||
|
|
||||||
|
if (!isset($this->_directoryMap[$DIRECTORY])) {
|
||||||
|
$this->_directoryMap[$DIRECTORY] = [];
|
||||||
|
}
|
||||||
|
return $DIRECTORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $Directory
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getDirectoryFiles(string $Directory): array
|
||||||
|
{
|
||||||
|
if (!isset($this->_directoryMap[$Directory])) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return $this->_directoryMap[$Directory];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|||||||
Reference in New Issue
Block a user