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

时间:2019-07-02 17:35:20

标签: php laravel symfony homestead

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

In LoadConfiguration.php line 68:

Unable to load the "app" configuration file.

一些人suggest认为这是Windows(10)将文件名大写的原因。但是,这在我的文件夹中看不到,也不适用于我的Ubuntu(18.04)环境。

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

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

    $files[$directory.basename($file->getRealPath(), '.php')] = $file->getRealPath();
}

问题是发现程序确实返回了一个迭代器,该迭代器以某种方式找不到我的配置文件。一个简单的scandir($configPath)返回所有文件:

.
..
app.php
and all other files

将通话包裹在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}
        }
      }
    }
  }
}

假设我对这些类型的迭代器一无所知。两件事对我来说很突出:

  • 有很多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,

编辑

将我的宅基地降级为v8.0.1,一切正常。但是,仍然没有解释为什么在v9.0.1上发生这种情况。

2 个答案:

答案 0 :(得分:1)

尝试将VirtualBox更新到v6。有关更多帮助,请参见this GitHub issue

答案 1 :(得分:0)

我没有答案为什么会发生这种情况,但是我在 Finder 函数(在\ vendor \ laravel内部)中编写了使用LoadConfiguration::getConfigurationFiles的替代方法\ 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;
}

希望能帮助某人。