Skip to content

Commit

Permalink
more modern properties
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Oct 26, 2022
1 parent 07dc5ab commit e6fbd8b
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 281 deletions.
8 changes: 1 addition & 7 deletions src/AwsS3V3/PortableVisibilityConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ class PortableVisibilityConverter implements VisibilityConverter
private const PUBLIC_ACL = 'public-read';
private const PRIVATE_ACL = 'private';

/**
* @var string
*/
private $defaultForDirectories;

public function __construct(string $defaultForDirectories = Visibility::PUBLIC)
public function __construct(private string $defaultForDirectories = Visibility::PUBLIC)
{
$this->defaultForDirectories = $defaultForDirectories;
}

public function visibilityToAcl(string $visibility): string
Expand Down
5 changes: 3 additions & 2 deletions src/Ftp/FtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class FtpAdapter implements FilesystemAdapter
private PathPrefixer $prefixer;
private VisibilityConverter $visibilityConverter;
private ?bool $isPureFtpdServer = null;
private ?bool $useRawListOptions = null;
private ?string $systemType = null;
private ?bool $useRawListOptions;
private ?string $systemType;
private MimeTypeDetector $mimeTypeDetector;

private ?string $rootDirectory = null;
Expand All @@ -60,6 +60,7 @@ public function __construct(
VisibilityConverter $visibilityConverter = null,
MimeTypeDetector $mimeTypeDetector = null
) {
$this->systemType = $this->connectionOptions->systemType();
$this->connectionProvider = $connectionProvider ?: new FtpConnectionProvider();
$this->connectivityChecker = $connectivityChecker ?: new NoopCommandConnectivityChecker();
$this->visibilityConverter = $visibilityConverter ?: new PortableVisibilityConverter();
Expand Down
117 changes: 15 additions & 102 deletions src/Ftp/FtpConnectionOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,110 +8,23 @@

class FtpConnectionOptions
{
/**
* @var string
*/
private $host;

/**
* @var string
*/
private $root;

/**
* @var string
*/
private $username;

/**
* @var string
*/
private $password;

/**
* @var int
*/
private $port;

/**
* @var bool
*/
private $ssl;

/**
* @var int
*/
private $timeout;

/**
* @var bool
*/
private $utf8;

/**
* @var bool
*/
private $passive;

/**
* @var int
*/
private $transferMode;

/**
* @var string|null
*/
private $systemType;

/**
* @var bool|null
*/
private $ignorePassiveAddress;

/**
* @var bool
*/
private $enableTimestampsOnUnixListings;

/**
* @var bool
*/
private $recurseManually;

private ?bool $useRawListOptions;

public function __construct(
string $host,
string $root,
string $username,
string $password,
int $port = 21,
bool $ssl = false,
int $timeout = 90,
bool $utf8 = false,
bool $passive = true,
int $transferMode = FTP_BINARY,
?string $systemType = null,
?bool $ignorePassiveAddress = null,
bool $enableTimestampsOnUnixListings = false,
bool $recurseManually = false,
?bool $useRawListOptions = null,
private string $host,
private string $root,
private string $username,
private string $password,
private int $port = 21,
private bool $ssl = false,
private int $timeout = 90,
private bool $utf8 = false,
private bool $passive = true,
private int $transferMode = FTP_BINARY,
private ?string $systemType = null,
private ?bool $ignorePassiveAddress = null,
private bool $enableTimestampsOnUnixListings = false,
private bool $recurseManually = false,
private ?bool $useRawListOptions = null,
) {
$this->host = $host;
$this->root = $root;
$this->username = $username;
$this->password = $password;
$this->port = $port;
$this->ssl = $ssl;
$this->timeout = $timeout;
$this->utf8 = $utf8;
$this->passive = $passive;
$this->transferMode = $transferMode;
$this->systemType = $systemType;
$this->ignorePassiveAddress = $ignorePassiveAddress;
$this->enableTimestampsOnUnixListings = $enableTimestampsOnUnixListings;
$this->recurseManually = $recurseManually;
$this->useRawListOptions = $useRawListOptions;
}

public function host(): string
Expand Down
8 changes: 2 additions & 6 deletions src/GoogleCloudStorage/GoogleCloudStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@

class GoogleCloudStorageAdapter implements FilesystemAdapter, PublicUrlGenerator, ChecksumProvider, TemporaryUrlGenerator
{
private Bucket $bucket;
private PathPrefixer $prefixer;
private VisibilityHandler $visibilityHandler;
private string $defaultVisibility;
private MimeTypeDetector $mimeTypeDetector;

private static array $algoToInfoMap = [
Expand All @@ -59,16 +57,14 @@ class GoogleCloudStorageAdapter implements FilesystemAdapter, PublicUrlGenerator
];

public function __construct(
Bucket $bucket,
private Bucket $bucket,
string $prefix = '',
VisibilityHandler $visibilityHandler = null,
string $defaultVisibility = Visibility::PRIVATE,
private string $defaultVisibility = Visibility::PRIVATE,
MimeTypeDetector $mimeTypeDetector = null
) {
$this->bucket = $bucket;
$this->prefixer = new PathPrefixer($prefix);
$this->visibilityHandler = $visibilityHandler ?: new PortableVisibilityHandler();
$this->defaultVisibility = $defaultVisibility;
$this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
}

Expand Down
41 changes: 6 additions & 35 deletions src/Local/LocalFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,9 @@ class LocalFilesystemAdapter implements FilesystemAdapter, ChecksumProvider
*/
public const DISALLOW_LINKS = 0002;

/**
* @var PathPrefixer
*/
private $prefixer;

/**
* @var int
*/
private $writeFlags;

/**
* @var int
*/
private $linkHandling;

/**
* @var VisibilityConverter
*/
private $visibility;

/**
* @var MimeTypeDetector
*/
private $mimeTypeDetector;

/**
* @var string
*/
private $rootLocation;
private PathPrefixer $prefixer;
private VisibilityConverter $visibility;
private MimeTypeDetector $mimeTypeDetector;

/**
* @var bool
Expand All @@ -96,16 +70,13 @@ class LocalFilesystemAdapter implements FilesystemAdapter, ChecksumProvider
public function __construct(
string $location,
VisibilityConverter $visibility = null,
int $writeFlags = LOCK_EX,
int $linkHandling = self::DISALLOW_LINKS,
private int $writeFlags = LOCK_EX,
private int $linkHandling = self::DISALLOW_LINKS,
MimeTypeDetector $mimeTypeDetector = null,
bool $lazyRootCreation = false,
) {
$this->prefixer = new PathPrefixer($location, DIRECTORY_SEPARATOR);
$this->writeFlags = $writeFlags;
$this->linkHandling = $linkHandling;
$this->visibility = $visibility ?: new PortableVisibilityConverter();
$this->rootLocation = $location;
$this->mimeTypeDetector = $mimeTypeDetector ?: new FallbackMimeTypeDetector(new FinfoMimeTypeDetector());

if ( ! $lazyRootCreation) {
Expand All @@ -119,7 +90,7 @@ private function ensureRootDirectoryExists(): void
return;
}

$this->ensureDirectoryExists($this->rootLocation, $this->visibility->defaultForDirectories());
$this->ensureDirectoryExists($this->prefixer->prefixPath('/'), $this->visibility->defaultForDirectories());
}

public function write(string $path, string $contents, Config $config): void
Expand Down
4 changes: 1 addition & 3 deletions src/PathPrefixing/PathPrefixedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ class PathPrefixedAdapter implements FilesystemAdapter, PublicUrlGenerator, Chec
{
use CalculateChecksumFromStream;

protected FilesystemAdapter $adapter;
private PathPrefixer $prefix;

public function __construct(FilesystemAdapter $adapter, string $prefix)
public function __construct(private FilesystemAdapter $adapter, string $prefix)
{
if ($prefix === '') {
throw new \InvalidArgumentException('The prefix must not be empty.');
}

$this->adapter = $adapter;
$this->prefix = new PathPrefixer($prefix);
}

Expand Down
25 changes: 4 additions & 21 deletions src/PhpseclibV3/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,16 @@

class SftpAdapter implements FilesystemAdapter
{
/**
* @var ConnectionProvider
*/
private $connectionProvider;

/**
* @var VisibilityConverter
*/
private $visibilityConverter;

/**
* @var PathPrefixer
*/
private $prefixer;

/**
* @var MimeTypeDetector
*/
private $mimeTypeDetector;
private VisibilityConverter $visibilityConverter;
private PathPrefixer $prefixer;
private MimeTypeDetector $mimeTypeDetector;

public function __construct(
ConnectionProvider $connectionProvider,
private ConnectionProvider $connectionProvider,
string $root,
VisibilityConverter $visibilityConverter = null,
MimeTypeDetector $mimeTypeDetector = null
) {
$this->connectionProvider = $connectionProvider;
$this->prefixer = new PathPrefixer($root);
$this->visibilityConverter = $visibilityConverter ?: new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
Expand Down
Loading

0 comments on commit e6fbd8b

Please sign in to comment.