* fix #71 find config.php automatically. in current and parent directories. Show error message if not found.
This commit is contained in:
parent
320e4e68cf
commit
8590e36394
4 changed files with 53 additions and 13 deletions
|
@ -1,10 +1,12 @@
|
|||
# Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
- find config.php automatically in current and parent directories. Show error message if not found.
|
||||
|
||||
## [0.2.1] - 2018-07-01
|
||||
|
||||
### Breaking Changes
|
||||
|
|
43
src/boot.php
Normal file
43
src/boot.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?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());
|
||||
}
|
||||
|
||||
/**
|
||||
* searches for a config-file in the current and parent directories until found.
|
||||
* @return path to found config file, or FALSE otherwise.
|
||||
*/
|
||||
function find_config($filename='config.php'){
|
||||
// Count the deph of the current directory, so we know how far we can go up.
|
||||
$path_length = substr_count(getcwd(),DIRECTORY_SEPARATOR)
|
||||
+ 1; // also search the current directory
|
||||
|
||||
$dir = '.'; // updated in each loop
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* searches and loads the config file. Prints an error if not found.
|
||||
*/
|
||||
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';
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in a new issue