Deprecate event helper (#2608)

This commit is contained in:
Alexander Skvortsov 2021-03-02 16:21:30 -05:00 committed by GitHub
parent 6e01c47c11
commit fc73d47e4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -16,6 +16,7 @@ use Flarum\Http\Rememberer;
use Flarum\Http\SessionAuthenticator;
use Flarum\User\Event\LoggedIn;
use Flarum\User\UserRepository;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
@ -38,6 +39,11 @@ class LogInController implements RequestHandlerInterface
*/
protected $authenticator;
/**
* @var Dispatcher
*/
protected $events;
/**
* @var Rememberer
*/
@ -49,11 +55,12 @@ class LogInController implements RequestHandlerInterface
* @param SessionAuthenticator $authenticator
* @param Rememberer $rememberer
*/
public function __construct(UserRepository $users, Client $apiClient, SessionAuthenticator $authenticator, Rememberer $rememberer)
public function __construct(UserRepository $users, Client $apiClient, SessionAuthenticator $authenticator, Dispatcher $events, Rememberer $rememberer)
{
$this->users = $users;
$this->apiClient = $apiClient;
$this->authenticator = $authenticator;
$this->events = $events;
$this->rememberer = $rememberer;
}
@ -76,7 +83,7 @@ class LogInController implements RequestHandlerInterface
$token = AccessToken::find($data->token);
event(new LoggedIn($this->users->findOrFail($data->userId), $token));
$this->events->dispatch(new LoggedIn($this->users->findOrFail($data->userId), $token));
if (Arr::get($body, 'remember')) {
$response = $this->rememberer->remember($response, $token);

View File

@ -13,6 +13,7 @@ use Flarum\Console\AbstractCommand;
use Flarum\Foundation\Event\ClearingCache;
use Flarum\Foundation\Paths;
use Illuminate\Contracts\Cache\Store;
use Illuminate\Contracts\Events\Dispatcher;
class CacheClearCommand extends AbstractCommand
{
@ -21,6 +22,11 @@ class CacheClearCommand extends AbstractCommand
*/
protected $cache;
/**
* @var Dispatcher
*/
protected $events;
/**
* @var Paths
*/
@ -30,9 +36,10 @@ class CacheClearCommand extends AbstractCommand
* @param Store $cache
* @param Paths $paths
*/
public function __construct(Store $cache, Paths $paths)
public function __construct(Store $cache, Dispatcher $events, Paths $paths)
{
$this->cache = $cache;
$this->events = $events;
$this->paths = $paths;
parent::__construct();
@ -62,6 +69,6 @@ class CacheClearCommand extends AbstractCommand
array_map('unlink', glob($storagePath.'/locale/*'));
array_map('unlink', glob($storagePath.'/views/*'));
event(new ClearingCache);
$this->events->dispatch(new ClearingCache);
}
}

View File

@ -29,6 +29,7 @@ if (! function_exists('app')) {
if (! function_exists('event')) {
/**
* @deprecated beta 16, removed in beta 17
* Fire an event and call the listeners.
*
* @param string|object $event