{ Hello Magento 2 }

解决 Magento 2 应用问题,更注重深度挖掘。(ง •̀_•́)ง


Virtual Type

A virtual type allows the developer to create an instance of an existing class that has custom constructor arguments. This is useful in cases where you need a “new” class only because the constructor arguments need to be changed. This is used frequently in Magento to reduce redundant PHP classes.

Practices Tests

You are making some major adjustments to a core Magento class (ClassA). These adjustments are only necessary when utilized from a specific Magento class (ClassB). You have created MyClass that contains the needed customizations. Keeping upgradeability in mind, how do you configure di.xml to make the substitution happen? A. Ensure that MyClass extends ModuleA and set the <argument/>, for ModuleB to point to your new class in di.xml. B. Set a <preference/> for ModuleA to be replaced by MyClass C. Create a virtual type that extends ModuleB, specifying an <argument/> for MyClass. D. Create a rewrite node that injects MyClass into ClassB. Answer A