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

@@ -32,6 +32,7 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* Class AccompanyingPeriodController
@@ -46,13 +47,20 @@ class AccompanyingPeriodController extends AbstractController
protected $eventDispatcher;
/**
* ReportController constructor.
* @var ValidatorInterface
*/
protected $validator;
/**
* AccompanyingPeriodController constructor.
*
* @param EventDispatcherInterface $eventDispatcher
* @param ValidatorInterface $validator
*/
public function __construct(EventDispatcherInterface $eventDispatcher)
public function __construct(EventDispatcherInterface $eventDispatcher, ValidatorInterface $validator)
{
$this->eventDispatcher = $eventDispatcher;
$this->validator = $validator;
}
/**
@@ -285,12 +293,14 @@ class AccompanyingPeriodController extends AbstractController
* @param Person $person
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
*/
private function _validatePerson(Person $person) {
$errors = $this->get('validator')->validate($person, null,
private function _validatePerson(Person $person)
{
$errors = $this->validator->validate($person, null,
array('Default'));
$errors_accompanying_period = $this->get('validator')->validate($person, null,
array('accompanying_period_consistent'));
$errors_accompanying_period = $this->validator->validate($person, null,
array('accompanying_period_consistent'));
foreach($errors_accompanying_period as $error ) {
$errors->add($error);
}