mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-29 02:11:10 -06:00
Used constants when possible when parsing app config
This commit is contained in:
parent
3b95925217
commit
0d9c7282df
@ -13,8 +13,8 @@ class ApplicationConfigCustomizer implements ConfigCustomizerInterface
|
||||
{
|
||||
use StringUtilsTrait;
|
||||
|
||||
private const SECRET = 'SECRET';
|
||||
private const DISABLE_TRACK_PARAM = 'DISABLE_TRACK_PARAM';
|
||||
public const SECRET = 'SECRET';
|
||||
public const DISABLE_TRACK_PARAM = 'DISABLE_TRACK_PARAM';
|
||||
private const EXPECTED_KEYS = [
|
||||
self::SECRET,
|
||||
self::DISABLE_TRACK_PARAM,
|
||||
|
@ -16,12 +16,12 @@ class DatabaseConfigCustomizer implements ConfigCustomizerInterface
|
||||
{
|
||||
use AskUtilsTrait;
|
||||
|
||||
private const DRIVER = 'DRIVER';
|
||||
private const NAME = 'NAME';
|
||||
private const USER = 'USER';
|
||||
private const PASSWORD = 'PASSWORD';
|
||||
private const HOST = 'HOST';
|
||||
private const PORT = 'PORT';
|
||||
public const DRIVER = 'DRIVER';
|
||||
public const NAME = 'NAME';
|
||||
public const USER = 'USER';
|
||||
public const PASSWORD = 'PASSWORD';
|
||||
public const HOST = 'HOST';
|
||||
public const PORT = 'PORT';
|
||||
private const DRIVER_DEPENDANT_OPTIONS = [
|
||||
self::DRIVER,
|
||||
self::NAME,
|
||||
|
@ -10,8 +10,8 @@ use function array_keys;
|
||||
|
||||
class LanguageConfigCustomizer implements ConfigCustomizerInterface
|
||||
{
|
||||
private const DEFAULT_LANG = 'DEFAULT';
|
||||
private const CLI_LANG = 'CLI';
|
||||
public const DEFAULT_LANG = 'DEFAULT';
|
||||
public const CLI_LANG = 'CLI';
|
||||
private const EXPECTED_KEYS = [
|
||||
self::DEFAULT_LANG,
|
||||
self::CLI_LANG,
|
||||
|
@ -15,10 +15,10 @@ class UrlShortenerConfigCustomizer implements ConfigCustomizerInterface
|
||||
{
|
||||
use AskUtilsTrait;
|
||||
|
||||
private const SCHEMA = 'SCHEMA';
|
||||
private const HOSTNAME = 'HOSTNAME';
|
||||
private const CHARS = 'CHARS';
|
||||
private const VALIDATE_URL = 'VALIDATE_URL';
|
||||
public const SCHEMA = 'SCHEMA';
|
||||
public const HOSTNAME = 'HOSTNAME';
|
||||
public const CHARS = 'CHARS';
|
||||
public const VALIDATE_URL = 'VALIDATE_URL';
|
||||
private const EXPECTED_KEYS = [
|
||||
self::SCHEMA,
|
||||
self::HOSTNAME,
|
||||
|
@ -3,6 +3,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Installer\Model;
|
||||
|
||||
use Shlinkio\Shlink\Installer\Config\Plugin\ApplicationConfigCustomizer;
|
||||
use Shlinkio\Shlink\Installer\Config\Plugin\DatabaseConfigCustomizer;
|
||||
use Shlinkio\Shlink\Installer\Config\Plugin\LanguageConfigCustomizer;
|
||||
use Shlinkio\Shlink\Installer\Config\Plugin\UrlShortenerConfigCustomizer;
|
||||
use Zend\Stdlib\ArraySerializableInterface;
|
||||
use function Shlinkio\Shlink\Common\array_get_path;
|
||||
use function Shlinkio\Shlink\Common\array_path_exists;
|
||||
@ -115,29 +119,29 @@ final class CustomizableAppConfig implements ArraySerializableInterface
|
||||
public function exchangeArray(array $array): void
|
||||
{
|
||||
$this->setApp($this->mapExistingPathsToKeys([
|
||||
'SECRET' => ['app_options', 'secret_key'],
|
||||
'DISABLE_TRACK_PARAM' => ['app_options', 'disable_track_param'],
|
||||
ApplicationConfigCustomizer::SECRET => ['app_options', 'secret_key'],
|
||||
ApplicationConfigCustomizer::DISABLE_TRACK_PARAM => ['app_options', 'disable_track_param'],
|
||||
], $array));
|
||||
|
||||
$this->setDatabase($this->mapExistingPathsToKeys([
|
||||
'DRIVER' => ['entity_manager', 'connection', 'driver'],
|
||||
'USER' => ['entity_manager', 'connection', 'user'],
|
||||
'PASSWORD' => ['entity_manager', 'connection', 'password'],
|
||||
'NAME' => ['entity_manager', 'connection', 'dbname'],
|
||||
'HOST' => ['entity_manager', 'connection', 'host'],
|
||||
'PORT' => ['entity_manager', 'connection', 'port'],
|
||||
DatabaseConfigCustomizer::DRIVER => ['entity_manager', 'connection', 'driver'],
|
||||
DatabaseConfigCustomizer::USER => ['entity_manager', 'connection', 'user'],
|
||||
DatabaseConfigCustomizer::PASSWORD => ['entity_manager', 'connection', 'password'],
|
||||
DatabaseConfigCustomizer::NAME => ['entity_manager', 'connection', 'dbname'],
|
||||
DatabaseConfigCustomizer::HOST => ['entity_manager', 'connection', 'host'],
|
||||
DatabaseConfigCustomizer::PORT => ['entity_manager', 'connection', 'port'],
|
||||
], $array));
|
||||
|
||||
$this->setLanguage($this->mapExistingPathsToKeys([
|
||||
'DEFAULT' => ['translator', 'locale'],
|
||||
'CLI' => ['cli', 'locale'],
|
||||
LanguageConfigCustomizer::DEFAULT_LANG => ['translator', 'locale'],
|
||||
LanguageConfigCustomizer::CLI_LANG => ['cli', 'locale'],
|
||||
], $array));
|
||||
|
||||
$this->setUrlShortener($this->mapExistingPathsToKeys([
|
||||
'SCHEMA' => ['url_shortener', 'domain', 'schema'],
|
||||
'HOSTNAME' => ['url_shortener', 'domain', 'hostname'],
|
||||
'CHARS' => ['url_shortener', 'shortcode_chars'],
|
||||
'VALIDATE_URL' => ['url_shortener', 'validate_url'],
|
||||
UrlShortenerConfigCustomizer::SCHEMA => ['url_shortener', 'domain', 'schema'],
|
||||
UrlShortenerConfigCustomizer::HOSTNAME => ['url_shortener', 'domain', 'hostname'],
|
||||
UrlShortenerConfigCustomizer::CHARS => ['url_shortener', 'shortcode_chars'],
|
||||
UrlShortenerConfigCustomizer::VALIDATE_URL => ['url_shortener', 'validate_url'],
|
||||
], $array));
|
||||
}
|
||||
|
||||
@ -155,11 +159,11 @@ final class CustomizableAppConfig implements ArraySerializableInterface
|
||||
|
||||
public function getArrayCopy(): array
|
||||
{
|
||||
$dbDriver = $this->database['DRIVER'] ?? '';
|
||||
$dbDriver = $this->database[DatabaseConfigCustomizer::DRIVER] ?? '';
|
||||
$config = [
|
||||
'app_options' => [
|
||||
'secret_key' => $this->app['SECRET'] ?? '',
|
||||
'disable_track_param' => $this->app['DISABLE_TRACK_PARAM'] ?? null,
|
||||
'secret_key' => $this->app[ApplicationConfigCustomizer::SECRET] ?? '',
|
||||
'disable_track_param' => $this->app[ApplicationConfigCustomizer::DISABLE_TRACK_PARAM] ?? null,
|
||||
],
|
||||
'entity_manager' => [
|
||||
'connection' => [
|
||||
@ -167,18 +171,18 @@ final class CustomizableAppConfig implements ArraySerializableInterface
|
||||
],
|
||||
],
|
||||
'translator' => [
|
||||
'locale' => $this->language['DEFAULT'] ?? 'en',
|
||||
'locale' => $this->language[LanguageConfigCustomizer::DEFAULT_LANG] ?? 'en',
|
||||
],
|
||||
'cli' => [
|
||||
'locale' => $this->language['CLI'] ?? 'en',
|
||||
'locale' => $this->language[LanguageConfigCustomizer::CLI_LANG] ?? 'en',
|
||||
],
|
||||
'url_shortener' => [
|
||||
'domain' => [
|
||||
'schema' => $this->urlShortener['SCHEMA'] ?? 'http',
|
||||
'hostname' => $this->urlShortener['HOSTNAME'] ?? '',
|
||||
'schema' => $this->urlShortener[UrlShortenerConfigCustomizer::SCHEMA] ?? 'http',
|
||||
'hostname' => $this->urlShortener[UrlShortenerConfigCustomizer::HOSTNAME] ?? '',
|
||||
],
|
||||
'shortcode_chars' => $this->urlShortener['CHARS'] ?? '',
|
||||
'validate_url' => $this->urlShortener['VALIDATE_URL'] ?? true,
|
||||
'shortcode_chars' => $this->urlShortener[UrlShortenerConfigCustomizer::CHARS] ?? '',
|
||||
'validate_url' => $this->urlShortener[UrlShortenerConfigCustomizer::VALIDATE_URL] ?? true,
|
||||
],
|
||||
];
|
||||
|
||||
@ -186,11 +190,12 @@ final class CustomizableAppConfig implements ArraySerializableInterface
|
||||
if ($dbDriver === 'pdo_sqlite') {
|
||||
$config['entity_manager']['connection']['path'] = self::SQLITE_DB_PATH;
|
||||
} else {
|
||||
$config['entity_manager']['connection']['user'] = $this->database['USER'] ?? '';
|
||||
$config['entity_manager']['connection']['password'] = $this->database['PASSWORD'] ?? '';
|
||||
$config['entity_manager']['connection']['dbname'] = $this->database['NAME'] ?? '';
|
||||
$config['entity_manager']['connection']['host'] = $this->database['HOST'] ?? '';
|
||||
$config['entity_manager']['connection']['port'] = $this->database['PORT'] ?? '';
|
||||
$config['entity_manager']['connection']['user'] = $this->database[DatabaseConfigCustomizer::USER] ?? '';
|
||||
$config['entity_manager']['connection']['password'] =
|
||||
$this->database[DatabaseConfigCustomizer::PASSWORD] ?? '';
|
||||
$config['entity_manager']['connection']['dbname'] = $this->database[DatabaseConfigCustomizer::NAME] ?? '';
|
||||
$config['entity_manager']['connection']['host'] = $this->database[DatabaseConfigCustomizer::HOST] ?? '';
|
||||
$config['entity_manager']['connection']['port'] = $this->database[DatabaseConfigCustomizer::PORT] ?? '';
|
||||
|
||||
if ($dbDriver === 'pdo_mysql') {
|
||||
$config['entity_manager']['connection']['driverOptions'] = [
|
||||
|
Loading…
Reference in New Issue
Block a user