Skip to content

Commit

Permalink
Use nullsafe operator for event dispatcher (#52024)
Browse files Browse the repository at this point in the history
  • Loading branch information
seriquynh authored Jul 5, 2024
1 parent 867c403 commit 7d9a206
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/Illuminate/Auth/Passwords/PasswordBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ public function sendResetLink(#[\SensitiveParameter] array $credentials, ?Closur
// the current URI having nothing set in the session to indicate errors.
$user->sendPasswordResetNotification($token);

if ($this->events) {
$this->events->dispatch(new PasswordResetLinkSent($user));
}
$this->events?->dispatch(new PasswordResetLinkSent($user));

return static::RESET_LINK_SENT;
}
Expand Down
8 changes: 2 additions & 6 deletions src/Illuminate/Auth/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,7 @@ public function logout()
// If we have an event dispatcher instance, we can fire off the logout event
// so any further processing can be done. This allows the developer to be
// listening for anytime a user signs out of this application manually.
if (isset($this->events)) {
$this->events->dispatch(new Logout($this->name, $user));
}
$this->events?->dispatch(new Logout($this->name, $user));

// Once we have fired the logout event we will clear the users out of memory
// so they are no longer available as the user is no longer considered as
Expand All @@ -637,9 +635,7 @@ public function logoutCurrentDevice()
// If we have an event dispatcher instance, we can fire off the logout event
// so any further processing can be done. This allows the developer to be
// listening for anytime a user signs out of this application manually.
if (isset($this->events)) {
$this->events->dispatch(new CurrentDeviceLogout($this->name, $user));
}
$this->events?->dispatch(new CurrentDeviceLogout($this->name, $user));

// Once we have fired the logout event we will clear the users out of memory
// so they are no longer available as the user is no longer considered as
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ protected function fireLogEvent($level, $message, array $context = [])
// If the event dispatcher is set, we will pass along the parameters to the
// log listeners. These are useful for building profilers or other tools
// that aggregate all of the log messages for a given "request" cycle.
if (isset($this->dispatcher)) {
$this->dispatcher->dispatch(new MessageLogged($level, $message, $context));
}
$this->dispatcher?->dispatch(new MessageLogged($level, $message, $context));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Redis/Connections/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ public function command($method, array $parameters = [])

$time = round((microtime(true) - $start) * 1000, 2);

if (isset($this->events)) {
$this->event(new CommandExecuted(
$method, $this->parseParametersForEvent($parameters), $time, $this
));
}
$this->events?->dispatch(new CommandExecuted(
$method, $this->parseParametersForEvent($parameters), $time, $this
));

return $result;
}
Expand All @@ -142,6 +140,8 @@ protected function parseParametersForEvent(array $parameters)
*
* @param mixed $event
* @return void
*
* @deprecated since Laravel 11.x
*/
protected function event($event)
{
Expand Down

0 comments on commit 7d9a206

Please sign in to comment.