Skip to content

Commit caf2288

Browse files
committed
Forward compatibility for Symfony 5.3 user interface
1 parent eea039d commit caf2288

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Types/SymfonyUserInterfaceType.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,30 @@
88
use TheCodingMachine\GraphQLite\Annotations\SourceField;
99
use TheCodingMachine\GraphQLite\Annotations\Type;
1010
use Symfony\Component\Security\Core\User\UserInterface;
11+
use TheCodingMachine\GraphQLite\FieldNotFoundException;
1112

1213
/**
1314
* @Type(class=UserInterface::class)
14-
* @SourceField(name="userName")
1515
*/
1616
class SymfonyUserInterfaceType
1717
{
18+
/**
19+
* @Field
20+
*/
21+
public function getUserName(UserInterface $user): string
22+
{
23+
// @phpstan-ignore-next-line Forward Compatibility for Symfony 5.3
24+
if (method_exists($user, 'getUserIdentifier')) {
25+
return $user->getUserIdentifier();
26+
}
27+
28+
if (method_exists($user, 'getUserName')) {
29+
return $user->getUserName();
30+
}
31+
32+
throw FieldNotFoundException::missingField(UserInterface::class, 'userName');
33+
}
34+
1835
/**
1936
* @Field()
2037
* @return string[]

0 commit comments

Comments
 (0)