如何在一个验证器上验证一个操作的多个参数

问题描述

我尝试使用一个验证器一步验证一个函数的多个参数,而不是在单独的验证器中验证它们中的每一个。 这有两个原因:

  1. 我需要检查一些参数是否相等
  2. 我以相同的方式检查多个字段,因此会得到重复的代码
/**
 * Creates a new topic.
 *
 * @param Post $post The first post of the new topic.
 * @param string $subject The subject of the new topic
 *
 * @validate $post \xxx\Domain\Validator\Forum\PostValidator
 * @validate $subject \xxx\Domain\Validator\Forum\AntiSpamValidator(post = $post)
 */
public function createAction(Post $post,$subject) {
    ...
}

这是我根据这个主题尝试的:https://forge.typo3.org/issues/52231 但似乎我忘记了任何东西或者它只是不工作:(

当我在 AntiSpamValidator 上使用 print_r($this->options) 时,我只得到 Array([post] => $post),所以只有文本“$post”而不是我想要到达那里的 $post 对象。

那么如何将 $post 附加到 AntiSpamValidator?

提前谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)