mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-17 07:49:54 +03:00
Updated to latest installer with support for env vars
This commit is contained in:
parent
0d37eb65c9
commit
c6f16b0558
6 changed files with 45 additions and 13 deletions
|
@ -51,7 +51,7 @@
|
|||
"shlinkio/shlink-config": "^1.5",
|
||||
"shlinkio/shlink-event-dispatcher": "^2.3",
|
||||
"shlinkio/shlink-importer": "^2.5",
|
||||
"shlinkio/shlink-installer": "dev-develop#a008036 as 7.0",
|
||||
"shlinkio/shlink-installer": "dev-develop#ba32503 as 7.0",
|
||||
"shlinkio/shlink-ip-geolocation": "^2.2",
|
||||
"symfony/console": "^6.0",
|
||||
"symfony/filesystem": "^6.0",
|
||||
|
|
|
@ -38,7 +38,7 @@ return (static function (): array {
|
|||
'dbname' => env('DB_NAME', 'shlink'),
|
||||
'user' => env('DB_USER'),
|
||||
'password' => env('DB_PASSWORD'),
|
||||
'host' => env('DB_HOST', $driver === 'postgres' ? env('DB_UNIX_SOCKET') : null),
|
||||
'host' => env('DB_HOST', env('DB_UNIX_SOCKET')),
|
||||
'port' => env('DB_PORT', $resolveDefaultPort()),
|
||||
'unix_socket' => $isMysqlCompatible ? env('DB_UNIX_SOCKET') : null,
|
||||
'charset' => $resolveCharset(),
|
||||
|
|
|
@ -18,8 +18,6 @@ return [
|
|||
Option\Database\DatabaseUserConfigOption::class,
|
||||
Option\Database\DatabasePasswordConfigOption::class,
|
||||
Option\Database\DatabaseUnixSocketConfigOption::class,
|
||||
Option\Database\DatabaseSqlitePathConfigOption::class,
|
||||
Option\Database\DatabaseMySqlOptionsConfigOption::class,
|
||||
Option\UrlShortener\ShortDomainHostConfigOption::class,
|
||||
Option\UrlShortener\ShortDomainSchemaConfigOption::class,
|
||||
Option\Visit\VisitsWebhooksConfigOption::class,
|
||||
|
@ -27,12 +25,12 @@ return [
|
|||
Option\Redirect\BaseUrlRedirectConfigOption::class,
|
||||
Option\Redirect\InvalidShortUrlRedirectConfigOption::class,
|
||||
Option\Redirect\Regular404RedirectConfigOption::class,
|
||||
Option\Visit\CheckVisitsThresholdConfigOption::class,
|
||||
Option\Visit\VisitsThresholdConfigOption::class,
|
||||
Option\BasePathConfigOption::class,
|
||||
Option\Worker\TaskWorkerNumConfigOption::class,
|
||||
Option\Worker\WebWorkerNumConfigOption::class,
|
||||
Option\RedisConfigOption::class,
|
||||
Option\Redis\RedisServersConfigOption::class,
|
||||
Option\Redis\RedisSentinelServiceConfigOption::class,
|
||||
Option\UrlShortener\ShortCodeLengthOption::class,
|
||||
Option\Mercure\EnableMercureConfigOption::class,
|
||||
Option\Mercure\MercurePublicUrlConfigOption::class,
|
||||
|
|
|
@ -12,12 +12,25 @@ use Mezzio\Swoole;
|
|||
|
||||
use function class_exists;
|
||||
use function Shlinkio\Shlink\Config\env;
|
||||
use function Shlinkio\Shlink\Core\putNotYetDefinedEnv;
|
||||
|
||||
use const PHP_SAPI;
|
||||
|
||||
$isCli = PHP_SAPI === 'cli';
|
||||
$isTestEnv = env('APP_ENV') === 'test';
|
||||
|
||||
return (new ConfigAggregator\ConfigAggregator([
|
||||
! $isTestEnv
|
||||
? new ConfigAggregator\ArrayProvider((new ConfigAggregator\ConfigAggregator([
|
||||
new ConfigAggregator\PhpFileProvider('config/params/generated_config.php'),
|
||||
], null, [function (array $generatedConfig) {
|
||||
foreach ($generatedConfig as $envVar => $value) {
|
||||
putNotYetDefinedEnv($envVar, $value);
|
||||
}
|
||||
|
||||
return [];
|
||||
}]))->getMergedConfig())
|
||||
: new ConfigAggregator\ArrayProvider([]),
|
||||
Mezzio\ConfigProvider::class,
|
||||
Mezzio\Router\ConfigProvider::class,
|
||||
Mezzio\Router\FastRouteRouter\ConfigProvider::class,
|
||||
|
@ -35,9 +48,9 @@ return (new ConfigAggregator\ConfigAggregator([
|
|||
CLI\ConfigProvider::class,
|
||||
Rest\ConfigProvider::class,
|
||||
new ConfigAggregator\PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'),
|
||||
env('APP_ENV') === 'test'
|
||||
$isTestEnv
|
||||
? new ConfigAggregator\PhpFileProvider('config/test/*.global.php')
|
||||
: new ConfigAggregator\PhpFileProvider('config/params/generated_config.php'),
|
||||
: new ConfigAggregator\ArrayProvider([]),
|
||||
], 'data/cache/app_config.php', [
|
||||
Core\Config\BasePathPrefixer::class,
|
||||
]))->getMergedConfig();
|
||||
|
|
|
@ -13,9 +13,13 @@ use PUGX\Shortid\Factory as ShortIdFactory;
|
|||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
|
||||
use function Functional\reduce_left;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function is_scalar;
|
||||
use function print_r;
|
||||
use function putenv;
|
||||
use function Shlinkio\Shlink\Common\buildDateRange;
|
||||
use function Shlinkio\Shlink\Config\env;
|
||||
use function sprintf;
|
||||
use function str_repeat;
|
||||
|
||||
|
@ -116,3 +120,18 @@ function fieldWithUtf8Charset(FieldBuilder $field, array $emConfig, string $coll
|
|||
default => $field,
|
||||
};
|
||||
}
|
||||
|
||||
function putNotYetDefinedEnv(string $key, mixed $value): void
|
||||
{
|
||||
$isArray = is_array($value);
|
||||
if (!($isArray || is_scalar($value)) || env($key) !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$normalizedValue = $isArray ? implode(',', $value) : match ($value) {
|
||||
true => 'true',
|
||||
false => 'false',
|
||||
default => $value,
|
||||
};
|
||||
putenv(sprintf('%s=%s', $key, $normalizedValue));
|
||||
}
|
||||
|
|
|
@ -8,7 +8,9 @@ use Laminas\Stdlib\AbstractOptions;
|
|||
|
||||
use function array_key_exists;
|
||||
use function explode;
|
||||
use function Functional\map;
|
||||
use function is_array;
|
||||
use function trim;
|
||||
|
||||
class TrackingOptions extends AbstractOptions
|
||||
{
|
||||
|
@ -108,10 +110,10 @@ class TrackingOptions extends AbstractOptions
|
|||
|
||||
protected function setDisableTrackingFrom(string|array|null $disableTrackingFrom): void
|
||||
{
|
||||
if (is_array($disableTrackingFrom)) {
|
||||
$this->disableTrackingFrom = $disableTrackingFrom;
|
||||
} else {
|
||||
$this->disableTrackingFrom = $disableTrackingFrom === null ? [] : explode(',', $disableTrackingFrom);
|
||||
}
|
||||
$this->disableTrackingFrom = match (true) {
|
||||
is_array($disableTrackingFrom) => $disableTrackingFrom,
|
||||
$disableTrackingFrom === null => [],
|
||||
default => map(explode(',', $disableTrackingFrom), static fn (string $value) => trim($value)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue