Skip to content
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

[11.x] Use nullsafe operator for event dispatcher #52024

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->events is not typed hinted as an \Illuminate\Contracts\Events\Dispatcher and because of this the proper check would be:

if ($this->events instanceof \Illuminate\Contracts\Events\Dispatcher) {

But I don't expect this observation to be taken into consideration so take it as FYI only :)


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