禁止显示“不明确的类解析”警告



有没有办法在运行composer install时禁用"不明确的类解析"警告?

我使用一个包,该包在不同的文件夹中具有相同名称(和命名空间(的类。

我知道这个错误,但事实并非如此,因为这些类实际上在供应商中是两次。我对此无能为力。

我也知道 --no-autoloader 标志,它当然不会抛出警告,而只是因为它跳过了自动加载器的生成。

与其从vendor目录中删除文件(应该避免(,不如将具有不明确类的文件/文件添加到composer.json exclude-from-classmap部分:

"autoload": {
    ...
    "exclude-from-classmap": [
        "vendor/somevendor/somepackage/directory/with/ambiguous/classes/",
        "vendor/somevendor/somepackage/src/AmbiguousClass.php"
    ]
},

然后,Composer 将在类映射生成期间忽略这些文件。

找到了一个解决方案,尽管它不是那么明显。在这里写过。

使用 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中。它用于示例(作为软件包的一部分(,如果没有供应商/自动加载可用.php则与 PPAutoloader 一起加载。但是这个内部逻辑(必须调用自动加载器(与"作曲家自动加载器生成过程"无关,该过程贯穿所有文件夹并构建自己的配置。

那么解决方案是什么?

无法从自动加载器生成过程中排除文件夹(位于供应商文件夹中(。当然,您可以使用 --no-autoloader 标志运行作曲家。但是,您需要自己处理自动加载,这对于"仅"产生警告的问题来说有点激烈。

在这种情况下,有一种更简单的方法。由于此类仅与示例相关(系统中未使用(,因此我可以简单地删除该文件。

为此,我使用了 composer.json 的脚本部分和预自动加载转储命令事件(在自动加载器生成过程之前触发(。该命令将删除包含PayPalAPIInterfaceService的服务文件夹。

"scripts": {
    "pre-autoload-dump": [
        "rm -rf vendor/paypal/merchant-sdk-php/lib/services"
    ]
},

删除供应商目录并运行composer install为我消除了错误。

相关内容

  • 没有找到相关文章

最新更新