Category : validation

I am using custom endpoint with custom controller in api platfrom for user instance. class PayingMembershipForOthersController { private ValidatorInterface $validator; public function __construct(ValidatorInterface $validator) { $this->validator = $validator; } public function __invoke(User $data) { $this->validator->validate($data); try { $userService->paymentMembership($data); } catch(Exception $e) { throw $e } return $data; } } if user is not found my ..

Read more

I’m going through The Fast Track Symfony tutorial. On the 13th step they add UniqueEntity constraint to the Conference entity. // … use SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity; /** * @ORMEntity(repositoryClass=ConferenceRepository::class) * @UniqueEntity("slug") */ class Conference { // … } When I try to visit any page I see an error: Attempted to load class "Constraint" from namespace "SymfonyComponentValidator". ..

Read more

I don’t know how to validate a checkbox with a @Assert. Returns a string "1" if checked otherwise false Step 1: create a class: SearchPlayerData.php to test my data (without ORM) This form is not linked to a class <?php namespace AppEntity; use SymfonyComponentValidatorConstraints as Assert; class SearchPlayerData { /** * (length=255, nullable=true) * @Assert??? ..

Read more

I am using Laravel 8 and validate my requests with the form request validation. However, I have a strange problem. Before I am going to describe my problem I will paste my routes and my validation class here: routes: Route::post(‘users’, [‘as’ => ‘user.search’, ‘uses’ => ‘[email protected]’]); Route::post(‘user/name’, [‘as’ => ‘user.name.exists’, ‘uses’ => ‘[email protected]’]); Route::post(‘user/email’, [‘as’ ..

Read more

I’m working with Symfony5 and ApiPlatform with phpunit for the tests I’m running tests on field validation. My issue comes from the fact that I want to restrain the user’s possiblity to enter a blank string in a property named name as follow : /** * @ApiResource( * attributes={ * "normalization_context"={"groups"={"cons:read", "cons:list"}}, * "denormalization_context"={"groups"={"cons:write"}} * ..

Read more

I wrote custom constraint for my entity where I have startDate and endDate where I want to avoid overlapping when saving new ones. <?php namespace AppEntity; use DoctrineORMMapping as ORM; use AppValidatorConstraintsNotOverlapping; /** */ class Product { /** * @ORMId() * @ORMGeneratedValue() * @ORMColumn(type="integer") */ private $id; /** * @ORMColumn(type="date", nullable=false) */ private $startDate; /** ..

Read more

working with a Sf form, which fails validation on value from ChoiceType: Form: public function buildForm(FormBuilderInterface $builder, array $options) { $countryChoiceArr = []; foreach ($options[‘countries’] as $country) { if (array_key_exists(‘fullName’, $country) && array_key_exists(‘countryCode’, $country)) { $countryChoiceArr[$country[‘fullName’]] = $country[‘countryCode’]; } } $builder ->add(‘choice’, ChoiceType::class, [ ‘choices’ => $countryChoiceArr, ]) } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ ..

Read more