Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

InputBag::get can return array, too#45650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
DocFX wants to merge1 commit intosymfony:6.1fromDocFX:patch-4
Closed

InputBag::get can return array, too#45650

DocFX wants to merge1 commit intosymfony:6.1fromDocFX:patch-4

Conversation

@DocFX
Copy link
Contributor

Just a simple fix to help static code analysis. Simply using a form will trigger a returned array when calling::get() on the form name, for instance, containing all the keys.

QA
Branch?6.1 (mostly not to break previous code analysis)
Bug fix?no
New feature?no
Deprecations?no
Tickets
LicenseMIT
Doc PR

This doesn't break test, as it only changes PHPDoc.

6.1 only (not going back to 5.4 so as not to break static code analysis (I suppose this is better as it's also absolutely not critical).

Just a simple fix to help static code analysis. Simply using a form will trigger a returned array when calling `::get()` on the form name, for instance, containing all the keys.
@carsonbotcarsonbot added this to the6.1 milestoneMar 5, 2022
@ro0NL
Copy link
Contributor

InputBag::get can return array

it can not ;)

@DocFX
Copy link
ContributorAuthor

Then why do I have one? Am I a true magician? ;)

src/Form/Admin/UserPasswordType.php

<?phpdeclare(strict_types =1);namespaceApp\Form\Admin;useApp\Entity\User;useSymfony\Component\Form\AbstractType;useSymfony\Component\Form\Extension\Core\Type\PasswordType;useSymfony\Component\Form\Extension\Core\Type\RepeatedType;useSymfony\Component\Form\FormBuilderInterface;useSymfony\Component\OptionsResolver\OptionsResolver;useSymfony\Component\Security\Core\Validator\Constraints\UserPassword;useSymfony\Component\Validator\Constraints\Length;useSymfony\Component\Validator\Mapping\ClassMetadata;class UserPasswordTypeextends AbstractType{publicfunctionbuildForm(FormBuilderInterface$builder,array$options):void    {$builder            ->add('oldpassword',                PasswordType::class,                ['label'           =>'front.users.forms.password.oldpassword.label','mapped'          =>false,'required'        =>true,'empty_data'      =>'','invalid_message' =>'front.users.forms.password.invalid_repeated','help'            =>'front.users.forms.password.oldpassword.help',                ]            )            ->add('password',                RepeatedType::class,                ['type'            => PasswordType::class,'required'        =>true,'empty_data'      =>'','options'         => ['attr' => ['class' =>'password-field']],'first_options'   => ['label' =>'front.users.forms.password.first','attr'  => ['minlength' =>'6',                        ],'help'  =>'front.users.forms.password.help',                    ],'second_options'  => ['label' =>'front.users.forms.password.second','attr'  => ['minlength' =>'6',                        ],'help'  =>'front.users.forms.password.help',                    ],'invalid_message' =>'front.users.forms.password.invalid_repeated','help'            =>'front.users.forms.password.help','constraints'     => [newLength(['min' =>6,                        ]),                    ],                ]            );    }publicfunctionconfigureOptions(OptionsResolver$resolver):void    {$resolver->setDefaults(['data_class' => User::class,        ]);    }publicstaticfunctionloadValidatorData(ClassMetadata$metadata):void    {$metadata->addPropertyConstraint('oldpassword',newUserPassword(['message' =>'front.users.forms.password.oldpassword.error',            ])        );    }}

src/Controller/Front/AccountController.php

<?phpdeclare(strict_types =1);namespaceApp\Controller\Front;useApp\Entity\User;useApp\Form\Admin\UserPasswordType;useApp\Form\Front\UserType;useDoctrine\ORM\EntityManagerInterface;useSensio\Bundle\FrameworkExtraBundle\Configuration\Security;useSymfony\Bundle\FrameworkBundle\Controller\AbstractController;useSymfony\Component\HttpFoundation\File\Exception\FileException;useSymfony\Component\HttpFoundation\Request;useSymfony\Component\HttpFoundation\Response;useSymfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;useSymfony\Component\Routing\Annotation\Route;useSymfony\Contracts\Translation\TranslatorInterface;#[Route('/my-account')]#[Security("is_granted('ROLE_PARTICIPANT')")]class AccountControllerextends AbstractController{    #[Route('/edit-my-password', name:'my_account_password', methods: ['GET','POST'])]publicfunctionpasswordEdit(Request$request,TranslatorInterface$translator,UserPasswordHasherInterface$userPasswordHasher,EntityManagerInterface$em):Response    {/** @var User $user */$user =$this->getUser();$form =$this->createForm(UserPasswordType::class,$user);$form->handleRequest($request);if ($form->isSubmitted()            &&$form->isValid()            && !empty($request->request->get('user_password')['oldpassword'])            && !empty($request->request->get('user_password')['password']['first'])        ) {$user->setPassword($userPasswordHasher->hashPassword($user,$request->request->get('user_password')['password']['first']));$em->persist($user);$em->flush();$this->addFlash('success',$translator->trans('front.users.forms.password.success', ['{entity_name}' =>$user->getDisplayName()]));return$this->redirectToRoute('my_account', [], Response::HTTP_SEE_OTHER);        }return$this->renderForm('front/account/my_account_password.html.twig', ['user'       =>$user,'form'       =>$form,        ]);    }...

@ro0NL
Copy link
Contributor

perhaps check your deprecations on 5.4

trigger_deprecation('symfony/http-foundation','5.1','Retrieving a non-string value from "%s()" is deprecated, and will throw a "%s" exception in Symfony 6.0, use "%s::all($key)" instead.',__METHOD__, BadRequestException::class,__CLASS__);

@nicolas-grekas
Copy link
Member

Duplicate of#41766

derrabus and DocFX reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas marked this as a duplicate of#41766Mar 6, 2022
@DocFXDocFX deleted the patch-4 branchMarch 6, 2022 21:52
@DocFX
Copy link
ContributorAuthor

Thanks! Got it, now! Totally missed that part! :)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

6.1

Development

Successfully merging this pull request may close these issues.

5 participants

@DocFX@ro0NL@nicolas-grekas@derrabus@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp