-
-
Notifications
You must be signed in to change notification settings - Fork 406
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[make:user] implement getUserIdentifier if required #862
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
use PhpParser\Node; | ||
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
use Symfony\Component\Security\Core\User\InMemoryUser; | ||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
|
@@ -67,7 +68,7 @@ private function addPasswordImplementation(ClassSourceManipulator $manipulator, | |
$this->addGetPassword($manipulator, $userClassConfig); | ||
} | ||
|
||
private function addGetUsername(ClassSourceManipulator $manipulator, UserClassConfiguration $userClassConfig) | ||
private function addGetUsername(ClassSourceManipulator $manipulator, UserClassConfiguration $userClassConfig): void | ||
{ | ||
if ($userClassConfig->isEntity()) { | ||
// add entity property | ||
|
@@ -97,10 +98,17 @@ private function addGetUsername(ClassSourceManipulator $manipulator, UserClassCo | |
); | ||
} | ||
|
||
$getterIdentifierName = 'getUsername'; | ||
|
||
// Check if we're using Symfony 5.3+ - UserInterface::getUsername() was replaced with UserInterface::getUserIdentifier() | ||
if (class_exists(InMemoryUser::class)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class DOES only exist on 5.3. But why did you choose this class specifically? Could we use something more direct like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$getterIdentifierName = 'getUserIdentifier'; | ||
} | ||
jrushlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// define getUsername (if it was defined above, this will override) | ||
$manipulator->addAccessorMethod( | ||
$userClassConfig->getIdentityPropertyName(), | ||
'getUsername', | ||
$getterIdentifierName, | ||
'string', | ||
false, | ||
[ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really need to, at some point, write a util class where we plug all the
use
statements into... then we just dumpecho $useStatements->render()
in the template :pThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No kidding.. use statements are getting harder and harder to manage lately.. have a solution on the todo list ;)