@@ -267,6 +267,62 @@ public function doSomething()
267
267
}
268
268
RST;
269
269
270
+ $ valid_with_function = <<<'RST'
271
+ for that::
272
+
273
+ use Symfony\Component\Form\AbstractType;
274
+ use function Symfony\foo;
275
+ RST;
276
+
277
+ $ valid3 = <<<'RST'
278
+ and storage::
279
+
280
+ // src/Security/NormalizedUserBadge.php
281
+ namespace App\Security;
282
+
283
+ use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
284
+ use function Symfony\Component\String\u;
285
+
286
+ final class NormalizedUserBadge extends UserBadge
287
+ {
288
+ public function __construct(string $identifier)
289
+ {
290
+ $callback = static fn (string $identifier): string => u($identifier)->normalize(UnicodeString::NFKC)->ascii()->lower()->toString();
291
+
292
+ parent::__construct($identifier, null, $callback);
293
+ }
294
+ }
295
+
296
+ ::
297
+
298
+ // src/Security/PasswordAuthenticator.php
299
+ namespace App\Security;
300
+
301
+ final class PasswordAuthenticator extends AbstractLoginFormAuthenticator
302
+ {
303
+ // simplified for brevity
304
+ public function authenticate(Request $request): Passport
305
+ {
306
+ $username = (string) $request->request->get('username', '');
307
+ $password = (string) $request->request->get('password', '');
308
+
309
+ $request->getSession()
310
+ ->set(SecurityRequestAttributes::LAST_USERNAME, $username);
311
+
312
+ return new Passport(
313
+ new NormalizedUserBadge($username),
314
+ new PasswordCredentials($password),
315
+ [
316
+ // all other useful badges
317
+ ]
318
+ );
319
+ }
320
+ }
321
+
322
+ User Credential
323
+ ~~~~~~~~~~~~~~~
324
+ RST;
325
+
270
326
yield 'valid with trait ' => [
271
327
NullViolation::create (),
272
328
new RstSample ($ valid_with_trait , 1 ),
@@ -299,5 +355,13 @@ public function doSomething()
299
355
NullViolation::create (),
300
356
new RstSample ($ valid_in_trait_definition , 1 ),
301
357
];
358
+ yield 'valid with function ' => [
359
+ NullViolation::create (),
360
+ new RstSample ($ valid_with_function , 1 ),
361
+ ];
362
+ yield 'valid 3 ' => [
363
+ NullViolation::create (),
364
+ new RstSample ($ valid3 ),
365
+ ];
302
366
}
303
367
}
0 commit comments