我想在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 = ...;
}
}