本文整理汇总了PHP中League\Flysystem\FilesystemInterface::listContents方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesystemInterface::listContents方法的具体用法?PHP FilesystemInterface::listContents怎么用?PHP FilesystemInterface::listContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\FilesystemInterface
的用法示例。
在下文中一共展示了FilesystemInterface::listContents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clean
/** @inheritdoc */
public function clean($validPackages)
{
foreach (Linq::from($this->filesystem->listContents($this->vendorDir))->where(function ($v) {
return $v['type'] == 'dir';
}) as $vendor) {
if (!Linq::from($validPackages)->any(function ($v, $k) use($vendor) {
return preg_match('/^' . $vendor['basename'] . '/i', $k);
})) {
$this->notify("DELETING: " . $vendor['path'] . "\n");
$this->filesystem->deleteDir($vendor['path']);
continue;
}
foreach (Linq::from($this->filesystem->listContents($vendor['path']))->where(function ($v) {
return $v['type'] == 'dir';
}) as $package) {
if (!Linq::from($validPackages)->any(function ($v, $k) use($vendor, $package) {
return $k == $vendor['basename'] . '/' . $package['basename'];
})) {
$this->notify("DELETING: " . $package['path'] . "\n");
$this->filesystem->deleteDir($package['path']);
continue;
}
foreach (Linq::from($this->filesystem->listContents($package['path']))->where(function ($v) {
return $v['type'] == 'dir';
}) as $version) {
if (!Linq::from($validPackages[$vendor['basename'] . '/' . $package['basename']])->any(function ($v) use($version) {
return $v == $version['basename'];
})) {
$this->notify("DELETING: " . $version['path'] . "\n");
$this->filesystem->deleteDir($version['path']);
}
}
}
}
}
示例2: handle
public function handle($path)
{
$files = [];
$folders = [];
$list = $this->filesystem->listContents($path);
$ignored = ['.', '..', '.DS_Store', '.gitignore', '.htaccess'];
foreach ($list as $entry) {
if (in_array($entry['basename'], $ignored)) {
continue;
}
if (!$this->filesystem->authorized($entry['path'])) {
continue;
}
if ($entry['type'] === 'file') {
try {
$url = $this->filesystem->url($entry['path']);
} catch (\Exception $e) {
$url = $entry['path'];
}
// Ugh, for some reason the foldername for the theme is included twice. Why?
// For now we 'fix' this with an ugly hack, replacing it. :-/
// TODO: dig into Filesystem and figure out why this happens.
$pathsegments = explode('/', $entry['path']);
if (!empty($pathsegments[0])) {
$url = str_replace('/' . $pathsegments[0] . '/' . $pathsegments[0] . '/', '/' . $pathsegments[0] . '/', $url);
}
$files[$entry['path']] = ['path' => $entry['dirname'], 'filename' => $entry['basename'], 'newpath' => $entry['path'], 'relativepath' => $entry['path'], 'writable' => true, 'readable' => false, 'type' => isset($entry['extension']) ? $entry['extension'] : '', 'filesize' => Lib::formatFilesize($entry['size']), 'modified' => date("Y/m/d H:i:s", $entry['timestamp']), 'permissions' => 'public', 'url' => $url];
/* **** Extra checks for files that can be resolved via PHP urlopen functions **** */
try {
$files[$entry['path']]['permissions'] = $this->filesystem->getVisibility($entry['path']);
} catch (\Exception $e) {
// Computer says "No!"
}
$fullfilename = $this->filesystem->getAdapter()->applyPathPrefix($entry['path']);
if (is_readable($fullfilename)) {
$files[$entry['path']]['readable'] = true;
if (!empty($entry['extension']) && in_array($entry['extension'], ['gif', 'jpg', 'png', 'jpeg'])) {
$size = getimagesize($fullfilename);
$files[$entry['path']]['imagesize'] = sprintf("%s × %s", $size[0], $size[1]);
}
$files[$entry['path']]['permissions'] = util::full_permissions($fullfilename);
}
}
if ($entry['type'] == 'dir') {
$folders[$entry['path']] = ['path' => $entry['dirname'], 'foldername' => $entry['basename'], 'newpath' => $entry['path'], 'modified' => date("Y/m/d H:i:s", $entry['timestamp']), 'writable' => true];
$fullfilename = $this->filesystem->getAdapter()->applyPathPrefix($entry['path']);
/* **** Extra checks for files that can be resolved via PHP urlopen functions **** */
if (is_readable($fullfilename)) {
if (!is_writable($fullfilename)) {
$folders[$entry['path']]['writable'] = false;
}
}
}
}
ksort($files);
ksort($folders);
return [$files, $folders];
}
示例3: getComposerFiles
/**
* @return array
*/
private function getComposerFiles()
{
$files = [];
$fileList = $this->fileSystem->listContents('./', true);
foreach ($fileList as $file) {
if ($file['basename'] === self::LOCATE_FILE) {
$files[] = $file['path'];
}
}
return $files;
}
示例4: handle
public function handle($term, $extensions = 'jpg,jpeg,gif,png')
{
$extensions = explode(",", $extensions);
$allFiles = $this->filesystem->listContents('', true);
$files = array();
foreach ($allFiles as $file) {
if ($file['type'] == 'file' && ($term == '*' || strpos($file['path'], $term) !== false) && in_array($file['extension'], $extensions)) {
$files[] = $file['path'];
}
}
return $files;
}
示例5: handle
/**
* {@inheritdoc}
*/
public function handle($config, CertificateResponse $response)
{
$remoteAdapter = $this->createAdapter($config);
$remote = new Filesystem($remoteAdapter);
$files = $this->master->listContents('.', true);
foreach ($files as $file) {
if (0 === strpos($file['basename'], '.')) {
continue;
}
$this->mirror($file['type'], $file['path'], $remote, $remoteAdapter);
}
}
示例6: listFilesByContainerName
/**
* @param string $containerName
*
* @return array
*/
public function listFilesByContainerName($containerName)
{
$files = [];
foreach ($this->filesystem->listContents($containerName, true) as $file) {
$file['mapped_path'] = sprintf('%s/%s', $this->baseUrl, $file['path']);
if (array_key_exists('size', $file)) {
$file['size_human'] = FileSize::convertToHumanReadable($file['size']);
}
$files[] = $file;
}
return $files;
}
示例7: yieldFilesInPath
/**
* Recursively yield files that meet the specification
*
* @param SpecificationInterface $specification
* @param string $path
* @return Generator
*/
private function yieldFilesInPath(SpecificationInterface $specification, $path)
{
$listContents = $this->filesystem->listContents($path);
foreach ($listContents as $location) {
if ($specification->isSatisfiedBy($location)) {
(yield $location);
}
if ($location['type'] == 'dir') {
foreach ($this->yieldFilesInPath($specification, $location['path']) as $returnedLocation) {
(yield $returnedLocation);
}
}
}
}
示例8: _scandir
/**
* Return files list in directory
*
* @param string $path dir path
* @return array
**/
protected function _scandir($path)
{
$paths = array();
foreach ($this->fs->listContents($path, false) as $object) {
$paths[] = $object['path'];
}
return $paths;
}
示例9: generate
public function generate($query)
{
$files = $this->filesystem->listContents($this->config['directory']);
array_filter($files, [$this, 'filterFiles']);
if (empty($files)) {
throw new RuntimeException('Cannot generate fractal image: template folder is empty');
}
mt_srand((double) microtime() * 1000000);
mt_rand(0, 1);
$random_file = mt_rand(0, count($files) - 1);
$resource = imagecreatefromjpeg(DIRECTORY_SEPARATOR . $files[$random_file]['path']);
if (!is_resource($resource)) {
throw new RuntimeException('Cannot create image from the fractal template: ' . $files[$random_file]['basename']);
}
return $resource;
// this variant will not work because of the different resource type
// return $this->filesystem->readStream($files[$random_file]['path']);
}
示例10: listFiles
/**
* @inheritdoc
*/
public function listFiles($directory = '')
{
$files = [];
foreach ($this->filesystem->listContents($directory, true) as $file) {
if ($file['type'] == 'dir' || strstr($file['path'], '/.') !== false) {
continue;
}
$files[] = $file['path'];
}
return $files;
}
示例11: getPaths
protected function getPaths(FilesystemInterface $filesystem, $skipDirs)
{
$paths = [];
foreach ($filesystem->listContents($this->dir, true) as $path) {
if ($skipDirs && $path['type'] === 'dir') {
continue;
}
$paths[$path['path']] = $path;
}
ksort($paths);
return $paths;
}
示例12: extract
/** @inheritdoc */
public function extract($zipBallPath, $to)
{
$absolutePathToZipBall = $this->filesystem->getAdapter()->applyPathPrefix($zipBallPath);
if ($this->zip->open($absolutePathToZipBall) === true) {
$absolutePathToExtract = $this->filesystem->getAdapter()->applyPathPrefix($to);
$this->zip->extractTo($absolutePathToExtract);
$this->zip->close();
$zipCreatedFolder = Linq::from($this->filesystem->listContents($to))->single(function ($object) {
return $object['type'] == 'dir';
})['path'];
foreach ($this->filesystem->listContents($zipCreatedFolder, true) as $object) {
if ($object['type'] == "file") {
$segments = explode('/', $object['path']);
unset($segments[4]);
$this->filesystem->rename($object['path'], implode('/', $segments));
}
}
$this->filesystem->deleteDir($zipCreatedFolder);
return;
}
throw new ZipExtractionFailed($zipBall, $to);
}
示例13: removeEmptyDirectories
/**
* {@inheritdoc}
*/
protected function removeEmptyDirectories($backupName)
{
/**
* @var \SplFileInfo $dir
*/
foreach ($this->flysystem->listContents($backupName) as $dir) {
if ($dir['type'] != 'dir') {
continue;
}
if (count($this->flysystem->listContents($dir['path'])) > 0) {
$this->removeEmptyDirectories($dir['path']);
} else {
$this->flysystem->deleteDir($dir['path']);
}
}
}
示例14: eraseDir
/**
* Erase a directory.
*
* @param string $dirname
* @throws IoWriteException
*/
public function eraseDir($dirname = '')
{
try {
$listing = $this->fs->listContents($dirname, false);
foreach ($listing as $item) {
if ($item['type'] === 'dir') {
$this->fs->deleteDir($item['path']);
} else {
$this->fs->delete($item['path']);
}
}
} catch (Error $ex) {
throw new IoWriteException("Directory {$dirname} could not be erased.", $ex);
} catch (Exception $ex) {
throw new IoWriteException("Directory {$dirname} could not be erased.", $ex);
}
}
示例15: ensuredEraseDir
/**
* Erase a directory.
*
* @param string $dirname
* @throws WriteException
*/
private function ensuredEraseDir($dirname)
{
try {
$listing = $this->fs->listContents($dirname, false);
foreach ($listing as $item) {
if ($item['type'] === 'dir') {
$this->fs->deleteDir($item['path']);
} else {
$this->fs->delete($item['path']);
}
}
return;
} catch (Error $ex) {
} catch (Exception $ex) {
}
throw new WriteException("Directory {$dirname} could not be erased.", $ex);
}