Skip to content

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
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c801300
fix merge error
AlexzPurewoko Jun 25, 2025
9a13110
fix merge error
AlexzPurewoko Jun 25, 2025
b11022f
refactor message structure to accept symfony email
AlexzPurewoko Jul 16, 2024
943b95f
refactor test
AlexzPurewoko Jul 16, 2024
9568e32
add refactored log transport
AlexzPurewoko Jul 16, 2024
8076b28
add forwardscalls
AlexzPurewoko Jul 16, 2024
72aae99
add sent message
AlexzPurewoko Jul 16, 2024
aa07573
refactor mailer
AlexzPurewoko Jul 16, 2024
1d418fa
add array transport
AlexzPurewoko Jul 17, 2024
34cf2bf
fix addressing
AlexzPurewoko Jul 17, 2024
2f220e9
fix some methods
AlexzPurewoko Jul 17, 2024
8713edc
fix test testMailerSendSendsMessageWithProperViewContent
AlexzPurewoko Jul 17, 2024
746ac9b
refactor the MailMailerTest
AlexzPurewoko Jul 17, 2024
f933f5f
cleaning up
AlexzPurewoko Jul 17, 2024
1457ba4
add symfony http client and mailgun mailer
AlexzPurewoko Jul 18, 2024
33f4e84
completely refactor the mail service provider
AlexzPurewoko Jul 18, 2024
8437072
remove the unused comments
AlexzPurewoko Jul 18, 2024
ff8dbcc
refactor failed test
AlexzPurewoko Jul 18, 2024
6626cba
refactor password broker
AlexzPurewoko Jul 18, 2024
98df200
remove temporary
AlexzPurewoko Jul 18, 2024
7da8272
add test from laravel 9.x
AlexzPurewoko Jul 18, 2024
e4f160b
pass test
AlexzPurewoko Jul 18, 2024
def812f
remove swiftmailer
AlexzPurewoko Jun 10, 2025
93324af
add optional for safe null
AlexzPurewoko Jun 10, 2025
2f65f08
revert to return just $view as is
AlexzPurewoko Jun 25, 2025
f48d9b7
remove the unused transport
AlexzPurewoko Jun 26, 2025
73d3c7f
remove the unused transport
AlexzPurewoko Jun 26, 2025
2bb075c
migrate back to LogTransport
AlexzPurewoko Jun 26, 2025
46606fe
remove unused imports
AlexzPurewoko Jun 26, 2025
87e4a3b
put back throws
AlexzPurewoko Jun 26, 2025
f8645d6
remove swiftmailer
AlexzPurewoko Jun 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"pda/pheanstalk": "~4.0",
"phpseclib/phpseclib": "~2.0",
"predis/predis": "^1.1",
"swiftmailer/swiftmailer": "^6.0",
"symfony/browser-kit": "~6.4",
"symfony/console": "~6.4",
"symfony/css-selector": "~6.4",
Expand All @@ -31,6 +30,7 @@
"symfony/finder": "~6.4",
"symfony/http-foundation": "~6.4",
"symfony/http-kernel": "~6.4",
"symfony/mailer": "^6.4",
"symfony/mime": "~6.4",
"symfony/process": "~6.4",
"symfony/routing": "~6.4",
Expand Down
106 changes: 54 additions & 52 deletions src/Illuminate/Auth/Reminders/PasswordBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
}
});
}

Expand All @@ -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.
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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))
{
Expand All @@ -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)
{
$credentials = array_except($credentials, array('token'));
/**
* Get the user for the given credentials.
*
* @param array $credentials
* @return RemindableInterface|null
* @throws \UnexpectedValueException
*/
public function getUser(array $credentials): ?RemindableInterface
{
$credentials = array_except($credentials, ['token']);

$user = $this->users->retrieveByCredentials($credentials);

Expand All @@ -274,8 +276,8 @@ public function getUser(array $credentials)
*
* @return \Illuminate\Auth\Reminders\ReminderRepositoryInterface
*/
protected function getRepository()
{
protected function getRepository(): ReminderRepositoryInterface
{
return $this->reminders;
}

Expand Down
Loading