Skip to content

Instantly share code, notes, and snippets.

@ErlendEllingsen
Created February 5, 2018 23:24
Show Gist options
  • Save ErlendEllingsen/3b82af9eb7147f5159ba8e1086c6ef93 to your computer and use it in GitHub Desktop.
Save ErlendEllingsen/3b82af9eb7147f5159ba8e1086c6ef93 to your computer and use it in GitHub Desktop.
<?php
class BasePathGenerator {
private static $isSet = false;
private static $foundBasePath = null;
public static function get() {
if (self::$isSet) return self::$foundBasePath;
if (!isset($_SERVER['REQUEST_URI'])) return false;
$jumps = explode('/', $_SERVER['REQUEST_URI']);
$c = count($jumps);
$c--; //Remove first element
$path = '';
for ($i = 0; $i < $c; $i++) {
$path .= '../';
}
self::$isSet = true;
self::$foundBasePath = $path;
return $path;
}
//end BasePathGenerator
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment