Php 更好地理解magento接口

Php 更好地理解magento接口,php,magento,interface,magento2,Php,Magento,Interface,Magento2,在magento中,在项目的每个步骤中,您都可以找到接口的实例,就像下面这个函数中的示例一样: public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) { //Upgrade schema logic } 如何创建接口的实例,如果我很好地理解接口,就不可能有接口对象 SchemaSetupInterface $setup, ModuleContextInter

在magento中,在项目的每个步骤中,您都可以找到接口的实例,就像下面这个函数中的示例一样:

public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) 
{
        //Upgrade schema logic
}
如何创建接口的实例,如果我很好地理解接口,就不可能有接口对象

SchemaSetupInterface $setup, 
ModuleContextInterface $context

这是一种很好的编程,在Magento中,它与依赖注入(DI)模式有关

通用接口使用 接口定义了类必须实现的最少功能。因此,如果函数接受类型为
SchemaSetupInterface
的接口,它只需要一个实现
SchemaSetupInterface
中定义的函数的类

在这种特殊情况下,接口定义如下,
upgrade
函数需要一个实现
getIdxName($tableName,$fields,$indexType='')的类
getFkName($priTableName、$priColumnName、$refTableName、$refColumnName)


通过此配置,Magento将
\Magento\Setup\Module\Setup
的一个实例传递给升级功能,该实例定义如下