forked from wallabag/wallabag
Make LoginFormAuthenticator a service and remove Factory
This commit is contained in:
@ -9,7 +9,7 @@ use GuzzleHttp\Message\RequestInterface;
|
||||
use Psr\Log\LoggerAwareInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Wallabag\SiteConfig\Authenticator\Factory;
|
||||
use Wallabag\SiteConfig\Authenticator\Authenticator;
|
||||
use Wallabag\SiteConfig\SiteConfig;
|
||||
use Wallabag\SiteConfig\SiteConfigBuilder;
|
||||
|
||||
@ -23,8 +23,8 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa
|
||||
/** @var SiteConfigBuilder */
|
||||
private $configBuilder;
|
||||
|
||||
/** @var Factory */
|
||||
private $authenticatorFactory;
|
||||
/** @var Authenticator */
|
||||
private $authenticator;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
@ -32,10 +32,10 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa
|
||||
/**
|
||||
* AuthenticatorSubscriber constructor.
|
||||
*/
|
||||
public function __construct(SiteConfigBuilder $configBuilder, Factory $authenticatorFactory)
|
||||
public function __construct(SiteConfigBuilder $configBuilder, Authenticator $authenticator)
|
||||
{
|
||||
$this->configBuilder = $configBuilder;
|
||||
$this->authenticatorFactory = $authenticatorFactory;
|
||||
$this->authenticator = $authenticator;
|
||||
$this->logger = new NullLogger();
|
||||
}
|
||||
|
||||
@ -62,14 +62,13 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa
|
||||
}
|
||||
|
||||
$client = $event->getClient();
|
||||
$authenticator = $this->authenticatorFactory->buildFromSiteConfig();
|
||||
|
||||
if (!$authenticator->isLoggedIn($config, $client)) {
|
||||
if (!$this->authenticator->isLoggedIn($config, $client)) {
|
||||
$this->logger->debug('loginIfRequired> user is not logged in, attach authenticator');
|
||||
|
||||
$emitter = $client->getEmitter();
|
||||
$emitter->detach($this);
|
||||
$authenticator->login($config, $client);
|
||||
$this->authenticator->login($config, $client);
|
||||
$emitter->attach($this);
|
||||
}
|
||||
}
|
||||
@ -94,8 +93,7 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa
|
||||
return;
|
||||
}
|
||||
|
||||
$authenticator = $this->authenticatorFactory->buildFromSiteConfig();
|
||||
$isLoginRequired = $authenticator->isLoginRequired($config, $body);
|
||||
$isLoginRequired = $this->authenticator->isLoginRequired($config, $body);
|
||||
|
||||
$this->logger->debug('loginIfRequested> retry #' . $this->retries . ' with login ' . ($isLoginRequired ? '' : 'not ') . 'required');
|
||||
|
||||
@ -104,7 +102,7 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa
|
||||
|
||||
$emitter = $client->getEmitter();
|
||||
$emitter->detach($this);
|
||||
$authenticator->login($config, $client);
|
||||
$this->authenticator->login($config, $client);
|
||||
$emitter->attach($this);
|
||||
|
||||
$event->retry();
|
||||
|
||||
Reference in New Issue
Block a user