Exemplo n.º 1
0
 static function compose($path1, $path2)
 {
     // si path2 es ruta estatica no hay operaciones
     if ($path2 != '' && $path2[0] == '/') {
         return $path2;
     }
     $is_static = $path1 && $path1[0] == '/';
     // las rutas se descomponen en arreglos
     $ddir1 = Paths::__split($path1);
     $ddir2 = Paths::__split($path2);
     $res = array();
     $isDir = 0;
     foreach ($ddir1 as $directory) {
         if ($directory == ".." && $isDir > 0) {
             array_pop($res);
             $isDir--;
             continue;
         }
         if ($directory != "") {
             if ($directory != "..") {
                 $isDir++;
             }
             array_push($res, $directory);
         }
     }
     foreach ($ddir2 as $directory) {
         if ($directory == ".." && $isDir > 0) {
             array_pop($res);
             $isDir--;
             continue;
         }
         if ($directory != "..") {
             $isDir++;
         }
         array_push($res, $directory);
     }
     if (count($res) == 1 && $res[0] == "") {
         return "";
     }
     $res = implode("/", $res);
     return ($is_static ? '/' : '') . $res . (is_dir($res) ? '/' : '');
 }