FlysystemBridge.php in Flysystem 8
File
src/FlysystemBridge.php
View source
<?php
namespace Drupal\flysystem;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use League\Flysystem\Util;
use Twistor\FlysystemStreamWrapper;
class FlysystemBridge extends FlysystemStreamWrapper implements StreamWrapperInterface {
use StringTranslationTrait;
public static function getType() {
return StreamWrapperInterface::WRITE_VISIBLE;
}
public function getName() {
$scheme = $this
->getProtocol();
$name = (string) $this
->getFactory()
->getSettings($scheme)['name'];
$default = $this
->t('Flysystem: @scheme', [
'@scheme' => $scheme,
]);
return $name !== '' ? $this
->t($name) : $default;
}
public function getDescription() {
$scheme = $this
->getProtocol();
$description = (string) $this
->getFactory()
->getSettings($scheme)['description'];
$default = $this
->t('Flysystem: @scheme', [
'@scheme' => $scheme,
]);
return $description !== '' ? $this
->t($description) : $default;
}
public function getUri() {
return $this->uri;
}
public function setUri($uri) {
$this->uri = $uri;
}
public function getExternalUrl() {
return $this
->getFactory()
->getPlugin($this
->getProtocol())
->getExternalUrl($this->uri);
}
public function realpath() {
return FALSE;
}
public function dirname($uri = NULL) {
if (!isset($uri)) {
$uri = $this->uri;
}
list($scheme, $target) = explode('://', $uri, 2);
return $scheme . '://' . ltrim(Util::dirname($target), '\\/');
}
protected function getFilesystemForScheme($scheme) {
if (!isset(static::$filesystems[$scheme])) {
static::$filesystems[$scheme] = $this
->getFactory()
->getFilesystem($scheme);
static::$config[$scheme] = static::$defaultConfiguration;
static::$config[$scheme]['permissions']['dir']['public'] = 0777;
static::registerPlugins($scheme, static::$filesystems[$scheme]);
}
return static::$filesystems[$scheme];
}
protected function getFilesystem() {
if (!isset($this->filesystem)) {
$this->filesystem = $this
->getFilesystemForScheme($this
->getProtocol());
}
return $this->filesystem;
}
protected function getFactory() {
return \Drupal::service('flysystem_factory');
}
}