PHP中的嵌套接口

时间:2019-02-09 09:11:52

标签: php typescript interface

我想在PHP中连接此TypeScript模型:

export interface Tournament {
    id: number;
    name: string;
    phases: {
        league: {
            groups: number;
            twoLegged: boolean;
        },
        playoff: {
            twoLegged: boolean;
        }
    };
}

我知道的唯一解决方案就是这个:

/**
 * @property int $id
 * @property int $name
 * @property Tournament_Phases $phases
 */
interface Tournament
{
}

/**
 * @property Tournament_Phase_League $league
 * @property Tournament_Phase_Playoff $playoff
 */
interface Tournament_Phases
{
}

/**
 * @property int $groups
 * @property bool $twoLegged
 */
interface Tournament_Phase_League
{
}
...

如果模型变大,则声明的接口数将相应增加。

还有其他更简洁的方法来声明嵌套对象接口吗?

编辑:

anonymous classes,有某种匿名接口吗?像这样:

interface Tournament
{
    public $phases = new interface {
        $league= new interface {
             $groups;
             $twoLegged;
         }
        $playoff = ...;
    }
}

0 个答案:

没有答案