【问题标题】:Laravel/Symfony: unable to load the "app" configuration fileLaravel/Symfony:无法加载“app”配置文件
【发布时间】:2019-11-13 09:37:01
【问题描述】:

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

In LoadConfiguration.php line 68:

Unable to load the "app" configuration file.

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

查看LoadConfiguration.php的源代码,我们可以看到它使用了symfony/finder组件中的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,

编辑

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

【问题讨论】:

  • 你升级 Laravel 了吗?
  • 是的,我测试了4.1symfony/finder 附带的5.75.8
  • 我在两天前将我的 Homestead vagrant box 更新到 v8.0.0 并将我的 Homestead 源代码更新到 v9.0.1 时遇到了同样的问题,从那以后我一直在苦苦挣扎。这是在 Windows 10 / Ubuntu 18.04.2 LTS / Laravel 5.6.26 / Finder 4.3.2 上。 @ThomasVanderVeen 您的 Homestead 盒子 (vagrant box list) 是什么版本?另外,您是否通过运行 git fetch --all 然后运行 ​​git checkout tags/v8.0.1 -b release 来降级您的 Homestead 源代码?
  • @w5m 当前运行的盒子版本 7.0.1 带有虚拟盒子。我确实跑了git checkout v8.0.1
  • 可能与case-sensitive有关。请同时检查文件的大小写。

标签: php laravel symfony homestead


【解决方案1】:

尝试将 VirtualBox 更新到 v6。如需更多帮助,请参阅this GitHub issue

【讨论】:

  • 非常感谢您发布链接@ncla - 你是救生员。我卸载了 Vagrant 并重新启动,卸载了 VirtualBox 5.2 并重新启动,安装了 VirtualBox 6.0.8 并重新启动,安装了 Vagrant 2.2.5 并重新启动,不得不摆弄 VirtualBox 网络适配器(遵循此评论的第 2 项:virtualbox.org/ticket/14832#comment:14)然后使用 Homestead v9.0.0 和 Settler v8.0.0 时一切正常。
【解决方案2】:

我不知道为什么会发生这种情况,但我确实在 LoadConfiguration::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;
}

希望对某人有所帮助。

【讨论】:

  • 感谢您的回答。 Ofc 你知道不得不改变源代码是不好的。
  • Thomas,谢天谢地,我的答案中的代码修改不需要 - 请参阅我对 @ncla 答案的评论。在 VirtualBox 6.0.8 上一切都很开心。
猜你喜欢
  • 1970-01-01
  • 2021-10-11
  • 2013-01-27
  • 1970-01-01
  • 2014-05-03
  • 2022-08-10
  • 2014-11-25
  • 2015-12-12
  • 2022-06-29
相关资源
最近更新 更多