Add a proper config system

This commit is contained in:
Olivier 'reivilibre' 2021-08-14 09:28:42 +01:00
parent 6de2ac40df
commit 29b919fd15
4 changed files with 36 additions and 2 deletions

2
.gitignore vendored
View File

@ -49,4 +49,4 @@ Thumbs.db
*.db
*.sqlite
*.zip
/src/config.php

View File

@ -24,6 +24,11 @@
"input": "src/api",
"output": "/api"
},
{
"glob": "config*.php",
"input": "src",
"output": "/"
},
{
"glob": "*.json",
"input": "src/json",

View File

@ -11,7 +11,13 @@ use RedBeanPHP\R;
require './vendor/autoload.php';
R::setup('sqlite:taskboard.sqlite');
$CONFIG = require('../config.default.php');
if (file_exists('../config.php')) {
$CONFIG = array_merge($CONFIG, require('../config.php'));
}
R::setup($CONFIG['database'], $CONFIG['database_user'], $CONFIG['database_password']);
$container = new DI\Container();
AppFactory::setContainer($container);

23
src/config.default.php Normal file
View File

@ -0,0 +1,23 @@
<?php
// Do not edit config.default.php as this may hinder your upgrade to a future version.
// Make a copy of it called config.php!
return array(
/**
* Database configuration settings.
*
* SQLite does not use or need a user or password.
*
* For SQLite, use sqlite:path_to_db.sqlite (the path is relative to the api/ directory).
*
* For Postgres, use e.g. pgsql:host=localhost;dbname=taskboard for a TCP connection,
* or e.g. pgsql:dbname=taskboard for a UNIX socket connection
*
* See https://redbeanphp.com/index.php?p=/connection for more options.
*/
'database' => 'sqlite:taskboard.sqlite',
'database_user' => '',
'database_password' => '',
);