你可以覆盖其中的类吗 \lib\internal\Magento\Framework 如果是这样怎么办?我知道如何使用 插件/首选项 覆盖中的类 \code 但这些方法似乎不适用于 lib 类。谢谢。

有帮助吗?

解决方案

使用首选项绝对可行。

你可以在 a 中做这样的事情 di.xml 文件:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Framework\Class\You\Want\To\Rewrite" type="Vendor\Module\Your\Class" />
</config>

这种方法在Magento 2原始文件中被广泛使用,例如: https://github.com/magento/magento2/blob/develop/app/code/Magento/Backend/etc/di.xml

许可以下: CC-BY-SA归因
scroll top