Use UrlGenerator over Application for base URL

We need to get rid of this god class, as Laravel's Application contract
gets even bigger with 5.8. To avoid having to add all these methods, we
should try to stop using it where we can.
This commit is contained in:
Franz Liedke 2020-03-28 11:17:45 +01:00
parent e446c91a27
commit 2ed194666b
2 changed files with 8 additions and 17 deletions

View File

@ -9,8 +9,8 @@
namespace Flarum\Forum\Controller;
use Flarum\Foundation\Application;
use Flarum\Http\SessionAuthenticator;
use Flarum\Http\UrlGenerator;
use Flarum\User\Command\ConfirmEmail;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
@ -27,9 +27,9 @@ class ConfirmEmailController implements RequestHandlerInterface
protected $bus;
/**
* @var Application
* @var UrlGenerator
*/
protected $app;
protected $url;
/**
* @var SessionAuthenticator
@ -38,13 +38,13 @@ class ConfirmEmailController implements RequestHandlerInterface
/**
* @param Dispatcher $bus
* @param Application $app
* @param UrlGenerator $url
* @param SessionAuthenticator $authenticator
*/
public function __construct(Dispatcher $bus, Application $app, SessionAuthenticator $authenticator)
public function __construct(Dispatcher $bus, UrlGenerator $url, SessionAuthenticator $authenticator)
{
$this->bus = $bus;
$this->app = $app;
$this->url = $url;
$this->authenticator = $authenticator;
}
@ -63,6 +63,6 @@ class ConfirmEmailController implements RequestHandlerInterface
$session = $request->getAttribute('session');
$this->authenticator->logIn($session, $user->id);
return new RedirectResponse($this->app->url());
return new RedirectResponse($this->url->to('forum')->base());
}
}

View File

@ -9,7 +9,6 @@
namespace Flarum\Forum\Controller;
use Flarum\Foundation\Application;
use Flarum\Http\Exception\TokenMismatchException;
use Flarum\Http\Rememberer;
use Flarum\Http\SessionAuthenticator;
@ -29,11 +28,6 @@ class LogOutController implements RequestHandlerInterface
{
use AssertPermissionTrait;
/**
* @var Application
*/
protected $app;
/**
* @var Dispatcher
*/
@ -60,7 +54,6 @@ class LogOutController implements RequestHandlerInterface
protected $url;
/**
* @param Application $app
* @param Dispatcher $events
* @param SessionAuthenticator $authenticator
* @param Rememberer $rememberer
@ -68,14 +61,12 @@ class LogOutController implements RequestHandlerInterface
* @param UrlGenerator $url
*/
public function __construct(
Application $app,
Dispatcher $events,
SessionAuthenticator $authenticator,
Rememberer $rememberer,
Factory $view,
UrlGenerator $url
) {
$this->app = $app;
$this->events = $events;
$this->authenticator = $authenticator;
$this->rememberer = $rememberer;
@ -93,7 +84,7 @@ class LogOutController implements RequestHandlerInterface
$session = $request->getAttribute('session');
$actor = $request->getAttribute('actor');
$url = Arr::get($request->getQueryParams(), 'return', $this->app->url());
$url = Arr::get($request->getQueryParams(), 'return', $this->url->to('forum')->base());
// If there is no user logged in, return to the index.
if ($actor->isGuest()) {