-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor swiftmailer to symfony mailer #10
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
Open
AlexzPurewoko
wants to merge
19
commits into
master
Choose a base branch
from
backport/migrate-swiftmailer-to-symfony-mailer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
df246a1
add symfony mailer
AlexzPurewoko 5d59c56
refactor message structure to accept symfony email
AlexzPurewoko 1d72fb2
refactor test
AlexzPurewoko b8a6014
add refactored log transport
AlexzPurewoko 308e73f
add forwardscalls
AlexzPurewoko 56e257e
add sent message
AlexzPurewoko 593ac47
refactor mailer
AlexzPurewoko 50100e3
add array transport
AlexzPurewoko b52fb91
fix addressing
AlexzPurewoko bbf5268
fix some methods
AlexzPurewoko d9771cf
fix test testMailerSendSendsMessageWithProperViewContent
AlexzPurewoko 87cfa1e
refactor the MailMailerTest
AlexzPurewoko 6e8af0f
cleaning up
AlexzPurewoko 25a8139
add symfony http client and mailgun mailer
AlexzPurewoko 7144ff5
completely refactor the mail service provider
AlexzPurewoko 85ba199
remove the unused comments
AlexzPurewoko 26098e3
refactor failed test
AlexzPurewoko 8f60758
refactor password broker
AlexzPurewoko 9ae3989
remove temporary
AlexzPurewoko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,49 +46,49 @@ class PasswordBroker { | |
* | ||
* @var \Illuminate\Auth\Reminders\ReminderRepositoryInterface $reminders | ||
*/ | ||
protected $reminders; | ||
protected ReminderRepositoryInterface $reminders; | ||
|
||
/** | ||
* The user provider implementation. | ||
* | ||
* @var \Illuminate\Auth\UserProviderInterface | ||
*/ | ||
protected $users; | ||
protected UserProviderInterface $users; | ||
|
||
/** | ||
* The mailer instance. | ||
* | ||
* @var \Illuminate\Mail\Mailer | ||
*/ | ||
protected $mailer; | ||
protected Mailer $mailer; | ||
|
||
/** | ||
* The view of the password reminder e-mail. | ||
* | ||
* @var string | ||
*/ | ||
protected $reminderView; | ||
protected string $reminderView; | ||
|
||
/** | ||
* The custom password validator callback. | ||
* | ||
* @var \Closure | ||
*/ | ||
protected $passwordValidator; | ||
protected Closure $passwordValidator; | ||
|
||
/** | ||
* Create a new password broker instance. | ||
* | ||
* @param \Illuminate\Auth\Reminders\ReminderRepositoryInterface $reminders | ||
* @param \Illuminate\Auth\UserProviderInterface $users | ||
* @param \Illuminate\Mail\Mailer $mailer | ||
* @param string $reminderView | ||
* @param string $reminderView | ||
* @return void | ||
*/ | ||
public function __construct(ReminderRepositoryInterface $reminders, | ||
UserProviderInterface $users, | ||
Mailer $mailer, | ||
$reminderView) | ||
UserProviderInterface $users, | ||
Mailer $mailer, | ||
string $reminderView) | ||
{ | ||
$this->users = $users; | ||
$this->mailer = $mailer; | ||
|
@@ -103,14 +103,14 @@ public function __construct(ReminderRepositoryInterface $reminders, | |
* @param \Closure $callback | ||
* @return string | ||
*/ | ||
public function remind(array $credentials, Closure $callback = null) | ||
public function remind(array $credentials, Closure $callback = null): string | ||
{ | ||
// First we will check to see if we found a user at the given credentials and | ||
// if we did not we will redirect back to this current URI with a piece of | ||
// "flash" data in the session to indicate to the developers the errors. | ||
$user = $this->getUser($credentials); | ||
|
||
if (is_null($user)) | ||
if ($user === null) | ||
{ | ||
return self::INVALID_USER; | ||
} | ||
|
@@ -129,22 +129,24 @@ public function remind(array $credentials, Closure $callback = null) | |
* Send the password reminder e-mail. | ||
* | ||
* @param \Illuminate\Auth\Reminders\RemindableInterface $user | ||
* @param string $token | ||
* @param \Closure $callback | ||
* @return int | ||
* @param string $token | ||
* @param Closure $callback | ||
* @return void | ||
*/ | ||
public function sendReminder(RemindableInterface $user, $token, Closure $callback = null) | ||
public function sendReminder(RemindableInterface $user, string $token, Closure $callback = null): void | ||
{ | ||
// We will use the reminder view that was given to the broker to display the | ||
// password reminder e-mail. We'll pass a "token" variable into the views | ||
// so that it may be displayed for an user to click for password reset. | ||
$view = $this->reminderView; | ||
|
||
return $this->mailer->send($view, compact('token', 'user'), function($m) use ($user, $token, $callback) | ||
$this->mailer->send($view, compact('token', 'user'), function($m) use ($user, $token, $callback) | ||
{ | ||
$m->to($user->getReminderEmail()); | ||
|
||
if ( ! is_null($callback)) call_user_func($callback, $m, $user, $token); | ||
if ($callback !== null) { | ||
call_user_func($callback, $m, $user, $token); | ||
} | ||
}); | ||
} | ||
|
||
|
@@ -153,10 +155,10 @@ public function sendReminder(RemindableInterface $user, $token, Closure $callbac | |
* | ||
* @param array $credentials | ||
* @param \Closure $callback | ||
* @return mixed | ||
*/ | ||
public function reset(array $credentials, Closure $callback) | ||
{ | ||
* @return RemindableInterface|string|int | ||
*/ | ||
public function reset(array $credentials, Closure $callback): RemindableInterface|string|int | ||
{ | ||
// If the responses from the validate method is not a user instance, we will | ||
// assume that it is a redirect and simply return it from this method and | ||
// the user is properly redirected having an error message on the post. | ||
|
@@ -179,25 +181,26 @@ public function reset(array $credentials, Closure $callback) | |
return self::PASSWORD_RESET; | ||
} | ||
|
||
/** | ||
* Validate a password reset for the given credentials. | ||
* | ||
* @param array $credentials | ||
* @return \Illuminate\Auth\Reminders\RemindableInterface | ||
*/ | ||
protected function validateReset(array $credentials) | ||
{ | ||
if (is_null($user = $this->getUser($credentials))) | ||
/** | ||
* Validate a password reset for the given credentials. | ||
* | ||
* @param array $credentials | ||
* @return RemindableInterface|int|string | ||
*/ | ||
protected function validateReset(array $credentials): RemindableInterface|int|string | ||
{ | ||
$user = $this->getUser($credentials); | ||
if ($user === null) | ||
{ | ||
return self::INVALID_USER; | ||
} | ||
|
||
if ( ! $this->validNewPasswords($credentials)) | ||
if (!$this->validNewPasswords($credentials)) | ||
{ | ||
return self::INVALID_PASSWORD; | ||
} | ||
|
||
if ( ! $this->reminders->exists($user, $credentials['token'])) | ||
if (!$this->reminders->exists($user, $credentials['token'])) | ||
{ | ||
return self::INVALID_TOKEN; | ||
} | ||
|
@@ -211,8 +214,8 @@ protected function validateReset(array $credentials) | |
* @param \Closure $callback | ||
* @return void | ||
*/ | ||
public function validator(Closure $callback) | ||
{ | ||
public function validator(Closure $callback): void | ||
{ | ||
$this->passwordValidator = $callback; | ||
} | ||
|
||
|
@@ -222,9 +225,9 @@ public function validator(Closure $callback) | |
* @param array $credentials | ||
* @return bool | ||
*/ | ||
protected function validNewPasswords(array $credentials) | ||
{ | ||
list($password, $confirm) = array($credentials['password'], $credentials['password_confirmation']); | ||
protected function validNewPasswords(array $credentials): bool | ||
{ | ||
list($password, $confirm) = [$credentials['password'], $credentials['password_confirmation']]; | ||
|
||
if (isset($this->passwordValidator)) | ||
{ | ||
|
@@ -240,24 +243,23 @@ protected function validNewPasswords(array $credentials) | |
* @param array $credentials | ||
* @return bool | ||
*/ | ||
protected function validatePasswordWithDefaults(array $credentials) | ||
{ | ||
protected function validatePasswordWithDefaults(array $credentials): bool | ||
{ | ||
list($password, $confirm) = [$credentials['password'], $credentials['password_confirmation']]; | ||
|
||
return $password === $confirm && mb_strlen((string) $password) >= 6; | ||
} | ||
|
||
/** | ||
* Get the user for the given credentials. | ||
* | ||
* @param array $credentials | ||
* @return \Illuminate\Auth\Reminders\RemindableInterface | ||
* | ||
* @throws \UnexpectedValueException | ||
*/ | ||
public function getUser(array $credentials) | ||
{ | ||
Comment on lines
-254
to
-259
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. @AlexzPurewoko ada pertimbangan tertentu kenapa return value-nya jadi nullable dan throw-nya dihapus? |
||
$credentials = array_except($credentials, array('token')); | ||
/** | ||
* Get the user for the given credentials. | ||
* | ||
* @param array $credentials | ||
* @return RemindableInterface|null | ||
* | ||
*/ | ||
public function getUser(array $credentials): ?RemindableInterface | ||
{ | ||
$credentials = array_except($credentials, ['token']); | ||
|
||
$user = $this->users->retrieveByCredentials($credentials); | ||
|
||
|
@@ -274,8 +276,8 @@ public function getUser(array $credentials) | |
* | ||
* @return \Illuminate\Auth\Reminders\ReminderRepositoryInterface | ||
*/ | ||
protected function getRepository() | ||
{ | ||
protected function getRepository(): ReminderRepositoryInterface | ||
{ | ||
return $this->reminders; | ||
} | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@AlexzPurewoko swiftmailer di list ini juga perlu dihapus.