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

@@ -29,6 +29,7 @@ use Chill\MainBundle\Form\Type\AddressType;
use Chill\MainBundle\Entity\Address;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* Class PersonAddressController
@@ -40,7 +41,21 @@ use Symfony\Component\HttpFoundation\Request;
*/
class PersonAddressController extends AbstractController
{
/**
* @var ValidatorInterface
*/
protected $validator;
/**
* PersonAddressController constructor.
*
* @param ValidatorInterface $validator
*/
public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;
}
public function listAction($person_id)
{
$person = $this->getDoctrine()->getManager()
@@ -302,9 +317,9 @@ class PersonAddressController extends AbstractController
*/
private function validatePerson(Person $person)
{
$errors = $this->get('validator')
$errors = $this->validator
->validate($person, null, array('Default'));
$errors_addresses_consistent = $this->get('validator')
$errors_addresses_consistent = $this->validator
->validate($person, null, array('addresses_consistent'));
foreach($errors_addresses_consistent as $error) {