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; }
/** * Write a file * * @param string $path The directory to put the file in (in the current destination) * @param string $content The file content * @param string $filename The file name * @param string $extension The file extension */ public function write($path, $content, $extension = 'html', $filename = 'index') { $directory = sprintf('%s/%s', $this->destination, trim($path, '/')); $file = sprintf('%s.%s', $filename, $extension); if (!$this->files->exists($directory)) { $this->files->mkdir($directory); } $this->files->dumpFile(sprintf('%s/%s', $directory, $file), $content); }
public function __construct(SymfonyFileSystem $fs, $kernelRootDirectory) { $tmpPath = realpath($kernelRootDirectory . '/../var/tmp'); $this->fileSystem = $fs; $this->temporaryFileStorePath = $tmpPath . '/uploads'; if (!$this->fileSystem->exists($this->temporaryFileStorePath)) { $this->fileSystem->mkdir($this->temporaryFileStorePath); } $this->fileSystem = $fs; }
/** * @param $path * @param $directoryName * @return StandardResponseInterface */ public function createDirectory($path, $directoryName) { if (!$this->isNameValid($directoryName)) { return new StandardResponse(false, 'Name not valid. Only a-z, A-Z, 0-9, - and _ are authorized'); } $realPath = $this->getRealPath($path); try { $this->fs->mkdir($realPath . '/' . $directoryName); return new StandardResponse(); } catch (IOException $e) { return new StandardResponse(false, 'Unable to create directory'); } }
/** * Writes the class to a file. */ public function write() { try { $dir = $this->path->isDir() ? $this->path->getPathname() : $this->path->getPath(); $path = $dir . '/' . $this->baseClass->getClassName() . $this->baseClass->getExtension(); if (!file_exists($dir)) { $this->fileSystem->mkdir($dir, 0777, true); } //if (!file_exists($path)) { file_put_contents($path, $this->baseClass->generate()); //} } catch (IOExceptionInterface $e) { } }
/** * 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 function extractTo($extractPath, $files = null) { $fs = new FileSystem(); $ds = DIRECTORY_SEPARATOR; for ($i = 0; $i < $this->numFiles; $i++) { $oldName = parent::getNameIndex($i); $newName = mb_convert_encoding($this->getNameIndex($i), 'ISO-8859-1', 'CP850,UTF-8'); //we cheat a little because we can't tell wich name the extracted part should have //so we put it a directory wich share it's name $tmpDir = $extractPath . $ds . '__claro_zip_hack_' . $oldName; parent::extractTo($tmpDir, parent::getNameIndex($i)); //now we move the content of the directory and we put the good name on it. foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tmpDir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) { if ($item->isFile()) { $fs->mkdir(dirname($extractPath . $ds . $oldName)); $fs->rename($item->getPathname(), $extractPath . $ds . $oldName); } } } //we remove our 'trash here' $iterator = new \DirectoryIterator($extractPath); foreach ($iterator as $item) { if (strpos($item->getFilename(), '_claro_zip_hack')) { $fs->rmdir($item->getRealPath(), true); } } }
/** * Get the staging directory for processed deposits. * * @param Journal $journal * * @return string */ public final function getStagingDir(Journal $journal) { $path = $this->absolutePath('staged', $journal); if (!$this->fs->exists($path)) { $this->logger->notice("Creating directory {$path}"); $this->fs->mkdir($path); } return $path; }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $serverDefinition = $container->getDefinition('secotrust.sabredav.server'); $fileSystem = new FileSystem(); foreach ($container->findTaggedServiceIds('secotrust.sabredav.plugin') as $id => $attr) { $serverDefinition->addMethodCall('addPlugin', array(new Reference($id))); switch ($id) { case 'secotrust.sabredav_lock_plugin': $definition = $container->getDefinition('secotrust.sabredav_lock_backend'); $file = $container->getParameterBag()->resolveValue($definition->getArgument(0)); $fileSystem->mkdir(dirname($file)); break; case 'secotrust.sabredav_temp_plugin': $definition = $container->getDefinition('secotrust.sabredav_temp_plugin'); $dir = $container->getParameterBag()->resolveValue($definition->getArgument(0)); $fileSystem->mkdir($dir); break; } } }
public function testNewSiteExistsEmptyDir() { $fs = new FileSystem(); $fs->mkdir($this->tmpDir); $this->assertFileExists($this->tmpDir); $operation = new NewSite($this->templatePath); $operation->newSite($this->tmpDir, 'blank'); $this->assertFileExists($this->tmpDir . '/config.yml'); $this->assertFileExists($this->tmpDir . '/composer.json'); $this->assertFileExists($this->tmpDir . '/index.html'); $this->assertFileExists($this->tmpDir . '/_posts'); $this->assertFileExists($this->tmpDir . '/_layouts'); }
public function testNewSiteExistsEmptyDir() { $fs = new FileSystem(); $fs->mkdir($this->tmpDir); $this->assertFileExists($this->tmpDir); $app = new Application(); $app->add(new NewSiteCommand()); $command = $app->find('new:site'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'path' => $this->tmpDir]); $output = $commandTester->getDisplay(); $this->assertRegExp('/New site created/', $output); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $this->io = new SymfonyStyle($input, $output); $fs = new FileSystem(); $this->io->title('RCHJWTUserBundle - Generate SSL Keys'); $rootDir = $this->getContainer()->getParameter('kernel.root_dir'); $passphrase = $this->getContainer()->getParameter('rch_jwt_user.passphrase'); $path = $rootDir . '/jwt'; /* Symfony3 directory structure */ if (is_writable($rootDir . '/../var')) { $path = $rootDir . '/../var/jwt'; } if (!$fs->exists($path)) { $fs->mkdir($path); } $this->generatePrivateKey($path, $passphrase, $this->io); $this->generatePublicKey($path, $passphrase, $this->io); $outputMessage = 'RSA keys successfully generated'; if ($passphrase) { $outputMessage .= $this->io->getFormatter()->format(sprintf(' with passphrase <comment>%s</comment></info>', $passphrase)); } $this->io->success($outputMessage); }
public function getTemplateData(File $file, $refresh = false) { //from cache if (!$refresh) { return $this->importData; } $archive = new \ZipArchive(); $fileName = $file->getBasename('.zip'); $extractPath = $this->templateDirectory . DIRECTORY_SEPARATOR . $fileName; if ($archive->open($file->getPathname())) { $fs = new FileSystem(); $fs->mkdir($extractPath); if (!$archive->extractTo($extractPath)) { throw new \Exception("The workspace archive couldn't be extracted"); } $archive->close(); $resolver = new Resolver($extractPath); $this->importData = $resolver->resolve(); return $this->importData; } throw new \Exception("The workspace archive couldn't be opened"); }
/** * Creates the directory to extract compressed files * * Should be removed after completion * * @param string $month * @return void * @author Fran Iglesias */ private function createDirectory($month) { $fs = new FileSystem(); $fs->mkdir($this->basePath . '/' . $month); return new SpecificDirectory($this->basePath . '/' . $month); }
protected function execute(InputInterface $input, OutputInterface $output) { $type = $input->getArgument('type'); if ($type == 'zip' || $type == 'ZIP') { $output->writeln('<info>Creating a ZIP package...</info>'); $output->writeln('<info>Archiving master branch...</info>'); $archiver = new Process('git archive --format zip --output ' . self::OPERATION_DIRECTORY . self::ZIP_FILE_NAME . ' master '); $archiver->run(); if (!$archiver->isSuccessful()) { $output->writeln('<info>Could not archive master branch.</info>'); $output->writeln('<error>' . $archiver->getErrorOutput() . '</error>'); return; } else { $output->writeln('<info>Done!</info>'); $output->writeln('<info>The archive is at: ' . self::OPERATION_DIRECTORY . self::ZIP_FILE_NAME); } } if ($type == 'deb' || $type == 'DEB') { $output->writeln('<info>Creating a Debian package...</info>'); $filesystem = new FileSystem(); try { $filesystem->mkdir(self::REPO_DIRECTORY); $filesystem->mkdir(self::OUTPUT_DIRECTORY); } catch (IOExceptionInterface $error) { echo "An error occurred while creating your directory at " . $error->getPath(); } $output->writeln('<info>Archiving master branch...</info>'); $archiver = new Process('git archive master | tar -x -C ' . self::REPO_DIRECTORY); $archiver->run(); if (!$archiver->isSuccessful()) { $output->writeln('<info>Could not archive master branch.</info>'); $output->writeln('<error>' . $archiver->getErrorOutput() . '</error>'); return; } $output->writeln('<info>Installing dependencies...</info>'); $composer = new Process('composer install'); $composer->setWorkingDirectory(self::REPO_DIRECTORY); $composer->setTimeout(3600); $composer->run(); $bower = new Process('bower install'); $bower->setWorkingDirectory(self::REPO_DIRECTORY); $bower->setTimeout(3600); $bower->run(); $dependencies = ['php5', 'php5-mysql', 'php5-mongo', 'php5-mcrypt', 'php5-memcached', 'php5-curl', 'memcached', 'mongodb']; $control = new StandardFile(); $control->setPackageName('ojs')->setProvides('ojs')->setVersion('1.5')->setDepends($dependencies)->setInstalledSize(10240)->setDescription('Open Journal Software')->setMaintainer('Utku Aydın', '*****@*****.**'); $packager = new Packager(); $packager->setControl($control); $packager->setOutputPath(self::OUTPUT_DIRECTORY); $packager->setPostInstallScript($this->getContainer()->get('kernel')->getRootDir() . '/../tools/debian/postinst'); $packager->setPostRemoveScript($this->getContainer()->get('kernel')->getRootDir() . '/../tools/debian/postrm'); $packager->addMount(self::REPO_DIRECTORY, '/opt/ojs'); $packager->run(); $command = $packager->build(self::DEB_FILE_NAME); $output->writeln('<info>Creating a DEB file...</info>'); $process = new Process($command); $process->setWorkingDirectory(self::OPERATION_DIRECTORY); $process->setTimeout(3600); $process->run(); if (!$process->isSuccessful()) { $output->writeln('<info>Could not create a DEB file.</info>'); $output->writeln('<error>' . $process->getErrorOutput() . '</error>'); } else { $output->writeln('<info>Done!</info>'); $output->writeln('<info>The package is at: ' . self::OPERATION_DIRECTORY . self::DEB_FILE_NAME); } } }
/** * Write the docker-compose.yml file. * * @return bool */ public function writeConfig() { // Create the app/environment folder $fs = new FileSystem(); try { $fs->mkdir($this->getDockerComposePath()); } catch (IOExceptionInterface $e) { return false; } // Create the environments docker-compose file. $dumper = new Dumper(); try { $fs->remove($this->getDockerComposePath() . '/docker-compose.yml'); $fs->dumpFile($this->getDockerComposePath() . '/docker-compose.yml', $dumper->dump($this->getDockerComposeArray(), 10)); return true; } catch (IOExceptionInterface $e) { return false; } }
/** * @param FormMetadata $formMetadata * @return string */ public function generate(FormMetadata $formMetadata) { $formMetadata->setCode($this->view->render('templates/class.php.twig', ['form' => $formMetadata])); $this->fileSystem->mkdir($formMetadata->classDirectory()); $this->fileSystem->dumpFile($formMetadata->classFilename(), $formMetadata->code()); }
public function addCssFile($rootDir, $theme) { $fs = new FileSystem(); $themedir = $rootDir . '/Resources/views/less/theme'; $fs->mkdir($themedir); $tempthemedir = $this->getContainer()->getParameter('claroline.param.plugin_template_theme_directory'); $fileList = array('common.less', 'theme.html.twig', 'theme.less', 'variables.less'); foreach ($fileList as $file) { copy($tempthemedir . '/' . $file, $themedir . '/' . $file); } }