fix service dependency injection for validatorInterface

This commit is contained in:
2021-03-30 11:13:36 +02:00
parent 6ea45e4d16
commit 3a50aea138
7 changed files with 81 additions and 22 deletions

View File

@@ -11,6 +11,7 @@ use Chill\MainBundle\Form\UserType;
use Chill\MainBundle\Entity\GroupCenter;
use Chill\MainBundle\Form\Type\ComposedGroupCenterType;
use Chill\MainBundle\Form\UserPasswordType;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
@@ -28,14 +29,21 @@ class UserController extends AbstractController
*/
private $logger;
/**
* @var ValidatorInterface
*/
private $validator;
/**
* UserController constructor.
*
* @param LoggerInterface $logger
* @param ValidatorInterface $validator
*/
public function __construct(LoggerInterface $logger)
public function __construct(LoggerInterface $logger, ValidatorInterface $validator)
{
$this->logger = $logger;
$this->validator = $validator;
}
/**
@@ -258,7 +266,7 @@ class UserController extends AbstractController
$form[self::FORM_GROUP_CENTER_COMPOSED]->getData());
$user->addGroupCenter($groupCenter);
if ($this->get('validator')->validate($user)->count() === 0) {
if ($this->validator->validate($user)->count() === 0) {
$em->flush();
$this->addFlash('success', $this->get('translator')->trans('The '
@@ -267,7 +275,7 @@ class UserController extends AbstractController
return $this->redirect($this->generateUrl('admin_user_edit',
array('id' => $uid)));
} else {
foreach($this->get('validator')->validate($user) as $error)
foreach($this->validator->validate($user) as $error)
$this->addFlash('error', $error->getMessage());
}
}
@@ -380,7 +388,7 @@ class UserController extends AbstractController
// logging for prod
$this->logger->info('update password for an user', [
'by' => $this->getUser()->getUsername(),
'by' => $this->getUser()->getUsername(),
'user' => $user->getUsername()
]);