Skip to content

Commit

Permalink
Allow set configs as int or string instead of enums
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed May 8, 2022
1 parent a8518ff commit 4adb3bb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Framework\HTTP\Request;
use Framework\HTTP\Response;
use Framework\Language\Debug\LanguageCollector;
use Framework\Language\FallbackLevel;
use Framework\Language\Language;
use Framework\Log\Debug\LogCollector;
use Framework\Log\Logger;
Expand Down Expand Up @@ -316,10 +317,14 @@ protected static function setCache(string $instance) : Cache
if (isset($config['logger_instance'])) {
$logger = static::logger($config['logger_instance']);
}
$config['serializer'] ??= Serializer::PHP;
if (\is_string($config['serializer'])) {
$config['serializer'] = Serializer::from($config['serializer']);
}
$service = new $config['class'](
$config['configs'] ?? [],
$config['prefix'] ?? null,
$config['serializer'] ?? Serializer::PHP,
$config['serializer'],
$logger
);
return static::setService('cache', $service, $instance);
Expand Down Expand Up @@ -659,6 +664,9 @@ protected static function setLanguage(string $instance) : Language
);
}
if (isset($config['fallback_level'])) {
if (\is_int($config['fallback_level'])) {
$config['fallback_level'] = FallbackLevel::from($config['fallback_level']);
}
$service->setFallbackLevel($config['fallback_level']);
}
$config['directories'] ??= [];
Expand Down Expand Up @@ -773,11 +781,15 @@ protected static function setLogger(string $instance) : Logger
{
$config = static::config()->get('logger', $instance);
$class = $config['class'] ?? MultiFileLogger::class;
$config['level'] ??= LogLevel::DEBUG;
if (\is_int($config['level'])) {
$config['level'] = LogLevel::from($config['level']);
}
return static::setService(
'logger',
new $class(
$config['destination'],
$config['level'] ?? LogLevel::DEBUG,
$config['level'],
$config['config'] ?? [],
),
$instance
Expand Down
2 changes: 1 addition & 1 deletion tests/configs/cache.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'directory' => getenv('GITHUB_ACTION') ? getenv('RUNNER_TEMP') : sys_get_temp_dir(),
],
'prefix' => null,
'serializer' => Serializer::PHP,
'serializer' => 'php', //Serializer::PHP,
'logger_instance' => 'default',
],
];
2 changes: 1 addition & 1 deletion tests/configs/language.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'es',
'pt-br',
],
'fallback_level' => FallbackLevel::default,
'fallback_level' => 2, //FallbackLevel::default,
'directories' => null,
'negotiate' => true,
'find_in_namespaces' => true,
Expand Down
2 changes: 1 addition & 1 deletion tests/configs/logger.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
'default' => [
'class' => MultiFileLogger::class,
'destination' => sys_get_temp_dir(),
'level' => LogLevel::DEBUG,
'level' => 0, //LogLevel::DEBUG,
],
];

0 comments on commit 4adb3bb

Please sign in to comment.