Ejemplo n.º 1
0
Archivo: Url.php Proyecto: jbzoo/utils
 /**
  * Convert file path to relative URL
  *
  * @param $path
  * @return string
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public static function pathToRel($path)
 {
     $root = FS::clean(Vars::get($_SERVER['DOCUMENT_ROOT']));
     $path = FS::clean($path);
     $normRoot = str_replace(DIRECTORY_SEPARATOR, '/', $root);
     $normPath = str_replace(DIRECTORY_SEPARATOR, '/', $path);
     $regExp = '/^' . preg_quote($normRoot, '/') . '/i';
     $relative = preg_replace($regExp, '', $normPath);
     $relative = ltrim($relative, '/');
     return $relative;
 }
Ejemplo n.º 2
0
Archivo: Sys.php Proyecto: jbzoo/utils
 /**
  * Return document root
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @return string
  */
 public static function getDocRoot()
 {
     $result = '.';
     $root = Arr::key('DOCUMENT_ROOT', $_SERVER, true);
     if ($root) {
         $result = $root;
     }
     $result = FS::clean($result);
     $result = FS::real($result);
     if (!$result) {
         $result = FS::real('.');
         // @codeCoverageIgnore
     }
     return $result;
 }