本文整理汇总了PHP中League\Flysystem\FilesystemInterface::getAdapter方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesystemInterface::getAdapter方法的具体用法?PHP FilesystemInterface::getAdapter怎么用?PHP FilesystemInterface::getAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\FilesystemInterface
的用法示例。
在下文中一共展示了FilesystemInterface::getAdapter方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: adapterType
protected function adapterType()
{
if ($this->filesystem instanceof Filesystem) {
$reflect = new \ReflectionClass($this->filesystem->getAdapter());
return $reflect->getShortName();
}
return 'Unknown';
}
示例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: getAdapter
/**
* @return AdapterInterface
*/
public function getAdapter()
{
if (!method_exists($this->fileSystem, 'getAdapter')) {
throw new InvalidArgumentException("This wrapper requires the getAdapter method to exist on the fileSystem");
}
return $this->fileSystem->getAdapter();
}
示例4: getIcon
/**
* Find the icon based on the used Adapter
*
* @return string
*/
protected function getIcon()
{
try {
$adapter = $this->fs->getAdapter();
} catch (\Exception $e) {
$adapter = null;
}
if ($adapter instanceof League\Flysystem\Adapter\AbstractFtpAdapter) {
$icon = 'volume_icon_ftp.png';
} elseif ($adapter instanceof League\Flysystem\Dropbox\DropboxAdapter) {
$icon = 'volume_icon_dropbox.png';
} else {
$icon = 'volume_icon_local.png';
}
$parentUrl = defined('ELFINDER_IMG_PARENT_URL') ? rtrim(ELFINDER_IMG_PARENT_URL, '/') . '/' : '';
return $parentUrl . 'img/' . $icon;
}
示例5: fetch
/**
* {@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);
}
示例6: fetch
/**
* {@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);
}
示例7: onGetClassGenerateFile
/**
* 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));
}
}
示例8: url
/**
* Get the URL for the file at the given path.
*
* @param string $path
* @return string
*/
public function url($path)
{
$adapter = $this->driver->getAdapter();
if ($adapter instanceof AwsS3Adapter) {
return $adapter->getClient()->getObjectUrl($adapter->getBucket(), $path);
} elseif ($adapter instanceof LocalAdapter) {
return '/storage/' . $path;
} else {
throw new RuntimeException('This driver does not support retrieving URLs.');
}
}
示例9: 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);
}
示例10: url
/**
* Get the URL for the file at the given path.
*
* @param string $path
* @return string
*/
public function url($path)
{
$adapter = $this->driver->getAdapter();
if ($adapter instanceof AwsS3Adapter) {
$path = $adapter->getPathPrefix() . $path;
return $adapter->getClient()->getObjectUrl($adapter->getBucket(), $path);
} elseif ($adapter instanceof LocalAdapter) {
$path = '/storage/' . $path;
return Str::contains($path, '/storage/public') ? Str::replaceFirst('/public', '', $path) : $path;
} elseif (method_exists($adapter, 'getUrl')) {
return $adapter->getUrl($path);
} else {
throw new RuntimeException('This driver does not support retrieving URLs.');
}
}
示例11: readFile
/**
* Given the path to a composer file we return it's json as an array.
*
* @param string $file
* @return array
*/
private function readFile($file)
{
$this->cache->setNamespace(sha1(__CLASS__));
$item = $this->cache->getItem(sha1($file));
$data = $item->get();
if ($item->isMiss()) {
$item->lock();
if ($this->filesystem->has($file)) {
$data = json_decode($this->filesystem->read($file), true);
} else {
throw new ComposerFileNotFound($this->filesystem->getAdapter()->applyPathPrefix($file));
}
$this->cache->save($item->set($data));
}
return $data;
}
示例12: init
/**
* Prepare driver before mount volume.
* Return true if volume is ready.
*
* @return bool
**/
protected function init()
{
$this->fs = $this->options['filesystem'];
if (!$this->fs instanceof FilesystemInterface) {
return $this->setError('A filesystem instance is required');
}
if ($this->fs instanceof Filesystem) {
$adapter = $this->fs->getAdapter();
// If the Flysystem adapter already is a cache, try to determine the cache.
if ($adapter instanceof CachedAdapter) {
// Try to get the cache (method doesn't exist in all versions)
if (method_exists($adapter, 'getCache')) {
$this->fscache = $adapter->getCache();
} elseif ($this->options['fscache'] instanceof CacheInterface) {
$this->fscache = $this->options['fscache'];
}
} elseif ($this->options['cache']) {
switch ($this->options['cache']) {
case 'session':
$this->fscache = new SessionStore($this->session, 'fls_cache_' . $this->id);
break;
case 'memory':
$this->fscache = new MemoryStore();
break;
}
if ($this->fscache) {
$adapter = new CachedAdapter($adapter, $this->fscache);
$this->fs = new Filesystem($adapter);
}
}
}
$this->fs->addPlugin(new GetUrl());
$this->options['icon'] = $this->options['icon'] ?: (empty($this->options['rootCssClass']) ? $this->getIcon() : '');
$this->root = $this->options['path'];
if ($this->options['glideURL']) {
$this->urlBuilder = UrlBuilderFactory::create($this->options['glideURL'], $this->options['glideKey']);
}
if ($this->options['imageManager']) {
$this->imageManager = $this->options['imageManager'];
} else {
$this->imageManager = new ImageManager();
}
return true;
}
示例13: setFilesystem
public function setFilesystem(FilesystemInterface $filesystem)
{
$this->adapter = $filesystem->getAdapter();
}