Skip to content

Commit

Permalink
Merge pull request #12 from librarianphp/newconfig
Browse files Browse the repository at this point in the history
Restructured configuration
  • Loading branch information
erikaheidi authored Mar 16, 2022
2 parents 031bbb7 + f1d7f51 commit 63ac673
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/app', __DIR__ . '/tests'])
->in([__DIR__ . '/app', __DIR__ . '/tests', __DIR__ . '/config'])
->name('*.php')
;

Expand Down
70 changes: 0 additions & 70 deletions app/Command/Web/CoverController.php

This file was deleted.

22 changes: 22 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

function config_default(string $config_dir): array
{
$config = [];

foreach (glob($config_dir . '/*.php') as $config_file) {
$config_data = include $config_file;
if (is_array($config_data)) {
$config = array_merge($config, $config_data);
}
}

return $config;
}

function load_config(): array
{
return array_merge(config_default(__DIR__ . '/../config'), include __DIR__ . '/../config.php');
}
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
"files": [
"app/helpers.php"
]
},
"require": {
"php": ">=8.0",
Expand Down
11 changes: 11 additions & 0 deletions config/devto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
/*****************************************************************************
* Dev.to Settings
* Set Up your dev.to username here or via ENV var.
* This is required if you want to import your posts from the dev.to platform.
******************************************************************************/
'devto_username' => getenv('DEVTO_USER'),
'devto_datadir' => '_to',
];
18 changes: 18 additions & 0 deletions config/minicli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

return [
/****************************************************************************
* Minicli Settings
* You shouldn't need to change the next settings,
* but you are free to do so at your own risk.
*****************************************************************************/
'app_path' => __DIR__ . '/../app/Command',
'theme' => 'unicorn',
'templates_path' => __DIR__ . '/../app/Resources/themes/default',
'data_path' => __DIR__ . '/../app/Resources/data',
'cache_path' => __DIR__ . '/../var/cache',
'stencil_dir' => __DIR__ . '/../app/Resources/stencil',
'stencil_locations' => [
'post' => __DIR__ . '/../app/Resources/data/_p'
]
];
11 changes: 11 additions & 0 deletions config/tests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
/*****************************************************************************
* End-to-end tests require you to set here the app url for testing.
* For Docker Compose setups, this should be where Nginx is running.
******************************************************************************/
'app_testing_url' => 'http://localhost', # Regular LEMP/LAMP/PHP built-in server
#'app_testing_url' => 'http://nginx', # Docker Compose w/ separate Nginx service

];
39 changes: 4 additions & 35 deletions config_sample.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<?php

/* Librarian Main Configuration */

return [
/****************************************************************************************
* Librarian site Info
* Update accordingly, and/or set up ENV vars with your preferred values.
* Librarian main config
* Values set here will overwrite default configuration from the /config dir.
*****************************************************************************************/
'site_name' => getenv('SITE_NAME') ?: 'Librarian',
'site_author' => getenv('SITE_AUTHOR') ?: '@erikaheidi',
'author_email' => getenv('SITE_AUTHOR') ?: 'erika@erikaheidi.com',
'site_description' => getenv('SITE_DESC') ?: 'Minimalist file-based CMS in PHP',
'site_url' => getenv('SITE_URL') ?: 'http://localhost:8000',
'site_root' => getenv('SITE_ROOT') ?: '/',
Expand All @@ -23,34 +20,6 @@
'Twitch' => getenv('LINK_TWITCH'),
],
'app_debug' => getenv('APP_DEBUG') ?: true,

/*****************************************************************************
* End-to-end tests require you to set here the app url for testing.
* For Docker Compose setups, this should be where Nginx is running.
******************************************************************************/
#'app_testing_url' => getenv('TEST_BASE_URL') ?: 'http://localhost', # Regular LEMP/LAMP/PHP built-in server
'app_testing_url' => getenv('TEST_BASE_URL') ?: 'http://nginx', # Docker Compose w/ separate Nginx service

/*****************************************************************************
* Dev.to Settings
* Set Up your dev.to username here or via ENV var.
* This is required if you want to import your posts from the dev.to platform.
******************************************************************************/
'app_testing_url' => getenv('TEST_BASE_URL') ?: 'http://nginx',
'devto_username' => getenv('DEVTO_USER'),
'devto_datadir' => '_to',

/****************************************************************************
* Other Settings
* You shouldn't need to change the next settings,
* but you are free to do so at your own risk.
*****************************************************************************/
'app_path' => __DIR__ . '/app/Command',
'theme' => 'unicorn',
'templates_path' => __DIR__ . '/app/Resources/themes/default',
'data_path' => __DIR__ . '/app/Resources/data',
'cache_path' => __DIR__ . '/var/cache',
'stencil_dir' => __DIR__ . '/app/Resources/stencil',
'stencil_locations' => [
'post' => __DIR__ . '/app/Resources/data/_p'
]
];
];
2 changes: 1 addition & 1 deletion librarian
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Minicli\App;
use Librarian\Provider\ContentServiceProvider;
use Librarian\Provider\DevtoServiceProvider;

$app = new App(require __DIR__ . '/config.php');
$app = new App(load_config());
$app->setSignature('
_ ____ ____ ____ ____ ____ ____ ____ ____
| | | || \ | \ / || \ | | / || \
Expand Down
7 changes: 2 additions & 5 deletions tests/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ function getCommandsPath(): string

function getApp(): App
{
return new App(array_merge(include __DIR__ . '/../config.php', [
'data_path' => __DIR__ . '/resources',
'cache_path' => __DIR__ . '/resources'
]));
return new App(load_config(__DIR__ . '/../config'));
}

function getWebApp(): App
Expand All @@ -33,7 +30,7 @@ function getWebApp(): App

function getConfigValue(string $key): mixed
{
$config = include __DIR__ . '/../config.php';
$config = load_config(__DIR__ . '/../config');

return $config[$key] ?: null;
}
Expand Down
2 changes: 1 addition & 1 deletion web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Librarian\Provider\LibrarianServiceProvider;
use Librarian\Response;

$app = new App(require __DIR__ . '/../config.php');
$app = new App(load_config());

$app->addService('twig', new TwigServiceProvider());
$app->addService('router', new RouterServiceProvider());
Expand Down

0 comments on commit 63ac673

Please sign in to comment.