有没有办法在运行composer install
时禁用“不明确的类解析”警告?
我使用的包在不同的文件夹中具有相同名称(和命名空间)的类。
我知道this bug,但事实并非如此,因为这些类实际上是供应商的两倍。我无法做任何事情。
我也知道--no-autoloader
标志当然不会抛出警告,只是因为它会跳过自动加载器生成。
答案 0 :(得分:4)
找到了解决方案,虽然不是那么明显。写了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上已经有一个针对此问题的错误提示,但它似乎没有以高优先级处理(因为它于2014年7月31日开放)。
搜索了一段时间后,我找到了问题的根源,即/被称为PPAutoloader和PayPalAPIInterfaceService。每个API类都被复制到PayPalAPIInterfaceService中。它用于示例(它们是程序包的一部分),如果没有vendor / autoload.php可用,则加载PPAutoloader。但是这个内部逻辑(必须调用自动加载器)与“作曲家自动加载器生成过程”无关,该过程贯穿所有文件夹并构建它自己的配置。
那么解决方案是什么?
无法从自动装带器生成过程中排除文件夹(在供应商文件夹中)。当然,您可以使用--no-autoloader
标志运行composer。但是你需要自己处理自动加载,这对于“仅”产生警告的问题来说有点激烈。
在这种情况下,有一种更简单的方法。由于此类仅与示例(系统中未使用)相关,因此我可以删除该文件。
为此,我使用composer.json的脚本部分和pre-autoload-dump命令事件(在自动加载器生成过程之前触发)。该命令删除包含PayPalAPIInterfaceService的services文件夹。
"scripts": {
"pre-autoload-dump": [
"rm -rf vendor/paypal/merchant-sdk-php/lib/services"
]
},
答案 1 :(得分:3)
不是从vendor
目录中删除文件(应避免使用),最好将带有歧义类的文件/ direactories添加到composer.json
中的exclude-from-classmap
部分:
"autoload": {
...
"exclude-from-classmap": [
"vendor/somevendor/somepackage/directory/with/ambiguous/classes/",
"vendor/somevendor/somepackage/src/AmbiguousClass.php"
]
},
然后Composer将在生成类映射时忽略这些文件。
答案 2 :(得分:-1)
删除 vendor 目录并运行 composer install
为我消除了错误。