Laravel / Symfony:无法加载“应用程序”配置文件

Tho*_*een 9 php symfony laravel homestead

升级Homestead并安装软件包后,我遇到了一个奇怪的错误。在调用时php artisan,给出以下内容作为输出:

In LoadConfiguration.php line 68:

Unable to load the "app" configuration file.
Run Code Online (Sandbox Code Playgroud)

少数人建议这是Windows(10)将文件名大写的原因。但是,这在我的文件夹中看不到,也不适用于我的Ubuntu(18.04)环境。

查看源代码,LoadConfiguration.php我们可以看到它正在使用组件中的Findersymfony/finder

foreach (Finder::create()->files()->name('*.php')->in($configPath) as $file) {
    $directory = $this->getNestedDirectory($file, $configPath);

    $files[$directory.basename($file->getRealPath(), '.php')] = $file->getRealPath();
}
Run Code Online (Sandbox Code Playgroud)

问题是查找程序确实返回了某种无法找到我的配置文件的迭代器。一个简单的scandir($configPath)返回所有文件:

.
..
app.php
and all other files
Run Code Online (Sandbox Code Playgroud)

将调用包装起来将iterator_to_array()返回一个空数组[]

通过添加返回以下对象..->in($configPath)->getIterator()

Symfony\Component\Finder\Iterator\PathFilterIterator {#47
  #matchRegexps: []
  #noMatchRegexps: array:2 [
    0 => "#(^|/)\..+(/|$)#"
    1 => "#(^|/)\..+(/|$)#"
  ]
  innerIterator: Symfony\Component\Finder\Iterator\FilenameFilterIterator {#43
    #matchRegexps: array:1 [
      0 => "#^(?=[^\.])[^/]*\.php$#"
    ]
    #noMatchRegexps: []
    innerIterator: Symfony\Component\Finder\Iterator\FileTypeFilterIterator {#39
      -mode: 1
      innerIterator: RecursiveIteratorIterator {#42
        innerIterator: Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator {#46
          -iterator: Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator {#48
            -ignoreUnreadableDirs: false
            -rewindable: null
            -rootPath: "/home/vagrant/somepath/api/config"
            -subPath: null
            -directorySeparator: "/"
            path: "/home/vagrant/somepath/api/config"
            filename: "app.php"
            basename: "app.php"
            pathname: "/home/vagrant/somepath/api/config/app.php"
            extension: "php"
            realPath: "./config/app.php"
            aTime: 2019-07-02 09:28:30
            mTime: 2019-01-31 17:43:49
            cTime: 2019-07-02 16:32:52
            inode: 429
            size: 9727
            perms: 0100777
            owner: 1000
            group: 1000
            type: "file"
            writable: true
            readable: true
            executable: true
            file: true
            dir: false
            link: false
          }
          -isRecursive: true
          -excludedDirs: array:9 [
            ".svn" => true
            "_svn" => true
            "CVS" => true
            "_darcs" => true
            ".arch-params" => true
            ".monotone" => true
            ".bzr" => true
            ".git" => true
            ".hg" => true
          ]
          -excludedPattern: null
          innerIterator: Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator {#48}
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

假设我对这些迭代器一无所知。我有两件事:

  • innerIterator存在很多。
  • 一个迭代器可以找到某些东西#48,我们可以看到我们的东西config/app.php,但是它在一个循环中ExcludeDirectoryFilterIterator

有人遇到过这个问题吗?或者知道如何引导我朝正确的方向发展吗?

使用了以下版本:

OS: Windows 10/Ubuntu 18.04 LTS
Homestead: 9.0.1
laravel/framework: 5.8.*/5.7.*
 \ symfony/finder: ^4.2/^4.1,
Run Code Online (Sandbox Code Playgroud)

编辑

将我的宅基地降级为v8.0.1,一切正常。但是仍然没有解释为什么会这样v9.0.1

w5m*_*w5m 0

我不知道为什么会发生这种情况,但我确实编写了一个FinderLoadConfiguration::getConfigurationFiles函数中使用的替代方案(在 \vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\LoadConfiguration.php 中),它允许我运行php artisan命令没有任何问题...

protected function getConfigurationFiles(Application $app)
{
    $files = [];

    $configPath = realpath($app->configPath());

    $file = new \DirectoryIterator($configPath);
    while($file->valid()) {
        if(!$file->isDot() && ($file->getExtension() == 'php')) {
            $directory = $this->getNestedDirectory($file, $configPath);
            $files[$directory.basename($file->getRealPath(), '.php')] = $file->getRealPath();
        }
        $file->next();
    }

    ksort($files, SORT_NATURAL);

    return $files;
}
Run Code Online (Sandbox Code Playgroud)

希望对某人有帮助。