Exemplo n.º 1
0
 public function testBuildURL()
 {
     $urlParts = array('path' => '/path/to/myFile.ext');
     $this->assertEquals('file:///path/to/myFile.ext', AdvancedPathLib::buildURL($urlParts));
     $urlParts['scheme'] = 'file';
     $this->assertEquals('file:///path/to/myFile.ext', AdvancedPathLib::buildURL($urlParts));
     $urlParts['user'] = '******';
     $urlParts['pass'] = '******';
     $this->assertEquals('file://*****:*****@localhost/path/to/myFile.ext', AdvancedPathLib::buildURL($urlParts));
     $urlParts = array('scheme' => 'file', 'host' => 'localhost', 'path' => '/path/to/myFile.ext');
     $this->assertEquals('file://localhost/path/to/myFile.ext', AdvancedPathLib::buildURL($urlParts));
     $urlParts['user'] = '******';
     $urlParts['pass'] = '******';
     $this->assertEquals('file://*****:*****@localhost/path/to/myFile.ext', AdvancedPathLib::buildURL($urlParts));
     //special behaviour on Windows (adding a leading slash to the path)
     $urlParts = array('scheme' => 'file', 'host' => 'localhost', 'path' => 'D:/path/to/myFile.ext');
     $this->assertEquals('file://localhost/D:/path/to/myFile.ext', AdvancedPathLib::buildURL($urlParts, AdvancedPathLib::OS_WINDOWS));
     $urlParts = array('scheme' => 'ftp', 'host' => 'dummyhost', 'path' => '/path/to/myFile #1.ext', 'port' => '210');
     $this->assertEquals('ftp://*****:*****@dummyhost:210/path/to/myFile #1.ext', AdvancedPathLib::buildURL($urlParts));
     $urlParts = array('scheme' => 'http', 'host' => 'dummyhost', 'path' => '/path/to/myPage.html', 'query' => 'this=1&that=2');
     $this->assertEquals('http://dummyhost/path/to/myPage.html?this=1&that=2', AdvancedPathLib::buildURL($urlParts));
     $urlParts['user'] = '******';
     $urlParts['pass'] = '******';
     $urlParts['fragment'] = 'myfragment';
     $this->assertEquals('http://*****:*****@dummyhost/path/to/myPage.html?this=1&that=2#myfragment', AdvancedPathLib::buildURL($urlParts));
 }
Exemplo n.º 2
0
 /**
  * @param IFile $file
  * @param bool $foldersFirst
  * @return int A negative value if the current file should be placed before $file,
  * zero (0) if they are equals, a positive value otherwise.
  */
 public function compareTo(IFile $file, $foldersFirst = false)
 {
     if ($foldersFirst) {
         $isDirThis = $this->isDirectory();
         $isDirFile = $file->isDirectory();
         if ($isDirThis && !$isDirFile) {
             return -1;
         } else {
             if ($isDirFile && !$isDirThis) {
                 return 1;
             }
         }
     }
     $urlParts = $file->getURLComponents();
     $urlParts['path'] = $file->getPathFromRoot();
     //needed to resolve the path (if relative)
     $absolutePathFile = AdvancedPathLib::buildURL($urlParts);
     $urlParts = $this->getURLComponents();
     $urlParts['path'] = $this->getPathFromRoot();
     //needed to resolve the path (if relative)
     $absolutePathThis = AdvancedPathLib::buildURL($urlParts);
     return utf8_strcasecmp($absolutePathThis, $absolutePathFile);
 }
Exemplo n.º 3
0
 /**
  * @return IFile
  */
 public function getRoot()
 {
     $urlParts = $this->getURLComponents();
     $urlParts['path'] = '/';
     return FSI::getFile(AdvancedPathLib::buildURL($urlParts));
 }
Exemplo n.º 4
0
 /**
  *
  * @param FTPFile $baseFile A file of the same server/connection
  * @param string $linkName The name of the link ("myLink -> /my/path/to/target")
  * @return array(0 => link_name, 1 => full_path_of_target)
  */
 protected static function parseLinkName(FTPFile $baseFile, $linkName)
 {
     if (preg_match('/^(.+) -> (.+)$/', $linkName, $matches)) {
         $urlParts = $baseFile->getURLComponents();
         $urlParts['path'] = $matches[2];
         return array($matches[1], AdvancedPathLib::buildURL($urlParts, AdvancedPathLib::OS_UNIX));
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * @return bool TRUE if the file has been successfully renamed.
  * @throws EyeIOException
  */
 public function renameTo($newName)
 {
     if (!$this->exists()) {
         throw new EyeFileNotFoundException($this->path . ' does not exist.');
     }
     if (!$newName) {
         return true;
     }
     $urlParts = AdvancedPathLib::parse_url($this->path);
     $urlParts['path'] = AdvancedPathLib::unifyPath(dirname($urlParts['path']) . '/' . $newName);
     $newPath = AdvancedPathLib::buildURL($urlParts);
     if ($this->exists()) {
         $path = AdvancedPathLib::getPhpLocalHackPath($this->path);
         $newPath = AdvancedPathLib::getPhpLocalHackPath($newPath);
         try {
             if (rename($path, $newPath)) {
                 $this->path = $newPath;
                 return true;
             }
             throw new EyeIOException('Unable to rename file ' . $this->path . '.');
         } catch (EyeErrorException $e) {
             throw new EyeIOException('Unable to rename file ' . $this->path . '.', 0, $e);
         }
     } else {
         $this->path = $newPath;
         return true;
     }
 }