/** * getSitePaths * * @param string $file Site absolute path. * @param string $script URL path. * * @return Array With wwwroot and prefix. */ public static function getSitePaths($file = "", $script = "") { if (self::$sitePaths && !defined('PHPUNIT')) { return self::$sitePaths; } if (!$file && defined("MOXMAN_API_FILE")) { $file = MOXMAN_API_FILE; } $file = $file ? $file : $_SERVER["SCRIPT_FILENAME"]; $script = $script ? $script : $_SERVER["SCRIPT_NAME"]; $file = explode("/", self::toUnixPath($file)); $script = explode("/", self::toUnixPath($script)); $u = count($file) - 1; for ($i = count($script) - 1; $i >= 0; $i--) { $val = $file[$u--]; if ($val != $script[$i]) { $u++; // To include last chunk break; } } $wwwroot = implode("/", array_slice($file, 0, $u + 1)); $prefix = implode("/", array_slice($script, 0, $i + 1)); self::$sitePaths = array("wwwroot" => $wwwroot, "prefix" => $prefix); return self::$sitePaths; }
/** * getSitePaths * * @param string $file Site absolute path /var/www/dir/file * @param string $script URL path. /dir/file * @return Array With wwwroot and prefix. */ public static function getSitePaths($file = "", $script = "") { // @codeCoverageIgnoreStart if (self::$sitePaths && !defined('PHPUNIT')) { return self::$sitePaths; } // @codeCoverageIgnoreEnd // Check if we have a defined MOXMAN_API_FILE this might not be the case // if MOXMAN.php is loaded directly we then need to fallback to SCRIPT_FILENAME //if (!$file && defined("MOXMAN_API_FILE")) { // $file = MOXMAN_API_FILE; //} $file = $file ? $file : MOXMAN_ROOT; $script = $script ? $script : dirname($_SERVER["SCRIPT_NAME"]); $file = explode("/", self::toUnixPath($file)); $script = explode("/", self::toUnixPath($script)); $u = count($file) - 1; for ($i = count($script) - 1; $i >= 0; $i--) { $val = $file[$u--]; if (strtolower($val) != strtolower($script[$i])) { $u++; // To include last chunk break; } } $wwwroot = implode("/", array_slice($file, 0, $u + 1)); $prefix = implode("/", array_slice($script, 0, $i + 1)); self::$sitePaths = array("wwwroot" => $wwwroot, "prefix" => $prefix); return self::$sitePaths; }