fix #71 find config.php automatically in current and parent directori… (#74)

* fix #71 find config.php automatically. in current and parent directories. Show error message if not found.
This commit is contained in:
Aravindo Wingeier 2018-12-25 22:45:10 -03:00 committed by GitHub
parent 320e4e68cf
commit 8590e36394
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 13 deletions

View file

@ -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
View 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';

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';

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';