我目前正在做一个拉拉维尔休息的阿皮。我想编写一些测试,但是由于以下错误,它们在第二个测试函数之后失败了:
RecursiveDirectoryIterator::__construct(): Argument #1 ($directory) cannot be empty
at C:\Users\matth\Projekte\Cookbook\api\vendor\symfony\finder\Iterator\RecursiveDirectoryIterator.php:42
38▕ if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) {
39▕ throw new \RuntimeException('This iterator only support returning current as fileinfo.');
40▕ }
41▕
➜ 42▕ parent::__construct($path, $flags);
43▕ $this->ignoreUnreadableDirs = $ignoreUnreadableDirs;
44▕ $this->rootPath = $path;
45▕ if ('/' !== \DIRECTORY_SEPARATOR && !($flags & self::UNIX_PATHS)) {
46▕ $this->directorySeparator = \DIRECTORY_SEPARATOR;
1 C:\Users\matth\Projekte\Cookbook\api\vendor\symfony\finder\Iterator\RecursiveDirectoryIterator.php:42
RecursiveDirectoryIterator::__construct("")
2 C:\Users\matth\Projekte\Cookbook\api\vendor\symfony\finder\Finder.php:732
Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator::__construct("")
在查看laravel.log
时,我发现了以下内容:
[2022-07-18 12:56:58] local.ERROR: RecursiveDirectoryIterator::__construct(): Argument #1 ($directory) cannot be empty {"exception":"[object] (ValueError(code: 0): RecursiveDirectoryIterator::__construct(): Argument #1 ($directory) cannot be empty at C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\symfony\\finder\\Iterator\\RecursiveDirectoryIterator.php:42)
[stacktrace]
#0 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\symfony\\finder\\Iterator\\RecursiveDirectoryIterator.php(42): RecursiveDirectoryIterator->__construct('', 4096)
#1 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\symfony\\finder\\Finder.php(732): Symfony\\Component\\Finder\\Iterator\\RecursiveDirectoryIterator->__construct('', 4096, false)
#2 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\symfony\\finder\\Finder.php(615): Symfony\\Component\\Finder\\Finder->searchInDirectory('')
#3 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Bootstrap\\LoadConfiguration.php(88): Symfony\\Component\\Finder\\Finder->getIterator()
#4 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Bootstrap\\LoadConfiguration.php(65): Illuminate\\Foundation\\Bootstrap\\LoadConfiguration->getConfigurationFiles(Object(Illuminate\\Foundation\\Application))
#5 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Bootstrap\\LoadConfiguration.php(39): Illuminate\\Foundation\\Bootstrap\\LoadConfiguration->loadConfigurationFiles(Object(Illuminate\\Foundation\\Application), Object(Illuminate\\Config\\Repository))
#6 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(239): Illuminate\\Foundation\\Bootstrap\\LoadConfiguration->bootstrap(Object(Illuminate\\Foundation\\Application))
#7 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(310): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#8 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\ConfigCacheCommand.php(101): Illuminate\\Foundation\\Console\\Kernel->bootstrap()
#9 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\ConfigCacheCommand.php(71): Illuminate\\Foundation\\Console\\ConfigCacheCommand->getFreshConfiguration()
#10 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(36): Illuminate\\Foundation\\Console\\ConfigCacheCommand->handle()
#11 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#12 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#13 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#14 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(651): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#15 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(136): Illuminate\\Container\\Container->call(Array)
#16 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\symfony\\console\\Command\\Command.php(308): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#17 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#18 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\symfony\\console\\Application.php(998): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\symfony\\console\\Application.php(299): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Foundation\\Console\\ConfigCacheCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#20 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\symfony\\console\\Application.php(171): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#21 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Application.php(102): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 C:\\Users\\matth\\Projekte\\Cookbook\\api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#23 C:\\Users\\matth\\Projekte\\Cookbook\\api\\artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#24 {main}
"}
当查看api\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\LoadConfiguration.php
文件时,我发现对$app->configPath()
的调用有时会返回一个相对路径,这似乎不起作用。这是失败的时候。
在运行php artisan config:cache
时,我复制了相同的错误。在那里,清除工作(配置目录的完整路径),但一旦它再次开始读取配置以进行缓存,它就会接收到配置目录(\config
)的相对路径,并失败。
我发现了一些帖子,他们删除了config目录,但对我来说并非如此。此外,应用程序启动时没有任何问题(使用php artisan serve
)。我还尝试删除vendor
文件夹并重新安装,这没有帮助。
如果有人知道导致这种情况的原因,请与我分享:)
代码的存储库可以在这里找到:https://github.com/m-thalmann/Cookbook/tree/develop/api
发布于 2022-07-18 14:15:50
这似乎与我在.env
文件中设置的密钥有关。键APP_BASE_PATH
似乎被Laravel所使用,因此被覆盖。我在bootstrap\app.php
文件中找到了对它的引用。重新命名.env
文件中的密钥解决了这个问题。
https://stackoverflow.com/questions/73021629
复制相似问题