本文整理汇总了PHP中FileSystem::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP FileSystem::exists方法的具体用法?PHP FileSystem::exists怎么用?PHP FileSystem::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem
的用法示例。
在下文中一共展示了FileSystem::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFile
/**
* 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;
}
示例2: deepCopy
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;
}
示例3: write
/**
* 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);
}
示例4: deleteExistingFile
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;
}
示例5: load
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();
}
}
示例6: downloadFileTaskAction
/**
* 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;
}
示例7: checkRepositoryExists
private function checkRepositoryExists($path)
{
$fs = new FileSystem();
if (!$fs->exists($path)) {
throw new PayrollRepositoryDoesNotExist(sprintf('Path %s does not exist.', $path));
}
}
示例8: testSavingNamespacedConfig
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.');
}
示例9: getStagingDir
/**
* 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;
}
示例10: loadConfig
/**
* 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;
}
}
示例11: frontendAction
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');
}
示例12: downloadFileAction
/**
* 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;
}
示例13: execute
/**
* {@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);
}
示例14: restoreMergedBackupFromRemoteHost
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);
}
示例15: checkLearningMaterialFilePath
/**
* 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);
}