/** * Get directory walker. * * @param string $path * @param callable $callable * * @return static */ public function directory($path, callable $callable = null) { $directory_path = $this->makePath($path); $this->outbox->createDir($directory_path); $context = clone $this->context; $context->directory = $directory_path; $sub = new static($this->outbox, $this->stubbox, $context); if ($callable) { call_user_func($callable, $sub); } return $sub; }
public function create(User $_user, string $extension, string $mime_type, string $original_name, string $temp_location, bool $is_image) { $query = "INSERT INTO `file` (user_id, extension, mime_type, md5, original_name, date_added, is_image)\n\t\t\t\t\t VALUES (:u, :e, :mt, :m, :o, :d, :i)"; $this->_pdo->perform($query, ["u" => $this->user_id = $_user->getId(), "e" => $this->extension = $extension, "mt" => $this->mime_type = $mime_type, "m" => $this->md5 = md5_file($temp_location), "o" => $this->original_name = $original_name, "d" => $this->date_added = Utility::getDateTimeForMySQLDateTime(), "i" => $this->is_image = $is_image]); $stream = fopen($temp_location, "r+"); if (!$this->_filesystem->has($this->getDirMain())) { $this->_filesystem->createDir($this->getDirMain()); } if (!$this->_filesystem->has($this->getDirSub())) { $this->_filesystem->createDir($this->getDirSub()); } $this->_filesystem->writeStream($this->getPath(), $stream, ["visibility" => AdapterInterface::VISIBILITY_PUBLIC]); fclose($stream); }
/** * {@inheritdoc} */ public function push(BackupInterface $backup) { $backupDirectory = $backup->getName(); if (!$this->flysystem->has($backupDirectory) && !$this->flysystem->createDir($backupDirectory)) { throw new DestinationException(sprintf('Unable to create backup directory "%s" in flysystem destination.', $backupDirectory)); } $removedBackupFiles = $this->getFiles($backupDirectory); /** * @var FileInterface $backupFile */ foreach ($backup->getFiles() as $backupFile) { if (isset($removedBackupFiles[$backupFile->getRelativePath()])) { unset($removedBackupFiles[$backupFile->getRelativePath()]); } $path = $backupDirectory . '/' . $backupFile->getRelativePath(); try { if ($this->flysystem->has($path)) { if ($backupFile->getModifiedAt() > new \DateTime('@' . $this->flysystem->getTimestamp($path))) { $resource = fopen($backupFile->getPath(), 'r'); $this->flysystem->updateStream($path, $resource); fclose($resource); } } else { $resource = fopen($backupFile->getPath(), 'r'); $this->flysystem->putStream($path, $resource); fclose($resource); } } catch (\Exception $e) { throw new DestinationException(sprintf('Unable to backup file "%s" to flysystem destination.', $backupFile->getPath()), 0, $e); } } /** * @var FileInterface $removedBackupFile */ foreach ($removedBackupFiles as $removedBackupFile) { $path = $backupDirectory . '/' . $removedBackupFile->getRelativePath(); try { $this->flysystem->delete($path); } catch (\Exception $e) { throw new DestinationException(sprintf('Unable to cleanup backup destination "%s" after backup process, file "%s" could not be removed.', $backupDirectory, $path), 0, $e); } } $this->removeEmptyDirectories($backupDirectory); if (is_array($this->backups)) { $this->backups[$backup->getName()] = $backup; } }
/** * {@inheritdoc} */ public function fetch(FilesystemInterface $filesystem, $fileKey) { if (!$filesystem->has($fileKey)) { throw new \LogicException(sprintf('The file "%s" is not present on the filesystem.', $fileKey)); } if (false === ($stream = $filesystem->readStream($fileKey))) { throw new FileTransferException(sprintf('Unable to fetch the file "%s" from the filesystem.', $fileKey)); } if (!$this->tmpFilesystem->has(dirname($fileKey))) { $this->tmpFilesystem->createDir(dirname($fileKey)); } $localPathname = $this->tmpFilesystem->getAdapter()->getPathPrefix() . $fileKey; if (false === file_put_contents($localPathname, $stream)) { throw new FileTransferException(sprintf('Unable to fetch the file "%s" from the filesystem.', $fileKey)); } return new \SplFileInfo($localPathname); }
private function touchDir(FilesystemInterface $fs, string $entityId, string $collectionUID, string $imageId) : string { $resultPath = sprintf('%s/%s/%s', $entityId, $collectionUID, $imageId); if (!$fs->has($resultPath)) { $fs->createDir($resultPath); } return $resultPath; }
/** * Create dir and return created dir path or false on failed * * @param string $path parent dir path * @param string $name new directory name * @return string|bool **/ protected function _mkdir($path, $name) { $path = $this->_joinPath($path, $name); if ($this->fs->createDir($path)) { return $path; } return false; }
/** * Creates a folder, within a parent folder. * If no parent folder is given, a root level folder will be created * * @param string $newFolderName * @param string $parentFolderIdentifier * @param bool $recursive * @return string the Identifier of the new folder */ public function createFolder($newFolderName, $parentFolderIdentifier = '', $recursive = false) { $parentFolderIdentifier = $this->canonicalizeAndCheckFolderIdentifier($parentFolderIdentifier); $newFolderName = trim($newFolderName, '/'); $newFolderName = $this->sanitizeFileName($newFolderName); $newIdentifier = $parentFolderIdentifier . $newFolderName . '/'; $this->filesystem->createDir($newIdentifier); return $newIdentifier; }
/** * Create a directory. * * @param string $dirname * @param string $visibility * @throws IoWriteException */ public function createDir($dirname, $visibility = self::VISIBILITY_DEFAULT) { try { $this->fs->createDir($dirname, $this->prepareConfig($visibility)); } catch (Error $ex) { throw new IoWriteException("Directory {$dirname} could not be created.", $ex); } catch (Exception $ex) { throw new IoWriteException("Directory {$dirname} could not be created.", $ex); } }
/** * Use flysystem to save the file in the desired location. * * @param \Onema\ClassyFile\Event\GetClassEvent $event */ public function onGetClassGenerateFile(GetClassEvent $event) { $statement = $event->getStatements(); $fileLocation = $event->getFileLocation(); $code = $event->getCode(); $name = $statement->name; if (!$this->filesystem->has($fileLocation)) { // dir doesn't exist, make it $this->filesystem->createDir($fileLocation); } $location = sprintf('%s/%s.php', $fileLocation, $name); $this->filesystem->put($location, $code); $adapter = $this->filesystem->getAdapter(); if ($adapter instanceof AbstractAdapter) { $prefix = $adapter->getPathPrefix(); $location = Util::normalizePath($location); $event->setFileLocation(sprintf('%s%s', $prefix, $location)); } }
/** * {@inheritdoc} */ public function fetch(FilesystemInterface $filesystem, $fileKey, array $options = []) { if (!$filesystem->has($fileKey)) { throw new \LogicException(sprintf('The file "%s" is not present on the filesystem.', $fileKey)); } if (false === ($stream = $filesystem->readStream($fileKey))) { throw new FileTransferException(sprintf('Unable to fetch the file "%s" from the filesystem.', $fileKey)); } if (!$this->tmpFilesystem->has(dirname($fileKey))) { $this->tmpFilesystem->createDir(dirname($fileKey)); } // TODO: we should not get the path prefix like that // TODO: it should be injected in the constructor $localPathname = $this->tmpFilesystem->getAdapter()->getPathPrefix() . $fileKey; if (false === file_put_contents($localPathname, $stream)) { throw new FileTransferException(sprintf('Unable to fetch the file "%s" from the filesystem.', $fileKey)); } return new \SplFileInfo($localPathname); }
/** * @override * @inheritDoc */ public function createDir($dirname, $visibility = self::VISIBILITY_DEFAULT) { try { if ($this->exists($dirname)) { $this->removeDir($dirname); } $this->fs->createDir($dirname, $this->prepareConfig($visibility)); return; } catch (Error $ex) { } catch (Exception $ex) { } throw new WriteException("Directory {$dirname} could not be created.", $ex); }
/** * Create a file or folder. * * @param string $path * @param string|null $contents */ protected function create($path, $contents = null) { // If the file already exists, quit $path = $this->formatPath($path); if ($this->filesystem->has($path)) { return; } // Create the file or folder if ($contents) { $this->filesystem->put($path, $contents); } else { $this->filesystem->createDir($path); } $this->output->writeln('<info>✓</info> Created <comment>' . $path . '</comment>'); }
/** * Create a directory. * * @param string $path * @return bool */ public function makeDirectory($path) { return $this->driver->createDir($path); }
/** * @param string $directory * @throws SaveResourceErrorException * @see \Staticus\Resources\Middlewares\SaveResourceMiddlewareAbstract::createDirectory */ protected function createDirectory($directory) { if (!$this->filesystem->createDir($directory)) { throw new SaveResourceErrorException('Can\'t create a directory: ' . $directory); } }
/** * Create dir and return created dir path or false on failed * * @param string $path parent dir path * @param string $name new directory name * @return string|bool **/ protected function _mkdir($path, $name) { $path = $this->_joinPath($path, $name); return $this->_resultPath($this->fs->createDir($path), $path); }
/** * @param string $path * @param FilesystemInterface $remote * @param AdapterInterface $remoteAdapter */ private function mirrorDirectory($path, FilesystemInterface $remote, AdapterInterface $remoteAdapter) { if (!$remote->has($path) && !$remote->createDir($path)) { throw $this->createRuntimeException('Directory', $path, 'created', $remoteAdapter); } }
/** * @inheritdoc */ public function createDir($dirname) { return $this->filesystem->createDir($dirname); }
/** * Create a directory. * * @param string $dirname The name of the new directory. * @param array $config An optional configuration array. * * @return bool True on success, false on failure. */ public function createDir($dirname, array $config = []) { return $this->fileSystem->createDir($dirname, $config); }