我有以下代码;
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
$builder->create(
'href',
'url',
$this->getOptionsForUrlWidget('Website URL')
)->addEventSubscriber(new GetResolvedUrlListener())
)
...
我的方法GetResolvedUrlListener
执行 curl 请求以发现正确的协议和最终地址(在重定向之后)以确定正确的 url。
如果 curl 请求没有收到成功的 HTTP 响应,我希望它导致验证失败。因此,如果提供的 url 不可访问,则不应保存。
这可以在实现 EventSubscriberInterface 的类中完成吗?我是否应该添加一个新的约束并验证提供的 url 两次?