我发现了很多类似的其他问题,但没有适合我的问题的解决方案。
我尝试通过 Composer 使用 google/apiclient: 2.14 在我的 xampp 驱动的 Windows 系统上,本地完全没有问题。 如果我将代码部署到运行 apache 和 PHP 8.2.15 的 ubuntu 系统,则会出现以下警告:
PHP Warning: Class "Google_Service" not found in /var/www/admin/vendor/google/apiclient-services/autoload.php on line 21
PHP Warning: Class "Google_Service_Resource" not found in /var/www/admin/vendor/google/apiclient-services/autoload.php on line 21
PHP Warning: Class "Google_Model" not found in /var/www/admin/vendor/google/apiclient-services/autoload.php on line 21
PHP Warning: Class "Google_Collection" not found in /var/www/admin/vendor/google/apiclient-services/autoload.php on line 21
这是我的作曲家 JSON
{
"require": {
"google/apiclient": "2.14.0"
},
"scripts": {
"pre-autoload-dump": "Google\\Task\\Composer::cleanup"
},
"extra": {
"google/apiclient-services": [
"Drive",
"YouTube"
]
}
}
这是我的完整代码:
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
?>
根据此测试设置,我确信这是服务器问题。 我试图要求另一个包版本。 我安装了其他软件包来测试自动加载器 我尝试了无开发选项 我尝试在工作项目中使用它,结果相同。
那么为什么我总是在需要供应商自动加载器时收到此警告?
更改 google/apiclient-services/autoload.php 不是一个选项,因为每次推送功能时它都会重新生成。
我脑子里唯一想到的是像不区分大小写的东西,但我不知道如何解决这个问题。
似乎作曲家自动加载没有看到里面的类别名
vendor/google/apiclient/src/aliases.php
尝试运行自动加载器
composer dump-autoload
如果这不起作用,你可以像这样导入你的类
use Google\Service as Google_Service;
use Google\Service\Resource as Google_Service_Resource;
use Google\Model as Google_Model;
use Google\Collection as Google_Collection;
// or use them without aliases;
use Google\Service;
use Google\Service\Resource;
use Google\Model;
use Google\Collection;