Quellcode durchsuchen

Reorder project path and project root defines (#6787)

* reorder the project_root and project_path define so isset is called
before the config key project.root is used

* ensure project path begins with a '/'

* rewrite for empty string in project_path

* Update require.php
frytimo vor 1 Jahr
Ursprung
Commit
204f63b7c5
1 geänderte Dateien mit 20 neuen und 16 gelöschten Zeilen
  1. 20 16
      resources/require.php

+ 20 - 16
resources/require.php

@@ -40,11 +40,8 @@
 		}
 	}
 
-//check if the config file exists
-	$config_exists = !empty($config_file) ? true : false;
-
 //config.conf file not found re-direct the request to the install
-	if (!$config_exists) {
+	if (empty($config_file)) {
 		header("Location: /core/install/install.php");
 		exit;
 	}
@@ -55,19 +52,26 @@
 //set the include path
 	set_include_path($conf['document.root']);
 
-//set the server variables and define project path constant
-	$_SERVER["DOCUMENT_ROOT"] = $conf['document.root'];
-	$_SERVER["PROJECT_ROOT"] = $conf['document.root'];
-	$_SERVER["PROJECT_PATH"]  = $conf['project.path'];
-	if (isset($conf['project.path'])) {
-		$_SERVER["PROJECT_ROOT"] = $conf['document.root'].'/'.$conf['project.path'];
-		if (!defined('PROJECT_ROOT')) { define("PROJECT_ROOT", $conf['document.root'].'/'.$conf['project.path']); }
-		if (!defined('PROJECT_PATH')) { define("PROJECT_PATH", $conf['project.path']); }
-	}
-	else {
-		if (!defined('PROJECT_ROOT')) { define("PROJECT_ROOT", $conf['document.root']); }
-		if (!defined('PROJECT_PATH')) { define("PROJECT_PATH", ''); }
+//set document root
+	$_SERVER["DOCUMENT_ROOT"] = substr($conf['document.root'], -1) === '/' ? substr($conf['document.root'], 0, -1) : $conf['document.root'];
+
+//set project path
+	if (isset($conf['project.path']) && !defined('PROJECT_PATH')) {
+		if (substr($conf['project.path'], 0, 1) === '/') {
+			define("PROJECT_PATH", $conf['project.path']);
+		} else {
+			if (!empty($conf['project.path'])) {
+				define("PROJECT_PATH", '/' . $conf['project.path']);
+			} else {
+				define("PROJECT_PATH", '');
+			}
+		}
 	}
+	$_SERVER["PROJECT_PATH"] = PROJECT_PATH;
+
+//set project root using project path
+	if (!defined('PROJECT_ROOT')) { define("PROJECT_ROOT", $conf['document.root'] . PROJECT_PATH); }
+	$_SERVER["PROJECT_ROOT"] = PROJECT_ROOT;
 
 //set the error reporting
 	ini_set('display_errors', '1');