I am currently updating an old application from Symfony 3.4. I get the following deprecation:
User Deprecated: The "security.encoder_factory" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
I get the same problem for another service: fos_user.change_password.form.factory
Here is my Controller, which I use:
<?phpnamespace AppBundle\Controller;use AppBundle\Form\UserType;use Doctrine\DBAL\Exception\UniqueConstraintViolationException;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Bundle\FrameworkBundle\Controller\Controller;use Symfony\Component\HttpFoundation\Request;use FOS\UserBundle\Model\UserInterface;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Security\Core\Exception\AccessDeniedException;class ProfileAdminController extends Controller{/** * @Route("/profile", name="editProfile") */public function indexAction(Request $request){ $user = $this->getUser(); if (!is_object($user) || !$user instanceof UserInterface) { throw new AccessDeniedException('This user does not have access to this section.'); } $groups = $this->getDoctrine()->getRepository('AppBundle:Group')->findAll(); $formUser = $this->createForm(UserType::class, $user, array('groups' => $groups, 'type' => 'profile')); /** Passwort edit */ $formFactory = $this->get('fos_user.change_password.form.factory'); //$formFactory = $changecontroller; $formPw = $formFactory->createForm(); $formPw->setData($user); /** User edit */ $formUser->handleRequest($request); if ($formUser->isSubmitted() && $formUser->isValid()) { // 3) save the User! $em = $this->getDoctrine()->getManager(); try { $em->persist($user); $em->flush(); } catch(UniqueConstraintViolationException $e) { $this->addFlash('danger','Ein eindeutiges Attribut wurde doppelt vergeben!' ); } $this->addFlash('info','Angaben erfolgreich geändert!' ); } else if ($formUser->isSubmitted() && !$formUser->isValid()) { $validator = $this->get('validator'); return $this->render('administration/profile/edit.html.twig', array('formPw' => $formPw->createView(),'formUser' => $formUser->createView(),'errors' => $validator->validate($user), )); } /** Passwort edit */ $formPwPostData = $request->request->get('fos_user_change_password_form'); /** Check if current password is correct */ $factory = $this->get('security.encoder_factory'); $encoder = $factory->getEncoder($user); $pwCorrect = ($encoder->isPasswordValid($user->getPassword(),$formPwPostData['current_password'],$user->getSalt())) ? true : false;
I cannot fix this issue. Could anyone help?
BR, Andreas