/** * @return string The path of the file's parent directory */ public function getParentPath() { if (preg_match('/^[a-z]{1}:\\/?$/i', AdvancedPathLib::getPhpLocalHackPath($this->path))) { return $this->getAbsolutePath(); //if the path is the root of a Windows drive, return itself } $urlParts = $this->getURLComponents(); $urlParts['path'] = AdvancedPathLib::dirname($urlParts['path']); return AdvancedPathLib::buildUrl($urlParts); }
/** * @return bool TRUE if the file has been successfully renamed, FALSE otherwise */ public function renameTo($newName) { if ($this->realFile === null) { throw new EyeUnsupportedOperationException(__METHOD__ . ' on ' . $this->path); } if (!$this->exists()) { throw new EyeFileNotFoundException($this->path . ' does not exist.'); } if ($this->isRoot()) { throw new EyeUnsupportedOperationException('Cannot rename the root folder.'); } $oldName = $this->getName(); $oldPath = $this->getAbsolutePath(); $this->getParentFile()->checkWritePermission(); $newFile = FSI::getFile(dirname($oldPath) . '/' . $newName); $newFile->checkWritePermission(); try { if ($this->realFile->renameTo($newName)) { //change internal name in URL $urlParts = $this->getURLComponents(); $dirname = dirname($urlParts['path']); $urlParts['path'] = $dirname . '/' . $newName; $this->path = AdvancedPathLib::buildUrl($urlParts); //Update URL components cache $this->urlParts = $urlParts; //update metadata MetaManager::getInstance()->updateMeta($this, array('oldName' => $oldName)); $oldFile = FSI::getFile($oldPath); //notify listeners $this->fireEvent('fileRenamed', new FileEvent($oldFile, $this)); return true; } } catch (EyeFileNotFoundException $e) { throw new EyeFileNotFoundException($this->path . ' does not exist.', 0, $e); } catch (EyeException $e) { throw new EyeIOException('Unable to rename file ' . $this->path . '.', 0, $e); } throw new EyeIOException('Unable to rename file ' . $this->path . '.'); }
/** * Returns an IVirtualFile object corresponding to the given virtual $path. * * @param string $path The path/URL of the file. * @param array $params Optionnal addionnal parameters passed to the file class constructor. * @return IVirtualFile The file object if the FOF was able to create it or null otherwise. * @throws EyeException If an error occured during the creation of the file object. */ public function getFile($path, $params = null) { $urlParts = AdvancedPathLib::parse_url($path, AdvancedPathLib::OS_UNIX); try { $xmlConf = FSI::getConfiguration($urlParts['scheme'] . '.scheme'); } catch (EyeFileNotFoundException $e) { throw new EyeMissingConfigurationException('Missing handler configuration file for scheme ' . $urlParts['scheme'] . '://.', 0, $e); } $handlerClassName = (string) $xmlConf->handlerClassName[0]; if (!class_exists($handlerClassName)) { throw new EyeClassNotFoundException('Unable to find ' . $handlerClassName); } //autocomplete path if possible (home://myFolder => home://~currentuser/myFolder) $path = call_user_func_array(array($handlerClassName, 'autocompletePath'), array($path)); //check for mounted file first $realFile = null; if ($xmlConf->mountpointsManager->getName() != '') { $realFile = MountedFileLocator::getRealFile($path, null, $params); if ($realFile !== null) { $params['realFile'] = $realFile; } } //if no mounted path has been found, get the real file object from its locator if ($realFile === null) { $locatorClassFilename = (string) $xmlConf->locatorClassName[0]; if ($locatorClassFilename == '') { throw new EyeMissingConfigurationException('No VirtualFileLocator class has been specified in the configuration file.'); } if (!is_file(SERVICE_FILESYSTEM_VIRTUALFILEFACTORY_LOCATORS_PATH . '/' . $locatorClassFilename . '.php')) { throw new EyeFileNotFoundException('Unable to find specified VirtualFileLocator class file: ' . $locatorClassFilename . '.php.'); } require_once SERVICE_FILESYSTEM_VIRTUALFILEFACTORY_LOCATORS_PATH . '/' . $locatorClassFilename . '.php'; if (!class_exists($locatorClassFilename)) { throw new EyeClassNotFoundException('Unable to find class ' . $locatorClassFilename); } $params['realFile'] = call_user_func_array(array($locatorClassFilename, 'getRealFile'), array($path, $xmlConf->parameters, $params)); } return new $handlerClassName(AdvancedPathLib::buildUrl($urlParts), $params); }