/** * Store a learning material file and return the relativePath * @param File $file * @param boolean $preserveOriginalFile * @return string $relativePath */ public function storeLearningMaterialFile(File $file, $preserveOriginalFile = true) { $relativePath = $this->getLearningMaterialFilePath($file); $fullPath = $this->getPath($relativePath); $dir = dirname($fullPath); $this->fileSystem->mkdir($dir); if ($preserveOriginalFile) { $this->fileSystem->copy($file->getPathname(), $fullPath, false); } else { if (!$this->fileSystem->exists($fullPath)) { $this->fileSystem->rename($file->getPathname(), $fullPath); } } return $relativePath; }
public static function deepCopy($src, $dest, array $patternMatch = null) { $fileSystem = new FileSystem(); if (!$fileSystem->exists($src)) { return; } if (!$fileSystem->exists($dest)) { $fileSystem->mkdir($dest, 0777); } $match = false; if (!empty($patternMatch) && count($patternMatch) == 2) { $match = true; } $fileCount = 0; foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($src, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $path) { if ($match && $patternMatch[0]->{$patternMatch}[1]($path->getPathname())) { continue; } $relativeFile = str_replace($src, '', $path->getPathname()); $destFile = $dest . $relativeFile; if ($path->isDir()) { if (!$fileSystem->exists($destFile)) { $fileSystem->mkdir($destFile, 0777); } } else { if (strpos($path->getFilename(), ".") === 0) { continue; } $fileSystem->copy($path->getPathname(), $destFile, true); $fileCount++; } } return $fileCount; }
/** * @param $origin file path * @param $destinationDirectory destination directory path * @return StandardResponseInterface */ public function copyFile($origin, $destinationDirectory) { $fullPath = $this->getRealPath($origin); $fullDestinationPath = $this->getRealPath($destinationDirectory); $this->fs->copy($fullPath, $fullDestinationPath . '/' . basename($fullPath)); return new StandardResponse(); }
/** * Copy a file, takes care of symbolic links * * @param PhingFile $src Source path and name file to copy. * @param PhingFile $dest Destination path and name of new file. * * @return void * @throws Exception if file cannot be copied. */ function copy(PhingFile $src, PhingFile $dest) { global $php_errormsg; if (!$src->isLink()) { return parent::copy($src, $dest); } $srcPath = $src->getAbsolutePath(); $destPath = $dest->getAbsolutePath(); $linkTarget = $src->getLinkTarget(); if (false === @symlink($linkTarget, $destPath)) { $msg = "FileSystem::copy() FAILED. Cannot create symlink from {$destPath} to {$linkTarget}."; throw new Exception($msg); } }
/** * Installs .htaccess and web.config to the given path * * @param string $path */ public static function protectDirectory($path) { $templatesLocation = __DIR__ . "/../Initialization"; FileSystem::copy("{$templatesLocation}/.htaccess.tpl", "{$path}/.htaccess"); FileSystem::copy("{$templatesLocation}/web.tpl.config", "{$path}/web.config"); }