Add support to override application constants

This commit is contained in:
Frederic Guillot 2013-07-06 12:11:29 -04:00
parent 2a67751e84
commit 16f0bd4966
5 changed files with 36 additions and 15 deletions

4
.gitignore vendored
View File

@ -38,3 +38,7 @@ Thumbs.db
*~
*.lock
*.out
# App specific #
################
config.php

View File

@ -118,3 +118,25 @@ You can report feeds that doesn't works properly too.
Miniflux is tested with the latest versions of Mozilla Firefox, Google Chrome and Safari.
I don't use Microsoft products, then I have no idea if Miniflux works correctly with Internet Explorer.
### How to override application variables?
There is few settings that can't be changed by the user interface.
These parameters are defined with PHP constants.
To override them, create a `config.php` file at the root of the project and change yourself the values.
By example, to override the default HTTP timeout value:
# file config.php
<?php
// My specific HTTP timeout (5 seconds)
define('HTTP_TIMEOUT', 5);
Actually, the following constants can be overrided:
- `HTTP_TIMEOUT` => default value is 10 seconds
- `APP_VERSION` => default value is master
- `DB_FILENAME` => default value is `data/db.sqlite`

View File

@ -9,26 +9,20 @@ require 'vendor/PicoDb/Table.php';
require 'schema.php';
require 'model.php';
if (file_exists('config.php')) require 'config.php';
const DB_VERSION = 9;
const APP_VERSION = 'master';
const HTTP_TIMEOUT = 10;
function get_db_filename()
{
return 'data/db.sqlite';
}
defined('APP_VERSION') or define('APP_VERSION', 'master');
defined('HTTP_TIMEOUT') or define('HTTP_TIMEOUT', 10);
defined('DB_FILENAME') or define('DB_FILENAME', 'data/db.sqlite');
PicoTools\container('db', function() {
$db = new PicoDb\Database(array(
'driver' => 'sqlite',
'filename' => get_db_filename()
'filename' => DB_FILENAME
));
if ($db->schema()->check(DB_VERSION)) {
if ($db->schema()->check(Model\DB_VERSION)) {
return $db;
}

View File

@ -394,7 +394,7 @@ Router\get_action('optimize-db', function() {
Router\get_action('download-db', function() {
Response\force_download('db.sqlite.gz');
Response\binary(gzencode(file_get_contents(get_db_filename())));
Response\binary(gzencode(file_get_contents(DB_FILENAME)));
});
@ -439,7 +439,7 @@ Router\get_action('config', function() {
Response\html(Template\layout('config', array(
'errors' => array(),
'values' => Model\get_config(),
'db_size' => filesize(get_db_filename()),
'db_size' => filesize(DB_FILENAME),
'languages' => Model\get_languages(),
'autoflush_options' => Model\get_autoflush_options(),
'paging_options' => Model\get_paging_options(),
@ -472,7 +472,7 @@ Router\post_action('config', function() {
Response\html(Template\layout('config', array(
'errors' => $errors,
'values' => $values,
'db_size' => filesize(get_db_filename()),
'db_size' => filesize(DB_FILENAME),
'languages' => Model\get_languages(),
'autoflush_options' => Model\get_autoflush_options(),
'paging_options' => Model\get_paging_options(),

View File

@ -22,6 +22,7 @@ use PicoFeed\Reader;
use PicoFeed\Export;
const DB_VERSION = 9;
const HTTP_USERAGENT = 'Miniflux - http://miniflux.net';
const LIMIT_ALL = -1;