php - 有没有办法在@property-read 中使用对象类型并“声明”它的属性?
问题描述
我想在其中添加一种对象,@property-read
并且还能够通过 PhpStorm 建议访问其属性。
这是我想做的事情:
/**
* @property-read object{type: string, schema: string} $request_schema
* @property-read object{type: string, schema: string} $response_schema
*/
class ConfigApiRoutesSchema extends BaseSchema
{
...
}
我这样做的原因是因为我想访问属性类型和架构,如下所示:
$configApiRoutesSchema = new ConfigApiRoutesSchema();
$configApiRoutesSchema->request_schema->type // Here's the problem, type is not suggested
$configApiRoutesSchema->request_schema->schema // schema is also not suggested
这正是我所需要的,但不幸的是,由于某种原因这不起作用。一种解决方案是创建两个类并将它们指定为类型:
/**
* @property-read string $type
* @property-read string $schema
*/
class RequestSchema {}
/**
* @property-read string $type
* @property-read string $schema
*/
class ResponseSchema {}
/**
* @property-read RequestSchema $request_schema
* @property-read ResponseSchema $response_schema
* @
*/
class ConfigApiRoutesSchema extends BaseSchema {}
现在 PhpStorm 建议模式和类型。
但这似乎不正确,因为RequestSchema
并且ResponseSchema
实际上不会被使用。所以我想知道是否有任何方法可以对对象使用注释,而不必创建一个类来建议它的属性。
谢谢你。
解决方案
推荐阅读
- reactjs - React:无法检查输入字段的类型
- java - Spring - 所有请求都将转到相同的映射
- php - PHP 代码在服务器中出现错误,但在本地运行良好
- android - REPO(aosp) 分支间切换
- android - Android - view.animate() 用于拖动后将视图恢复到旧位置
- bash - awk 如何找到第一个可用的日期字段?
- c# - 我想显示与以下课程的关系,但我收到了这些错误
- swift - 如何从项目文件 Swift 通知 UITestcase
- python - 让 gmsh 进入 virtualenv
- visual-studio-2017 - 程序 'xxx' 以代码 -55 (0xffffffc9) 退出