mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #1972 from dhensby/environment-conf-patch
FIX #1866 Environment file finder logic
This commit is contained in:
commit
ac0e324e1c
@ -44,24 +44,46 @@
|
|||||||
error_reporting(E_ALL | E_STRICT);
|
error_reporting(E_ALL | E_STRICT);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include _ss_environment.php files
|
* Include _ss_environment.php file
|
||||||
*/
|
*/
|
||||||
//define the name of the environment file
|
//define the name of the environment file
|
||||||
$envFile = '_ss_environment.php';
|
$envFile = '_ss_environment.php';
|
||||||
//define the dir to start scanning from (have to add the trailing slash)
|
//define the dirs to start scanning from (have to add the trailing slash)
|
||||||
$dir = '.';
|
// we're going to check the realpath AND the path as the script sees it
|
||||||
//check this dir and every parent dir (until we hit the base of the drive)
|
$dirsToCheck = array(
|
||||||
do {
|
realpath('.'),
|
||||||
$dir = realpath($dir) . '/';
|
dirname($_SERVER['SCRIPT_FILENAME'])
|
||||||
//if the file exists, then we include it, set relevant vars and break out
|
);
|
||||||
if (file_exists($dir . $envFile)) {
|
//if they are the same, remove one of them
|
||||||
define('SS_ENVIRONMENT_FILE', $dir . $envFile);
|
if ($dirsToCheck[0] == $dirsToCheck[1]) {
|
||||||
include_once(SS_ENVIRONMENT_FILE);
|
unset($dirsToCheck[1]);
|
||||||
break;
|
}
|
||||||
}
|
foreach ($dirsToCheck as $dir) {
|
||||||
//here we need to check that the real path of the last dir and the next one are
|
//check this dir and every parent dir (until we hit the base of the drive)
|
||||||
// not the same, if they are, we have hit the root of the drive
|
// or until we hit a dir we can't read
|
||||||
} while (realpath($dir) != realpath($dir .= '../'));
|
do {
|
||||||
|
//add the trailing slash we need to concatenate properly
|
||||||
|
$dir .= DIRECTORY_SEPARATOR;
|
||||||
|
//if it's readable, go ahead
|
||||||
|
if (@is_readable($dir)) {
|
||||||
|
//if the file exists, then we include it, set relevant vars and break out
|
||||||
|
if (file_exists($dir . $envFile)) {
|
||||||
|
define('SS_ENVIRONMENT_FILE', $dir . $envFile);
|
||||||
|
include_once(SS_ENVIRONMENT_FILE);
|
||||||
|
//break out of BOTH loops because we found the $envFile
|
||||||
|
break(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//break out of the while loop, we can't read the dir
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//go up a directory
|
||||||
|
$dir = dirname($dir);
|
||||||
|
//here we need to check that the path of the last dir and the next one are
|
||||||
|
// not the same, if they are, we have hit the root of the drive
|
||||||
|
} while (dirname($dir) != $dir);
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// GLOBALS AND DEFINE SETTING
|
// GLOBALS AND DEFINE SETTING
|
||||||
|
@ -28,27 +28,47 @@ if (function_exists('session_start')) {
|
|||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include environment files
|
/**
|
||||||
$usingEnv = false;
|
* Include _ss_environment.php file
|
||||||
$envFileExists = false;
|
*/
|
||||||
//define the name of the environment file
|
//define the name of the environment file
|
||||||
$envFile = '_ss_environment.php';
|
$envFile = '_ss_environment.php';
|
||||||
//define the dir to start scanning from
|
//define the dirs to start scanning from (have to add the trailing slash)
|
||||||
$dir = '.';
|
// we're going to check the realpath AND the path as the script sees it
|
||||||
//check this dir and every parent dir (until we hit the base of the drive)
|
$dirsToCheck = array(
|
||||||
do {
|
realpath('.'),
|
||||||
$dir = realpath($dir) . '/';
|
dirname($_SERVER['SCRIPT_FILENAME'])
|
||||||
//if the file exists, then we include it, set relevant vars and break out
|
);
|
||||||
if (file_exists($dir . $envFile)) {
|
//if they are the same, remove one of them
|
||||||
include_once($dir . $envFile);
|
if ($dirsToCheck[0] == $dirsToCheck[1]) {
|
||||||
$envFileExists = true;
|
unset($dirsToCheck[1]);
|
||||||
//legacy variable assignment
|
}
|
||||||
$usingEnv = true;
|
foreach ($dirsToCheck as $dir) {
|
||||||
break;
|
//check this dir and every parent dir (until we hit the base of the drive)
|
||||||
}
|
// or until we hit a dir we can't read
|
||||||
//here we need to check that the real path of the last dir and the next one are
|
do {
|
||||||
// not the same, if they are, we have hit the root of the drive
|
//add the trailing slash we need to concatenate properly
|
||||||
} while (realpath($dir) != realpath($dir .= '../'));
|
$dir .= DIRECTORY_SEPARATOR;
|
||||||
|
//if it's readable, go ahead
|
||||||
|
if (@is_readable($dir)) {
|
||||||
|
//if the file exists, then we include it, set relevant vars and break out
|
||||||
|
if (file_exists($dir . $envFile)) {
|
||||||
|
define('SS_ENVIRONMENT_FILE', $dir . $envFile);
|
||||||
|
include_once(SS_ENVIRONMENT_FILE);
|
||||||
|
//break out of BOTH loops because we found the $envFile
|
||||||
|
break(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//break out of the while loop, we can't read the dir
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//go up a directory
|
||||||
|
$dir = dirname($dir);
|
||||||
|
//here we need to check that the path of the last dir and the next one are
|
||||||
|
// not the same, if they are, we have hit the root of the drive
|
||||||
|
} while (dirname($dir) != $dir);
|
||||||
|
}
|
||||||
|
|
||||||
if($envFileExists) {
|
if($envFileExists) {
|
||||||
if(!empty($_REQUEST['useEnv'])) {
|
if(!empty($_REQUEST['useEnv'])) {
|
||||||
|
Loading…
Reference in New Issue
Block a user