Example #1
0
 function testrealpath()
 {
     $drive = OS_WINDOWS ? substr(getcwd(), 0, 2) : '';
     $this->assertEquals($drive . '/a/weird/path/is', File::realpath('/a\\weird//path\\is/that/./../', '/'));
     $this->assertEquals($drive . '/a/weird/path/is/that', File::realpath('/a\\weird//path\\is/that/./../that/.', '/'));
 }
Example #2
0
 /**
  * Get path relative to another path
  *
  * @static
  * @access  public
  * @return  string
  * @param   string  $path
  * @param   string  $root
  * @param   string  $separator
  */
 function relativePath($path, $root, $separator = DIRECTORY_SEPARATOR)
 {
     $path = File::realpath($path, $separator);
     $root = File::realpath($root, $separator);
     $dirs = explode($separator, $path);
     $comp = explode($separator, $root);
     if (OS_WINDOWS) {
         if (strcasecmp($dirs[0], $comp[0])) {
             return $path;
         }
         unset($dirs[0], $comp[0]);
     }
     foreach ($comp as $i => $part) {
         if (isset($dirs[$i]) && $part == $dirs[$i]) {
             unset($dirs[$i], $comp[$i]);
         } else {
             break;
         }
     }
     return str_repeat('..' . $separator, count($comp)) . implode($separator, $dirs);
 }