Skip to content

Commit 8ad46c4

Browse files
committed
Events refactoring
1 parent 85d30c5 commit 8ad46c4

File tree

7 files changed

+115
-4
lines changed

7 files changed

+115
-4
lines changed

app/Events/UserAccess.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\Events\Event;
6+
use Illuminate\Queue\SerializesModels;
7+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
8+
9+
class UserAccess extends Event
10+
{
11+
use SerializesModels;
12+
13+
/**
14+
* Get the channels the event should be broadcast on.
15+
*
16+
* @return array
17+
*/
18+
public function broadcastOn()
19+
{
20+
return [];
21+
}
22+
}

app/Http/Middleware/App.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Jobs\SetLocale;
88

99
use Illuminate\Bus\Dispatcher as BusDispatcher;
10+
use App\Events\UserAccess;
1011

1112
class App
1213
{
@@ -51,7 +52,7 @@ public function handle($request, Closure $next)
5152
{
5253
$this->bus->dispatch($this->setLocale);
5354

54-
event('user.access');
55+
event(new UserAccess);
5556

5657
return $next($request);
5758
}

app/Listeners/ListenerBase.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use Illuminate\Queue\InteractsWithQueue;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use App\Services\Statut;
8+
9+
class ListenerBase
10+
{
11+
/**
12+
* The Statut instance.
13+
*
14+
* @var App\Services\Statut
15+
*/
16+
protected $statut;
17+
18+
/**
19+
* Create the event listener.
20+
*
21+
* @param App\Services\Statut $statut
22+
* @return void
23+
*/
24+
public function __construct(Statut $statut)
25+
{
26+
$this->statut = $statut;
27+
}
28+
}

app/Listeners/LoginSuccess.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use Illuminate\Auth\Events\Login;
6+
7+
class LoginSuccess extends ListenerBase
8+
{
9+
/**
10+
* Handle the event.
11+
*
12+
* @param Login $login
13+
* @return void
14+
*/
15+
public function handle(Login $login)
16+
{
17+
$this->statut->setLoginStatut($login);
18+
}
19+
}

app/Listeners/LogoutSuccess.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use Illuminate\Auth\Events\Logout;
6+
7+
class LogoutSuccess extends ListenerBase
8+
{
9+
/**
10+
* Handle the event.
11+
*
12+
* @param Logout $event
13+
* @return void
14+
*/
15+
public function handle(Logout $event)
16+
{
17+
$this->statut->setVisitorStatut();
18+
}
19+
}

app/Listeners/UserAccess.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use App\Events\UserAccess;
6+
7+
class UserAccess extends ListenerBase
8+
{
9+
/**
10+
* Handle the event.
11+
*
12+
* @param UserAccess $event
13+
* @return void
14+
*/
15+
public function handle(UserAccess $event)
16+
{
17+
$this->statut->setStatut();
18+
}
19+
}

app/Providers/EventServiceProvider.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ class EventServiceProvider extends ServiceProvider {
1111
* @var array
1212
*/
1313
protected $listen = [
14-
'Illuminate\Auth\Events\Login' => ['App\Services\Statut@setLoginStatut'],
15-
'Illuminate\Auth\Events\Logout' => ['App\Services\Statut@setVisitorStatut'],
16-
'user.access' => ['App\Services\Statut@setStatut']
14+
'Illuminate\Auth\Events\Login' => ['App\Listeners\LoginSuccess'],
15+
//'Illuminate\Auth\Events\Login' => ['App\Services\Statut@setLoginStatut'],
16+
'Illuminate\Auth\Events\Logout' => ['App\Listeners\LogoutSuccess'],
17+
//'Illuminate\Auth\Events\Logout' => ['App\Services\Statut@setVisitorStatut'],
18+
//'user.access' => ['App\Services\Statut@setStatut']
19+
'App\Event\UserAccess' => ['App\Listeners\UserAccess']
1720
];
1821

1922
/**

0 commit comments

Comments
 (0)