fix #71 find config.php automatically in current and parent directories. Show error message if not found.

This commit is contained in:
synox 2018-12-26 02:23:11 +01:00
parent 320e4e68cf
commit 32c9a172d2
4 changed files with 48 additions and 11 deletions

View File

@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.
### Changed
- find config.php automatically in current and parent directories. Show error message if not found.
The format is based on [Keep a Changelog](http://keepachangelog.com/).
## [Unreleased]

39
src/boot.php Normal file
View File

@ -0,0 +1,39 @@
<?php
if (version_compare(phpversion(), '7.2', '<')) {
die("ERROR! The php version isn't high enough, you need at least 7.2 to run this application! But you have: " . phpversion());
}
# set the new path of config.php (must be in a safe location outside the `public_html`)
#require_once '../../config.php';
function find_config($filename='config.php'){
$path_length = substr_count(getcwd(),DIRECTORY_SEPARATOR)
+ 1; # also search the current directory
$dir = '.';
for($i=0; $i<$path_length;$i++){
$config_filename = $dir . DIRECTORY_SEPARATOR . $filename;
if(file_exists($config_filename)){
return $config_filename;
} else {
$dir = '../'.$dir;
}
}
return FALSE;
}
function load_config(){
global $config;
$file = find_config();
if ( $file !== FALSE) {
require_once($file);
} else {
die('ERROR: Config file not found. Please see the installation instructions in the README.md');
}
}
load_config();
# load php dependencies:
require_once './backend-libs/autoload.php';

View File

@ -3,11 +3,8 @@ if (version_compare(phpversion(), '7.2', '<')) {
die("ERROR! The php version isn't high enough, you need at least 7.2 to run this application! But you have: " . phpversion());
}
# set the new path of config.php (must be in a safe location outside the `public_html`)
require_once '../../config.php';
# load php dependencies:
require_once './backend-libs/autoload.php';
# load config file and dependencies
require_once './boot.php';
require_once './user.php';
require_once './imap_client.php';
@ -24,4 +21,4 @@ $controller->invoke($imapClient);
// delete after each request
$imapClient->delete_old_messages($config['delete_messages_older_than']);
?>
?>

View File

@ -1,9 +1,7 @@
<?php
# set the new path of config.php (must be in a safe location outside the `public_html`)
require_once '../../config.php';
# load php dependencies:
require_once 'backend-libs/autoload.php';
# load config file and dependencies
require_once './boot.php';
require_once 'user.php';
require_once 'imap_client.php';
@ -101,4 +99,4 @@ $controller->invoke($imapClient);
$imapClient->delete_old_messages($config['delete_messages_older_than']);
?>
?>