Use config helper instead

This commit is contained in:
Lance Pioch 2024-03-19 04:59:19 -04:00
parent b11810588a
commit d9cfb62a12
9 changed files with 54 additions and 85 deletions

View File

@ -4,7 +4,6 @@ namespace App\Console\Commands\Environment;
use Illuminate\Console\Command;
use App\Traits\Commands\EnvironmentWriterTrait;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
class EmailSettingsCommand extends Command
{
@ -25,14 +24,6 @@ class EmailSettingsCommand extends Command
protected array $variables = [];
/**
* EmailSettingsCommand constructor.
*/
public function __construct(private ConfigRepository $config)
{
parent::__construct();
}
/**
* Handle command execution.
*
@ -49,7 +40,7 @@ class EmailSettingsCommand extends Command
'mandrill' => 'Mandrill Transactional Email',
'postmark' => 'Postmark Transactional Email',
],
$this->config->get('mail.default', 'smtp')
config('mail.default', 'smtp')
);
$method = 'setup' . studly_case($this->variables['MAIL_DRIVER']) . 'DriverVariables';
@ -59,12 +50,12 @@ class EmailSettingsCommand extends Command
$this->variables['MAIL_FROM_ADDRESS'] = $this->option('email') ?? $this->ask(
trans('command/messages.environment.mail.ask_mail_from'),
$this->config->get('mail.from.address')
config('mail.from.address')
);
$this->variables['MAIL_FROM_NAME'] = $this->option('from') ?? $this->ask(
trans('command/messages.environment.mail.ask_mail_name'),
$this->config->get('mail.from.name')
config('mail.from.name')
);
$this->writeToEnvironment($this->variables);
@ -80,17 +71,17 @@ class EmailSettingsCommand extends Command
{
$this->variables['MAIL_HOST'] = $this->option('host') ?? $this->ask(
trans('command/messages.environment.mail.ask_smtp_host'),
$this->config->get('mail.mailers.smtp.host')
config('mail.mailers.smtp.host')
);
$this->variables['MAIL_PORT'] = $this->option('port') ?? $this->ask(
trans('command/messages.environment.mail.ask_smtp_port'),
$this->config->get('mail.mailers.smtp.port')
config('mail.mailers.smtp.port')
);
$this->variables['MAIL_USERNAME'] = $this->option('username') ?? $this->ask(
trans('command/messages.environment.mail.ask_smtp_username'),
$this->config->get('mail.mailers.smtp.username')
config('mail.mailers.smtp.username')
);
$this->variables['MAIL_PASSWORD'] = $this->option('password') ?? $this->secret(
@ -100,7 +91,7 @@ class EmailSettingsCommand extends Command
$this->variables['MAIL_ENCRYPTION'] = $this->option('encryption') ?? $this->choice(
trans('command/messages.environment.mail.ask_encryption'),
['tls' => 'TLS', 'ssl' => 'SSL', '' => 'None'],
$this->config->get('mail.mailers.smtp.encryption', 'tls')
config('mail.mailers.smtp.encryption', 'tls')
);
}
@ -111,17 +102,17 @@ class EmailSettingsCommand extends Command
{
$this->variables['MAILGUN_DOMAIN'] = $this->option('host') ?? $this->ask(
trans('command/messages.environment.mail.ask_mailgun_domain'),
$this->config->get('services.mailgun.domain')
config('services.mailgun.domain')
);
$this->variables['MAILGUN_SECRET'] = $this->option('password') ?? $this->ask(
trans('command/messages.environment.mail.ask_mailgun_secret'),
$this->config->get('services.mailgun.secret')
config('services.mailgun.secret')
);
$this->variables['MAILGUN_ENDPOINT'] = $this->option('endpoint') ?? $this->ask(
trans('command/messages.environment.mail.ask_mailgun_endpoint'),
$this->config->get('services.mailgun.endpoint')
config('services.mailgun.endpoint')
);
}
@ -132,7 +123,7 @@ class EmailSettingsCommand extends Command
{
$this->variables['MANDRILL_SECRET'] = $this->option('password') ?? $this->ask(
trans('command/messages.environment.mail.ask_mandrill_secret'),
$this->config->get('services.mandrill.secret')
config('services.mandrill.secret')
);
}
@ -146,7 +137,7 @@ class EmailSettingsCommand extends Command
$this->variables['MAIL_PORT'] = 587;
$this->variables['MAIL_USERNAME'] = $this->variables['MAIL_PASSWORD'] = $this->option('username') ?? $this->ask(
trans('command/messages.environment.mail.ask_postmark_username'),
$this->config->get('mail.username')
config('mail.username')
);
}
}

View File

@ -4,7 +4,6 @@ namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Services\Helpers\SoftwareVersionService;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
class InfoCommand extends Command
{
@ -15,7 +14,7 @@ class InfoCommand extends Command
/**
* VersionCommand constructor.
*/
public function __construct(private ConfigRepository $config, private SoftwareVersionService $versionService)
public function __construct(private SoftwareVersionService $versionService)
{
parent::__construct();
}
@ -27,47 +26,47 @@ class InfoCommand extends Command
{
$this->output->title('Version Information');
$this->table([], [
['Panel Version', $this->config->get('app.version')],
['Panel Version', config('app.version')],
['Latest Version', $this->versionService->getPanel()],
['Up-to-Date', $this->versionService->isLatestPanel() ? 'Yes' : $this->formatText('No', 'bg=red')],
['Unique Identifier', $this->config->get('panel.service.author')],
['Unique Identifier', config('panel.service.author')],
], 'compact');
$this->output->title('Application Configuration');
$this->table([], [
['Environment', $this->formatText($this->config->get('app.env'), $this->config->get('app.env') === 'production' ?: 'bg=red')],
['Debug Mode', $this->formatText($this->config->get('app.debug') ? 'Yes' : 'No', !$this->config->get('app.debug') ?: 'bg=red')],
['Installation URL', $this->config->get('app.url')],
['Environment', $this->formatText(config('app.env'), config('app.env') === 'production' ?: 'bg=red')],
['Debug Mode', $this->formatText(config('app.debug') ? 'Yes' : 'No', !config('app.debug') ?: 'bg=red')],
['Installation URL', config('app.url')],
['Installation Directory', base_path()],
['Timezone', $this->config->get('app.timezone')],
['Cache Driver', $this->config->get('cache.default')],
['Queue Driver', $this->config->get('queue.default')],
['Session Driver', $this->config->get('session.driver')],
['Filesystem Driver', $this->config->get('filesystems.default')],
['Default Theme', $this->config->get('themes.active')],
['Proxies', $this->config->get('trustedproxies.proxies')],
['Timezone', config('app.timezone')],
['Cache Driver', config('cache.default')],
['Queue Driver', config('queue.default')],
['Session Driver', config('session.driver')],
['Filesystem Driver', config('filesystems.default')],
['Default Theme', config('themes.active')],
['Proxies', config('trustedproxies.proxies')],
], 'compact');
$this->output->title('Database Configuration');
$driver = $this->config->get('database.default');
$driver = config('database.default');
$this->table([], [
['Driver', $driver],
['Host', $this->config->get("database.connections.$driver.host")],
['Port', $this->config->get("database.connections.$driver.port")],
['Database', $this->config->get("database.connections.$driver.database")],
['Username', $this->config->get("database.connections.$driver.username")],
['Host', config("database.connections.$driver.host")],
['Port', config("database.connections.$driver.port")],
['Database', config("database.connections.$driver.database")],
['Username', config("database.connections.$driver.username")],
], 'compact');
// TODO: Update this to handle other mail drivers
$this->output->title('Email Configuration');
$this->table([], [
['Driver', $this->config->get('mail.default')],
['Host', $this->config->get('mail.mailers.smtp.host')],
['Port', $this->config->get('mail.mailers.smtp.port')],
['Username', $this->config->get('mail.mailers.smtp.username')],
['From Address', $this->config->get('mail.from.address')],
['From Name', $this->config->get('mail.from.name')],
['Encryption', $this->config->get('mail.mailers.smtp.encryption')],
['Driver', config('mail.default')],
['Host', config('mail.mailers.smtp.host')],
['Port', config('mail.mailers.smtp.port')],
['Username', config('mail.mailers.smtp.username')],
['From Address', config('mail.from.address')],
['From Name', config('mail.from.name')],
['Encryption', config('mail.mailers.smtp.encryption')],
], 'compact');
}

View File

@ -11,12 +11,9 @@ use Illuminate\Foundation\Application;
use League\Flysystem\FilesystemAdapter;
use App\Extensions\Filesystem\S3Filesystem;
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
class BackupManager
{
protected ConfigRepository $config;
/**
* The array of resolved backup drivers.
*/
@ -32,7 +29,6 @@ class BackupManager
*/
public function __construct(protected Application $app)
{
$this->config = $app->make(ConfigRepository::class);
}
/**
@ -127,7 +123,7 @@ class BackupManager
*/
protected function getConfig(string $name): array
{
return $this->config->get("backups.disks.$name") ?: [];
return config("backups.disks.$name") ?: [];
}
/**
@ -135,7 +131,7 @@ class BackupManager
*/
public function getDefaultAdapter(): string
{
return $this->config->get('backups.default');
return config('backups.default');
}
/**
@ -143,7 +139,7 @@ class BackupManager
*/
public function setDefaultAdapter(string $name): void
{
$this->config->set('backups.default', $name);
config()->set('backups.default', $name);
}
/**
@ -163,7 +159,7 @@ class BackupManager
/**
* Register a custom adapter creator closure.
*/
public function extend(string $adapter, \Closure $callback): self
public function extend(string $adapter, Closure $callback): self
{
$this->customCreators[$adapter] = $callback;

View File

@ -24,7 +24,6 @@ use App\Services\Databases\DatabasePasswordService;
use App\Services\Servers\DetailsModificationService;
use App\Services\Servers\StartupModificationService;
use App\Services\Databases\DatabaseManagementService;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use App\Services\Servers\ServerConfigurationStructureService;
use App\Http\Requests\Admin\Servers\Databases\StoreServerDatabaseRequest;
@ -36,7 +35,6 @@ class ServersController extends Controller
public function __construct(
protected AlertsMessageBag $alert,
protected BuildModificationService $buildModificationService,
protected ConfigRepository $config,
protected DaemonServerRepository $daemonServerRepository,
protected DatabaseManagementService $databaseManagementService,
protected DatabasePasswordService $databasePasswordService,

View File

@ -8,7 +8,6 @@ use Illuminate\Http\RedirectResponse;
use Prologue\Alerts\AlertsMessageBag;
use Illuminate\Contracts\Console\Kernel;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use App\Http\Requests\Admin\Settings\AdvancedSettingsFormRequest;
class AdvancedController extends Controller
@ -18,7 +17,6 @@ class AdvancedController extends Controller
*/
public function __construct(
private AlertsMessageBag $alert,
private ConfigRepository $config,
private Kernel $kernel,
) {
}
@ -30,8 +28,8 @@ class AdvancedController extends Controller
{
$showRecaptchaWarning = false;
if (
$this->config->get('recaptcha._shipped_secret_key') === $this->config->get('recaptcha.secret_key')
|| $this->config->get('recaptcha._shipped_website_key') === $this->config->get('recaptcha.website_key')
config('recaptcha._shipped_secret_key') === config('recaptcha.secret_key')
|| config('recaptcha._shipped_website_key') === config('recaptcha.website_key')
) {
$showRecaptchaWarning = true;
}

View File

@ -13,7 +13,6 @@ use App\Exceptions\DisplayException;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Encryption\Encrypter;
use App\Providers\SettingsServiceProvider;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use App\Http\Requests\Admin\Settings\MailSettingsFormRequest;
class MailController extends Controller
@ -22,7 +21,6 @@ class MailController extends Controller
* MailController constructor.
*/
public function __construct(
private ConfigRepository $config,
private Encrypter $encrypter,
private Kernel $kernel,
) {
@ -35,7 +33,7 @@ class MailController extends Controller
public function index(): View
{
return view('admin.settings.mail', [
'disabled' => $this->config->get('mail.default') !== 'smtp',
'disabled' => config('mail.default') !== 'smtp',
]);
}
@ -47,7 +45,7 @@ class MailController extends Controller
*/
public function update(MailSettingsFormRequest $request): Response
{
if ($this->config->get('mail.default') !== 'smtp') {
if (config('mail.default') !== 'smtp') {
throw new DisplayException('This feature is only available if SMTP is the selected email driver for the Panel.');
}

View File

@ -6,7 +6,6 @@ use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Events\Auth\FailedCaptcha;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Events\Dispatcher;
use Symfony\Component\HttpKernel\Exception\HttpException;
@ -15,7 +14,7 @@ class VerifyReCaptcha
/**
* VerifyReCaptcha constructor.
*/
public function __construct(private Dispatcher $dispatcher, private Repository $config)
public function __construct(private Dispatcher $dispatcher)
{
}
@ -24,15 +23,15 @@ class VerifyReCaptcha
*/
public function handle(Request $request, \Closure $next): mixed
{
if (!$this->config->get('recaptcha.enabled')) {
if (!config('recaptcha.enabled')) {
return $next($request);
}
if ($request->filled('g-recaptcha-response')) {
$client = new Client();
$res = $client->post($this->config->get('recaptcha.domain'), [
$res = $client->post(config('recaptcha.domain'), [
'form_params' => [
'secret' => $this->config->get('recaptcha.secret_key'),
'secret' => config('recaptcha.secret_key'),
'response' => $request->input('g-recaptcha-response'),
],
]);
@ -40,7 +39,7 @@ class VerifyReCaptcha
if ($res->getStatusCode() === 200) {
$result = json_decode($res->getBody());
if ($result->success && (!$this->config->get('recaptcha.verify_domain') || $this->isResponseVerified($result, $request))) {
if ($result->success && (!config('recaptcha.verify_domain') || $this->isResponseVerified($result, $request))) {
return $next($request);
}
}
@ -61,7 +60,7 @@ class VerifyReCaptcha
*/
private function isResponseVerified(\stdClass $result, Request $request): bool
{
if (!$this->config->get('recaptcha.verify_domain')) {
if (!config('recaptcha.verify_domain')) {
return false;
}

View File

@ -4,18 +4,10 @@ namespace App\Services\Eggs;
use Ramsey\Uuid\Uuid;
use App\Models\Egg;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use App\Exceptions\Service\Egg\NoParentConfigurationFoundException;
class EggCreationService
{
/**
* EggCreationService constructor.
*/
public function __construct(private ConfigRepository $config)
{
}
/**
* Create a new egg.
*
@ -32,7 +24,7 @@ class EggCreationService
return Egg::query()->create(array_merge($data, [
'uuid' => Uuid::uuid4()->toString(),
'author' => $this->config->get('panel.service.author'),
'author' => config('panel.service.author'),
]));
}
}

View File

@ -4,7 +4,6 @@ namespace App\Services\Users;
use App\Models\User;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
class TwoFactorSetupService
{
@ -14,7 +13,6 @@ class TwoFactorSetupService
* TwoFactorSetupService constructor.
*/
public function __construct(
private ConfigRepository $config,
private Encrypter $encrypter,
) {
}
@ -30,7 +28,7 @@ class TwoFactorSetupService
{
$secret = '';
try {
for ($i = 0; $i < $this->config->get('panel.auth.2fa.bytes', 16); $i++) {
for ($i = 0; $i < config('panel.auth.2fa.bytes', 16); $i++) {
$secret .= substr(self::VALID_BASE32_CHARACTERS, random_int(0, 31), 1);
}
} catch (\Exception $exception) {
@ -40,7 +38,7 @@ class TwoFactorSetupService
$user->totp_secret = $this->encrypter->encrypt($secret);
$user->save();
$company = urlencode(preg_replace('/\s/', '', $this->config->get('app.name')));
$company = urlencode(preg_replace('/\s/', '', config('app.name')));
return [
'image_url_data' => sprintf(