4

There are lots of descendants of Mage_Eav_Model_Entity_Setup for example

class Mage_Checkout_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
{
}

But all of them are empty.

What is the use of having all these empty classes?

Is it just for the sake of extensibiliy and to keep common functions that are shared in different setup scripts of the same module?

I was thinking there might be some kind of module autodetection triggered by these custom classes, but could not find any hints into this direction).

(Based on Magento Certification Study Guide: What are the advantages of using a custom setup class for manipulating EAV attributes in a custom module).

4

2 回答 2

7

First, you need to understand that Magento organizes it's code into modules. The idea behind a module is to both help and force a developer to write their code in such a way that their code doesn't interfere with other system code.

Second, when a module needs to create persistant data in the Magento database, you create a setup resource (self-link). A setup resource is an installer script that has access to special functions/methods via its parent class. These special functions/methods help the developer create and populate tables in the database for their data structures. Many of these methods can be found on the Mage_Eav_Model_Entity_Setup class.

When a developer creates a setup resource for their own module, they create a new class. By creating a new class they ensure that any special methods their setup resources need will have a place to live. The Mage_Checkout_Model_Resource_Setup class is the Mage_Checkout module's setup resource class. It just so happens that this module didn't need extra methods. Earlier versions of Magento forced (at least, I believe they did) module developers to create their own setup resource classes if they wanted to use the setup resource feature. This was done because, as mentioned in paragraph one, Magento's module system is there to help ensure code from Module A doesn't interfere with Module B.

于 2012-07-24T17:09:08.770 回答
2

In order to understand the logic, you'll have to give Alan Storm's tutorials a read. Maybe you should read them in the proper order, but you can also jump straight to this one. They definitely helped me understand what's going on a few years ago.

于 2012-07-24T16:51:26.877 回答