问题描述
我正在用PHPStorm在PHP中为Mongodb编写一个小型ODM。在汇总查询中:
$value = $this->creditRepo->execute(AggregateQueryBuilder::create()->project('name','ts')->take(10)->toQuery(),new class{
public ?string $name;
});
function execute(AggregateQuery $query,$class): ArrayObject
{
$result = $this->_collection->aggregate($query->getPipeline(),$query->getoptions());
$returnArray = new ArrayObject();
foreach ($result as $item){
$itemx = App::jsonMapper()->map($item,new $class); // $itemx is instance of $class
$returnArray->append($itemx);
}
return $returnArray;
}
调用者脚本中的结果:
$value = $this->creditRepo->execute(AggregateQueryBuilder::create()
->project('name',new class{
public ?string $name;
});
$d = $value->getArraycopy();
$d[0]-> // not type hint,I want it hint to me the <name>
PHPStorm是否可以知道我可以键入的execute()
的输出来提示其输出?
[编辑]
我尝试使用功能array_map
$value = $this->creditRepo->execute(AggregateQueryBuilder::create()
->project('name','ts')->take(10)->toQuery());
$temp = new class{
public ?string $name;
};
$output = array_map(static function ($item) use ($temp) {
$temp->name = $item['name'];
return $temp;
},(array)$value);
$output[0]->name // type hinted
我想编写一个PHPStorm知道返回的函数,例如array_map
怎么做?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)