/** * Get a File from a hash * @param [string] $relativePath * @return File */ public function getFile($relativePath) { if ($this->fileSystem->exists($this->getPath($relativePath))) { return new File($this->getPath($relativePath)); } return false; }
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 deleteExistingFile($fileIdWithoutExtension, $fileFullPath) { $fs = new FileSystem(); if ($fs->exists($fileFullPath . $fileIdWithoutExtension . '.docx')) { unlink($fileFullPath . $fileIdWithoutExtension . '.docx'); } elseif ($fs->exists($fileFullPath . $fileIdWithoutExtension . '.doc')) { unlink($fileFullPath . $fileIdWithoutExtension . '.doc'); } elseif ($fs->exists($fileFullPath . $fileIdWithoutExtension . '.pdf')) { unlink($fileFullPath . $fileIdWithoutExtension . '.pdf'); } return; }
public function load() { if ($this->file === NULL) { throw new \Exception(__CLASS__ . ": Missing required property (configFile)"); } if ($this->fs->exists($this->file)) { $items = $this->decodeDocument(file_get_contents($this->file)); $this->instances = array(); foreach ($items as $key => $item) { $this->instances[$key] = $this->decodeItem($item); } } else { $this->instances = array(); } }
/** * Serve a file by forcing the download * * @Route("/download-task/{id}", name="download_file_task", requirements={"filename": ".+"}) */ public function downloadFileTaskAction($id) { /** * $basePath can be either exposed (typically inside web/) * or "internal" */ $repository = $this->getDoctrine()->getRepository('TrackersBundle:Project_Task_Attachments'); $files = $repository->find($id); if (empty($files)) { throw $this->createNotFoundException(); } $filename = $files->getFileurl(); $basePath = $this->get('kernel')->getRootDir() . '/../web/upload'; $filePath = $basePath . '/' . $filename; $name_array = explode('/', $filename); $filename = $name_array[sizeof($name_array) - 1]; // check if file exists $fs = new FileSystem(); if (!$fs->exists($filePath)) { throw $this->createNotFoundException(); } header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filePath)); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filePath)); readfile($filePath); exit; }
private function checkRepositoryExists($path) { $fs = new FileSystem(); if (!$fs->exists($path)) { throw new PayrollRepositoryDoesNotExist(sprintf('Path %s does not exist.', $path)); } }
public function testSavingNamespacedConfig() { $group = md5(time() . uniqid()); $namespace = md5(time() . uniqid()); $item = 'this.is.the.test.key'; $value = $group; $this->saver->save($item, $value, 'testing', $group, $namespace); $path = DIR_APPLICATION . "/config/generated_overrides/{$namespace}/{$group}.php"; $exists = $this->files->exists($path); $array = array(); if ($exists) { $array = $this->files->getRequire($path); $this->files->delete($path); } $this->assertTrue($exists, 'Failed to save file'); $this->assertEquals($value, array_get($array, $item), 'Failed to save correct value.'); }
/** * 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; }
/** * Loads app config from environment source code into $this->config */ private function loadConfig() { // Look for .director.yml $fs = new FileSystem(); if ($fs->exists($this->getSourcePath() . '/.director.yml')) { $this->config = Yaml::parse(file_get_contents($this->getSourcePath() . '/.director.yml')); } else { $this->config = NULL; } }
public function frontendAction(Request $request, $path) { if (strpos($path, 'assets/') === 0) { $assetPath = $this->get('kernel')->getRootDir() . '/../web/' . $path; $fs = new FileSystem(); if (!$fs->exists($assetPath)) { throw $this->createNotFoundException(); } else { $response = new BinaryFileResponse($assetPath); if ((new File($assetPath))->getExtension() === 'html') { $response->headers->set('Content-Type', 'text/html'); } return $response; } } return $this->render('AppBundle:Default:index.html.twig'); }
/** * Serve a file by forcing the download * * @Route("/download/{filename}", name="download_file", requirements={"filename": ".+"}) */ public function downloadFileAction($filename) { /** * $basePath can be either exposed (typically inside web/) * or "internal" */ $basePath = $this->container->getParameter('kernel.root_dir') . '/Resources/uploads'; $filePath = $basePath . '/' . $filename; // check if file exists $fs = new FileSystem(); if (!$fs->exists($filePath)) { throw $this->createNotFoundException(); } // prepare BinaryFileResponse $response = new BinaryFileResponse($filePath); $response->trustXSendfileTypeHeader(); $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename)); return $response; }
/** * {@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 restoreMergedBackupFromRemoteHost($dataItemId, $hostUrl, $sessionId, $fileName) { // Restore session with session id global $SynchSessionController, $SynchServerController; $session = $SynchSessionController->createSessionAsCurrent(true, array('id' => $sessionId)); $session->servers = new stdClass(); $session->servers->{$SynchServerController->getServerId()} = new stdClass(); $session->servers->{$SynchServerController->getRemoteServerId()} = new stdClass(); $this->moveBackupFromQueueToSession($session, $fileName, 0); $files = array(); $files['merged'] = $fileName; $sessionBackupPath = $this->createSessionBackupPath($session); $path = $sessionBackupPath . '/' . $fileName; if (!FileSystem::exists($path, 'f')) { return false; } $remoteServerId = $SynchServerController->getRemoteServerId(); $this->setSessionHasChangesByServerId(true, $remoteServerId, $session); $this->setSessionItemExistsByServerId(array($dataItemId), $SynchServerController->getServerId(), $session); return $this->restoreMergedBackup($dataItemId, $files, $session); }
/** * Get if a learning material file path is valid * @param LearningMaterialInterface $lm * * @return boolean */ public function checkLearningMaterialFilePath(LearningMaterialInterface $lm) { $relativePath = $lm->getRelativePath(); $fullPath = $this->getPath($relativePath); return $this->fileSystem->exists($fullPath); }
protected function checkInstall() { $fs = new FileSystem(); $kernelDir = $this->container->getParameter('kernel.root_dir'); $parameterFile = $kernelDir . 'config/parameters.yml'; if ($fs->exists($parameterFile)) { exit('This Fork has already been installed. To reinstall, delete parameters.yml from the ' . $kernelDir . 'config/ directory. To log in, <a href="/private">click here</a>.'); } }
private function downloadFileAction($os) { /** * $basePath can be either exposed (typically inside web/) * or "internal". */ $basePath = $this->container->getParameter('kernel.root_dir') . '/Resources/my_custom_folder'; $dir = $this->get('kernel')->getRootDir() . "/../../Dropbox/quota/updates"; $handle = fopen("{$dir}/updates.txt", "r"); if ($handle) { $version = "0.0.0"; $link = ""; while (($line = fgets($handle)) !== false) { $s = explode('#', $line); if (version_compare($s[0], $version) == 1) { $link = $s[1]; $version = $s[0]; } } fclose($handle); } else { // error opening the file. } $a = explode("/", $link); $filename = trim(end($a)); $filePath = "{$dir}/{$filename}"; // check if file exists $fs = new FileSystem(); if (!$fs->exists($filePath)) { throw $this->createNotFoundException(); } $filename = "Quota_Setup_{$os}.exe"; // prepare BinaryFileResponse $response = new BinaryFileResponse($filePath); $response->trustXSendfileTypeHeader(); $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename)); return $response; }
/** * Loads app config from environment source code into $this->config. */ private function loadConfig() { // Look for .terra.yml $fs = new FileSystem(); if ($fs->exists($this->getSourcePath() . '/.terra.yml')) { // Process any string replacements. $environment_config_string = file_get_contents($this->getSourcePath() . '/.terra.yml'); $this->config = Yaml::parse(strtr($environment_config_string, array('{{alias}}' => "@{$this->app->name}.{$this->environment->name}"))); } else { $this->config = null; } }
/** * Serve a file by forcing the download * * @Route("/download/{filename}", name="download_file", requirements={"filename": ".+"}) */ public function downloadFileAction($filename) { /** * $basePath can be either exposed (typically inside web/) * or "internal" */ $basePath = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/documents'; $filePath = $basePath . '/' . $filename; // check if file exists $fs = new FileSystem(); if (!$fs->exists($filePath)) { throw $this->createNotFoundException(); } $response = new BinaryFileResponse($filePath); $d = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename); $response->headers->set('Content-Disposition', $d); return $response; }