找到了一个解决方案,虽然不是那么明显。写了about it here。
当使用 paypal/merchant-sdk-php composer 包并运行 composer install 或 composer update 您会收到很多警告消息,如下所示:
...
Writing lock file
Generating autoload files
Warning: Ambiguous class resolution, "SetDataRequestType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/SetDataRequestType.php", the first will be used.
Warning: Ambiguous class resolution, "MerchantPullPaymentType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/MerchantPullPaymentType.php", the first will be used.
Warning: Ambiguous class resolution, "InitiateRecoupReq" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/InitiateRecoupReq.php", the first will be used.
Warning: Ambiguous class resolution, "CreateBillingAgreementResponseType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/CreateBillingAgreementResponseType.php", the first will be used.
Warning: Ambiguous class resolution, "MeasureType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/MeasureType.php", the first will be used.
Warning: Ambiguous class resolution, "BusinessInfoType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/BusinessInfoType.php", the first will be used.
Warning: Ambiguous class resolution, "ButtonSearchResultType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/ButtonSearchResultType.php", the first will be used.
Warning: Ambiguous class resolution, "SetAuthFlowParamReq" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/SetAuthFlowParamReq.php", the first will be used.
...
# Many more lines
Github 上已经有针对此问题的 bug 票证,但似乎没有以高优先级进行处理(因为它于 2014 年 7 月 31 日开放)。
找了一阵子,找到了问题的根源,就是/分别调用了PPAutoloader和PayPalAPIInterfaceService。 API 的每个类都被复制到 PayPalAPIInterfaceService 中。它用于示例(它是包的一部分),如果没有可用的 vendor/autoload.php 则使用 PPAutoloader 加载。但是这个内部逻辑(必须调用自动加载器)与“作曲家自动加载器生成过程”无关,它贯穿所有文件夹并构建它自己的配置。
那么解决办法是什么?
无法从自动加载器生成过程中排除文件夹(位于供应商文件夹中)。当然,您可以使用 --no-autoloader 标志运行 composer。但是你需要自己处理自动加载,这对于“仅”产生警告的问题来说有点激烈。
在这种情况下,有一种更简单的方法。由于该类仅与示例相关(系统中未使用),因此我可以简单地删除该文件。
为此,我使用 composer.json 的脚本部分和 pre-autoload-dump 命令事件(在自动加载器生成过程之前触发)。该命令删除包含 PayPalAPIInterfaceService 的服务文件夹。
"scripts": {
"pre-autoload-dump": [
"rm -rf vendor/paypal/merchant-sdk-php/lib/services"
]
},