Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 31f80df

Browse files
harrygullifordstevebauman
authored andcommitted
Use event helper for BC for Laravel 5.0 to 5.8
#676
1 parent c127cfc commit 31f80df

File tree

7 files changed

+18
-25
lines changed

7 files changed

+18
-25
lines changed

src/Auth/DatabaseUserProvider.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Adldap\Laravel\Events\DiscoveredWithCredentials;
1313
use Adldap\Laravel\Events\AuthenticatedWithCredentials;
1414
use Illuminate\Support\Facades\Bus;
15-
use Illuminate\Support\Facades\Event;
1615
use Illuminate\Support\Facades\Config;
1716
use Illuminate\Auth\EloquentUserProvider;
1817
use Illuminate\Contracts\Hashing\Hasher;
@@ -104,7 +103,7 @@ public function retrieveByCredentials(array $credentials)
104103
// Set the currently authenticating LDAP user.
105104
$this->user = $user;
106105

107-
Event::fire(new DiscoveredWithCredentials($user));
106+
event(new DiscoveredWithCredentials($user));
108107

109108
// Import / locate the local user account.
110109
return Bus::dispatch(
@@ -126,7 +125,7 @@ public function validateCredentials(Authenticatable $model, array $credentials)
126125
// If an LDAP user was discovered, we can go
127126
// ahead and try to authenticate them.
128127
if (Resolver::authenticate($this->user, $credentials)) {
129-
Event::fire(new AuthenticatedWithCredentials($this->user, $model));
128+
event(new AuthenticatedWithCredentials($this->user, $model));
130129

131130
// Here we will perform authorization on the LDAP user. If all
132131
// validation rules pass, we will allow the authentication
@@ -142,15 +141,15 @@ public function validateCredentials(Authenticatable $model, array $credentials)
142141
if ($model->wasRecentlyCreated) {
143142
// If the model was recently created, they
144143
// have been imported successfully.
145-
Event::fire(new Imported($this->user, $model));
144+
event(new Imported($this->user, $model));
146145
}
147146

148-
Event::fire(new AuthenticationSuccessful($this->user, $model));
147+
event(new AuthenticationSuccessful($this->user, $model));
149148

150149
return true;
151150
}
152151

153-
Event::fire(new AuthenticationRejected($this->user, $model));
152+
event(new AuthenticationRejected($this->user, $model));
154153
}
155154

156155
// LDAP Authentication failed.

src/Auth/NoDatabaseUserProvider.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Adldap\Laravel\Events\AuthenticationSuccessful;
88
use Adldap\Laravel\Events\DiscoveredWithCredentials;
99
use Adldap\Laravel\Events\AuthenticatedWithCredentials;
10-
use Illuminate\Support\Facades\Event;
1110
use Illuminate\Contracts\Auth\Authenticatable;
1211

1312
class NoDatabaseUserProvider extends Provider
@@ -46,7 +45,7 @@ public function updateRememberToken(Authenticatable $user, $token)
4645
public function retrieveByCredentials(array $credentials)
4746
{
4847
if ($user = Resolver::byCredentials($credentials)) {
49-
Event::fire(new DiscoveredWithCredentials($user));
48+
event(new DiscoveredWithCredentials($user));
5049

5150
return $user;
5251
}
@@ -58,15 +57,15 @@ public function retrieveByCredentials(array $credentials)
5857
public function validateCredentials(Authenticatable $user, array $credentials)
5958
{
6059
if (Resolver::authenticate($user, $credentials)) {
61-
Event::fire(new AuthenticatedWithCredentials($user));
60+
event(new AuthenticatedWithCredentials($user));
6261

6362
if ($this->passesValidation($user)) {
64-
Event::fire(new AuthenticationSuccessful($user));
63+
event(new AuthenticationSuccessful($user));
6564

6665
return true;
6766
}
6867

69-
Event::fire(new AuthenticationRejected($user));
68+
event(new AuthenticationRejected($user));
7069
}
7170

7271
return false;

src/Commands/Console/Import.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Adldap\Laravel\Commands\Import as ImportUser;
1212
use Illuminate\Console\Command;
1313
use Illuminate\Support\Facades\Bus;
14-
use Illuminate\Support\Facades\Event;
1514
use Illuminate\Support\Facades\Config;
1615
use Illuminate\Database\Eloquent\Model;
1716

@@ -254,7 +253,7 @@ protected function save(User $user, Model $model) : bool
254253
if ($model->save() && $model->wasRecentlyCreated) {
255254
$imported = true;
256255

257-
Event::fire(new Imported($user, $model));
256+
event(new Imported($user, $model));
258257

259258
// Log the successful import.
260259
if ($this->isLogging()) {

src/Commands/Import.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Adldap\Laravel\Events\Synchronized;
88
use Adldap\Laravel\Events\Synchronizing;
99
use Illuminate\Support\Str;
10-
use Illuminate\Support\Facades\Event;
1110
use Illuminate\Support\Facades\Config;
1211
use Illuminate\Database\Eloquent\Model;
1312

@@ -61,14 +60,14 @@ public function handle()
6160
$model = $this->findByCredentials() ?: $this->model->newInstance();
6261

6362
if (! $model->exists) {
64-
Event::fire(new Importing($this->user, $model));
63+
event(new Importing($this->user, $model));
6564
}
6665

67-
Event::fire(new Synchronizing($this->user, $model));
66+
event(new Synchronizing($this->user, $model));
6867

6968
$this->sync($model);
7069

71-
Event::fire(new Synchronized($this->user, $model));
70+
event(new Synchronized($this->user, $model));
7271

7372
return $model;
7473
}

src/Middleware/WindowsAuthenticate.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Illuminate\Http\Request;
1414
use Illuminate\Contracts\Auth\Guard;
1515
use Illuminate\Support\Facades\Bus;
16-
use Illuminate\Support\Facades\Event;
1716
use Illuminate\Support\Facades\Config;
1817

1918
class WindowsAuthenticate
@@ -112,7 +111,7 @@ protected function retrieveAuthenticatedUser($username)
112111
*/
113112
protected function fireAuthenticatedEvent(User $user, $model = null)
114113
{
115-
Event::fire(new AuthenticatedWithWindows($user, $model));
114+
event(new AuthenticatedWithWindows($user, $model));
116115
}
117116

118117
/**

src/Resolvers/UserResolver.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Adldap\Laravel\Events\AuthenticationFailed;
1212
use Adldap\Laravel\Auth\NoDatabaseUserProvider;
1313
use Illuminate\Support\Facades\Auth;
14-
use Illuminate\Support\Facades\Event;
1514
use Illuminate\Support\Facades\Config;
1615
use Illuminate\Contracts\Auth\UserProvider;
1716
use Illuminate\Contracts\Auth\Authenticatable;
@@ -111,15 +110,15 @@ public function authenticate(User $user, array $credentials = [])
111110

112111
$password = $this->getPasswordFromCredentials($credentials);
113112

114-
Event::fire(new Authenticating($user, $username));
113+
event(new Authenticating($user, $username));
115114

116115
if ($this->getLdapAuthProvider()->auth()->attempt($username, $password)) {
117-
Event::fire(new Authenticated($user));
116+
event(new Authenticated($user));
118117

119118
return true;
120119
}
121120

122-
Event::fire(new AuthenticationFailed($user));
121+
event(new AuthenticationFailed($user));
123122

124123
return false;
125124
}

src/Validation/Rules/DenyTrashed.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Adldap\Laravel\Validation\Rules;
44

5-
use Illuminate\Support\Facades\Event;
65
use Adldap\Laravel\Events\AuthenticatedModelTrashed;
76

87
class DenyTrashed extends Rule
@@ -13,7 +12,7 @@ class DenyTrashed extends Rule
1312
public function isValid()
1413
{
1514
if ($this->isTrashed()) {
16-
Event::fire(
15+
event(
1716
new AuthenticatedModelTrashed($this->user, $this->model)
1817
);
1918

0 commit comments

Comments
 (0)