Class 未在不同服务器中使用 composer autoload 找到

Class not found with composer autoload in different servers

我有一个非常简单的 PHP/Composer 应用程序,其结构如下:

- src
  - content
    - test
      - Sandbox.php

Sandbox.php只有一个打印"test"的静态函数,它的命名空间是

namespace MyApplication\Content\Test;

我的 autoload.php 有一个 MyApplication "autoload" 属性。

"autoload" : {
    "psr-4": {"MyApplication\": "src/"}
},

我 运行 composer install --no-dev 在 Windows 环境中 XAMPP 和 test.php 我做的文件(为了一个非常简单的测试):

$autoloadFile = __DIR__ . '/wp-content/plugins/sandbox/vendor/autoload.php';
require $autoloadFile;
echo 'autoload = ' . file_exists($autoloadFile);
echo '<br />';
echo 'class_exists = ' . class_exists('MyApplication\Content\Test\Sandbox');

当我在本地 运行 这个 test.php 文件时,它工作得很好。 MyApplication 正在加载沙盒 class。

但是,当我将其发布到我的服务器时,该服务器是基于 Linux 的服务器,但 运行 在 相同的 PHP 版本 上, 未找到沙盒 class。

我确保我的 /vendor/ 文件夹也已正确上传。

我想知道问题是否正在发生,因为我 运行 在 Windows 环境中安装作曲家,而它应该 运行 在我的服务器中安装相同的命令(我现在不能)。 /vendor/ 文件夹上传是否足以使自动加载 classes 正常工作?

您文件的路径是 src/content/test/Sandbox.php,根据 PSR-4,它应该是 src/Content/Test/Sandbox.php - 在 Windows 上没关系,但在 Linux 上它确实如此.