Unified app and view config into a single file

This commit is contained in:
Chris Kankiewicz
2020-02-18 12:59:55 -07:00
parent 7d6356298e
commit 6fd2212bc9
7 changed files with 40 additions and 50 deletions

View File

@@ -3,6 +3,28 @@
use App\Support\Helpers;
return [
/**
* Enable dark mode?
*
* Default value: false
*/
'dark_mode' => Helpers::env('DARK_MODE'),
/**
* Parse and render README files on the page.
*
* Default value: true
*/
'display_readmes' => Helpers::env('DISPLAY_READMES'),
/**
* Your Google analytics tracking ID.
* Expected format: 'UA-123456789-0'.
*
* Default value: false
*/
'google_analytics_id' => Helpers::env('GOOGLE_ANALYTICS_ID'),
/**
* Sorting order of files and folders.
*
@@ -44,11 +66,12 @@ return [
'hide_vcs_files' => Helpers::env('HIDE_VSC_FILES'),
/**
* Parse and render README files on the page.
* Default date format. For additional info on date formatting see:
* https://www.php.net/manual/en/function.date.php.
*
* Default value: true
* Default value: 'Y-m-d H:i:s'
*/
'display_readmes' => Helpers::env('DISPLAY_READMES'),
'date_format' => Helpers::env('DATE_FORMAT'),
/**
* The maximum file size (in bytes) that can be hashed. This helps to
@@ -57,4 +80,12 @@ return [
* Default value: 1000000000
*/
'max_hash_size' => Helpers::env('MAX_HASH_SIZE'),
/**
* Path to the view cache directory.
* Set to 'false' to disable view caching entirely.
*
* Default value: 'app/cache/views'
*/
'view_cache' => Helpers::env('VIEW_CACHE'),
];

View File

@@ -1,36 +0,0 @@
<?php
use App\Support\Helpers;
return [
/**
* Enable dark mode?
*
* Default value: false
*/
'dark_mode' => Helpers::env('DARK_MODE'),
/**
* Your Google analytics tracking ID.
* Expected format: 'UA-123456789-0'.
*
* Default value: false
*/
'google_analytics_id' => Helpers::env('GOOGLE_ANALYTICS_ID'),
/**
* Default date format. For additional info on date formatting see:
* https://www.php.net/manual/en/function.date.php.
*
* Default value: 'Y-m-d H:i:s'
*/
'date_format' => Helpers::env('DATE_FORMAT'),
/**
* Path to the view cache directory.
* Set to 'false' to disable view caching entirely.
*
* Default value: 'app/cache/views'
*/
'cache' => Helpers::env('VIEW_CACHE'),
];

View File

@@ -52,11 +52,11 @@ class TwigProvider
$twig = new Twig(new FilesystemLoader('app/views'));
$twig->getEnvironment()->setCache(
$this->config->get('view.cache', 'app/cache/views')
$this->config->get('app.view_cache', 'app/cache/views')
);
$twig->getEnvironment()->getExtension(CoreExtension::class)->setDateFormat(
$this->config->get('view.date_format', 'Y-m-d H:i:s'), '%d days'
$this->config->get('app.date_format', 'Y-m-d H:i:s'), '%d days'
);
foreach (self::VIEW_FUNCTIONS as $function) {

View File

@@ -17,8 +17,6 @@ class Config extends ViewFunction
*/
public function __invoke(string $key, $default = null)
{
$viewConfig = $this->config->split('view');
return $viewConfig->get($key, $default);
return $this->config->split('app')->get($key, $default);
}
}

View File

@@ -17,6 +17,5 @@ class ConfigProviderTest extends TestCase
$this->assertInstanceOf(Config::class, $config);
$this->assertTrue($config->has('app'));
$this->assertTrue($config->has('icons'));
$this->assertTrue($config->has('view'));
}
}

View File

@@ -35,10 +35,8 @@ class TestCase extends PHPUnitTestCase
'hide_vcs_files' => false,
'display_readmes' => true,
'max_hash_size' => 1000000000,
],
'view' => [
'cache' => false
],
'view_cache' => false,
]
]);
$this->container = new Container();

View File

@@ -18,7 +18,7 @@ class ConfigTest extends TestCase
$this->config = new AppConfig([
'foo' => false,
'bar' => 'Red herring',
'view' => [
'app' => [
'foo' => 'Test value; please ignore'
],
]);