Skip to content

Commit 9bc9d0b

Browse files
imorlandStyleCIBot
andauthored
fix: don't cache the oauth config if we're in debug mode (#91)
* chore: don't cache the oauth config if we're in debug mode * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent 380efc5 commit 9bc9d0b

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/Events/UnlinkingFromProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class UnlinkingFromProvider
3535
* @param User $user
3636
* @param LoginProvider $provider
3737
*/
38-
public function __construct(User $user, LoginProvider $provider, User $actor = null)
38+
public function __construct(User $user, LoginProvider $provider, ?User $actor = null)
3939
{
4040
$this->user = $user;
4141
$this->provider = $provider;

src/Extend/RegisterProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(string $provider)
2626
$this->provider = $provider;
2727
}
2828

29-
public function extend(Container $container, Extension $extension = null)
29+
public function extend(Container $container, ?Extension $extension = null)
3030
{
3131
$provider = $container->make($this->provider);
3232

src/LoginProviderStatus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class LoginProviderStatus
6666
*/
6767
public $lastLogin;
6868

69-
public static function build(string $name, string $icon, int $priority, User $user, LoginProvider $provider = null, bool $orphaned = false)
69+
public static function build(string $name, string $icon, int $priority, User $user, ?LoginProvider $provider = null, bool $orphaned = false)
7070
{
7171
$status = new self();
7272

src/OAuthServiceProvider.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace FoF\OAuth;
1313

1414
use Flarum\Foundation\AbstractServiceProvider;
15+
use Flarum\Foundation\Config;
1516
use Flarum\Http\RouteCollection;
1617
use Flarum\Http\RouteHandlerFactory;
1718
use Illuminate\Contracts\Cache\Store as Cache;
@@ -44,8 +45,15 @@ public function boot()
4445
{
4546
/** @var Cache $cache */
4647
$cache = $this->container->make(Cache::class);
48+
/** @var Config $config */
49+
$config = $this->container->make(Config::class);
50+
51+
$this->container->singleton('fof-oauth.providers.forum', function () use ($cache, $config) {
52+
// If we're in debug mode, don't cache the providers, but directly return them.
53+
if ($config->inDebugMode()) {
54+
return $this->mapProviders();
55+
}
4756

48-
$this->container->singleton('fof-oauth.providers.forum', function () use ($cache) {
4957
$cacheKey = 'fof-oauth.providers.forum';
5058

5159
$data = $cache->get($cacheKey);
@@ -57,7 +65,12 @@ public function boot()
5765
return $data;
5866
});
5967

60-
$this->container->singleton('fof-oauth.providers.admin', function () use ($cache) {
68+
$this->container->singleton('fof-oauth.providers.admin', function () use ($cache, $config) {
69+
// If we're in debug mode, don't cache the providers, but directly return them.
70+
if ($config->inDebugMode()) {
71+
return $this->mapProviders();
72+
}
73+
6174
$cacheKey = 'fof-oauth.providers.admin';
6275

6376
$data = $cache->get($cacheKey);

0 commit comments

Comments
 (0)