我正在尝试在我自己的服务中使用全局验证器服务,如下所示:
# app/config/services.yml
services:
app.handler.user:
class: AppBundle\Handler\UserHandler
arguments: ["@doctrine.orm.entity_manager", "@validator"]
# AppBundle/Handler/UserHandler.php
namespace AppBundle\Handler;
use Doctrine\ORM\EntityManager;
use AppBundle\Entity\User;
use Symfony\Component\Validator\Validator\ValidatorInterface;
class UserHandler
{
public function __construct(EntityManager $entityManager, ValidatorInterface $validator)
{
$this->em = $entityManager;
$this->validator = $validator;
}
public function add(User $user)
{
$errors = $this->validator->validate($user);
return $errors;
}
}
但是当我调用验证方法时,它会抛出错误:
严格的电子邮件验证需要egulias / email-validator
我使用的Symfony版本是3.1 在Symfony 3.0 +中使用验证器服务是否已弃用?