Read from the package's own PHP files at the commit c627235810f8: its namespaces, classes, interfaces and enums, their public constants, properties and methods with their PHPDoc, and the options its factories take. Nothing of it is run.
ConfigclassA drive's configuration while its factory builds it: the options given, the factory's defaults under them, and the keys that must be filled. Options come as configuration and environment variables give them: strings too.
8 methods
DriveinterfaceOne storage, by the name the application gives it ("uploads", "s3.private"...): files read and written by their path in it, wherever it is - a directory of this machine, a bucket, an SFTP or FTP server.
24 methods
DriveFactoryclassThe family's way, at its simplest: a drive's factory fills a Config - its name ("omnidrive.factory_name"), its title ("omnidrive.factory_title"), the options it needs ("omnidrive.required_options") and the defaults of the others - then builds the drive from it.
3 methods
DriveFactoryInterfaceinterfaceBuilds a drive from its options (a root, a bucket and its keys, a server...).
2 methods
DrivesinterfaceThe application's drives by name. Registry builds them from factories and options; a host gives them from its own storages (Flysystem\OperatorDrives: Symfony's flysystem-bundle storages, Laravel's disks).
3 methods
RegistryclassThe application's drives by name, each built once from its factory and options:
8 methods
VisibilityenumWho may read a file: anyone (a public bucket's object, a file the web server serves, 0644) or the drive's own user (0600, a private object).
1 method · 2 cases
DriveExceptionclassA drive could not do what it was asked: the operation (one of OPERATIONS), the drive and the path are kept; the engine's own exception is the previous one.
2 methods · 3 properties · 1 constant
FileNotFoundExceptionclassThe file asked for is not on the drive.
InvalidConfigExceptionclassA drive that is not configured, a factory that is not installed, an option missing.
NotSupportedExceptionclassThe drive does not do that: a public address for a drive that has none, a signed one for a drive that cannot sign. Its Capabilities say so beforehand.
1 method
OmnidriveExceptioninterfaceEvery exception Omnidrive throws.
FlysystemDriveclassA Drive over a Flysystem operator: Flysystem is the engine, this class the only place that speaks to it. Its exceptions become the contract's (the engine's kept as the previous one), its attributes Entry, its visibility strings Visibility.
27 methods
FlysystemDriveFactoryclassA provider's factory: it builds the league adapter from its options, this class the drive around it. The options every drive takes:
OperatorDrivesclassThe drives a host already has, as Flysystem operators in a PSR-11 container by name: Symfony's flysystem-bundle storages (a service locator of the services tagged flysystem.storage), Laravel's disks. Each becomes a FlysystemDrive the first time it is asked for.
4 methods
CapabilitiesclassWhat a drive can do besides reading and writing, said before it is asked: whether its files are files of this machine (Drive::localPath()), whether it has a public address (Drive::publicUrl()), whether it signs temporary ones (Drive::temporaryUrl()).
2 methods · 3 properties
EntryclassA file or a directory of a drive, as a listing or metadata() gives it: what the drive told, null where it told nothing (a listing gives no type, a bucket no directory's date).
4 methods · 6 properties
DriveContractTeststraitWhat every Drive does, as PHPUnit tests: a provider's test case (or an application's, for a drive of its own) uses this trait and gives the drive.
9 methods
InMemoryDriveFactoryclassA drive in this process's memory, for an application's tests: what is written is read back until the process ends, nothing touches a disk or a network.
Omnidrive
Config class
final class Config extends ArrayObject Config.php:14
A drive's configuration while its factory builds it: the options given, the factory's defaults under them, and the keys that must be filled. Options come as configuration and environment variables give them: strings too.
Config::defaults()
public function defaults(array $defaults): selfSets each key not set yet.
Config::validateNotEmpty()
public function validateNotEmpty(array $keys): voidConfig::get()
public function get(string $key, mixed $default = null): mixedConfig::string()
public function string(string $key): ?stringA string option; null when it is empty.
Config::int()
public function int(string $key, int $default = 0): intConfig::octal()
public function octal(string $key, int $default): intAn octal permission, as an integer (0644) or a string ("0644", "644").
Config::bool()
public function bool(string $key, bool $default = false): boolA boolean option, as an environment variable gives it too: "1", "true", "yes", "on".
Config::list()
public function list(string $key): arrayA list given as one environment variable arrives as a single comma-separated string: split here.
Drive interface
interface Drive Drive.php:24
One storage, by the name the application gives it ("uploads", "s3.private"...): files read and written by their path in it, wherever it is - a directory of this machine, a bucket, an SFTP or FTP server.
A path is relative to the drive's root, "/" separated ("avatars/1.png"); a leading "/" is the same path. Nothing here names how the drive is reached: an application type-hints Drive (and Drives), never the engine behind it.
What fails is a DriveException (FileNotFoundException when the file is not there), what the drive cannot do a NotSupportedException - its Capabilities say so beforehand.
Drive::name()
public function name(): stringThe name the drive is configured with.
Drive::capabilities()
public function capabilities(): CapabilitiesWhat the drive can do besides reading and writing: a local file, public and temporary URLs.
Drive::read()
public function read(string $path): string- Throws
FileNotFoundException|\DriveException
Drive::readStream()
public function readStream(string $path)The file as a stream, for large files: the caller closes it.
- Throws
FileNotFoundException|\DriveException
Drive::write()
public function write(string $path, string $contents, array $options = []): voidWrites the file, replacing it when it is there; missing directories are made.
$options"visibility" (Visibility or "public"/"private"), "directory_visibility", and whatever the drive's engine takes
- Throws
DriveException
Drive::writeStream()
public function writeStream(string $path, $stream, array $options = []): void$optionsas write()
- Throws
DriveException
Drive::exists()
public function exists(string $path): boolWhether a file is there (a directory is not a file).
Drive::directoryExists()
public function directoryExists(string $path): boolDrive::delete()
public function delete(string $path): voidDeletes the file; a file that is not there is no error.
Drive::deleteDirectory()
public function deleteDirectory(string $path): voidDeletes the directory and everything under it; a directory that is not there is no error.
Drive::createDirectory()
public function createDirectory(string $path, array $options = []): void$options"directory_visibility"
Drive::list()
public function list(string $path = '', bool $deep = false): iterableWhat a directory holds, files and directories, lazily; $deep goes down every directory under it.
- Throws
DriveException
Drive::move()
public function move(string $from, string $to): void- Throws
FileNotFoundException|\DriveException
Drive::copy()
public function copy(string $from, string $to): void- Throws
FileNotFoundException|\DriveException
Drive::metadata()
public function metadata(string $path): EntryThe file's size, type, last change and visibility, as one Entry (several calls to a remote drive: ask size() or mimeType() alone when that is all you need).
- Throws
FileNotFoundException|\DriveException
Drive::size()
public function size(string $path): intIn bytes.
@throws FileNotFoundException|DriveException
Drive::mimeType()
public function mimeType(string $path): string- Throws
FileNotFoundException|\DriveException
Drive::lastModified()
public function lastModified(string $path): \DateTimeImmutable- Throws
FileNotFoundException|\DriveException
Drive::checksum()
public function checksum(string $path, string $algorithm = 'md5'): string- Throws
FileNotFoundException|\DriveException
Drive::visibility()
public function visibility(string $path): Visibility- Throws
FileNotFoundException|\DriveException
Drive::setVisibility()
public function setVisibility(string $path, Visibility $visibility): void- Throws
FileNotFoundException|\DriveException
Drive::publicUrl()
public function publicUrl(string $path): stringWhere anyone fetches the file from: the drive's public address (its "public_url" option, or a bucket's own), whether the file is there or not.
- Throws
NotSupportedException when the drive has none (Capabilities::$publicUrls)
Drive::temporaryUrl()
public function temporaryUrl(string $path, \DateTimeInterface $expiresAt): stringA signed address that serves the file until $expiresAt, to whoever holds it.
- Throws
NotSupportedException when the drive cannot sign one (Capabilities::$temporaryUrls)
Drive::localPath()
public function localPath(string $path): ?stringThe file's path on this machine, whether it is there or not; null for a drive with no local file behind its paths (a bucket, a server).
DriveFactory class
abstract class DriveFactory implements DriveFactoryInterface DriveFactory.php:13
The family's way, at its simplest: a drive's factory fills a Config - its name ("omnidrive.factory_name"), its title ("omnidrive.factory_title"), the options it needs ("omnidrive.required_options") and the defaults of the others - then builds the drive from it.
Nothing here connects: a drive reaches its server on its first operation.
DriveFactory::getName()
public function getName(): stringDriveFactory::create()
public function create(array $options = [], ?string $name = null): DriveDriveFactory::createConfig()
public function createConfig(array $options = []): ConfigDriveFactoryInterface interface
interface DriveFactoryInterface DriveFactoryInterface.php:6
Builds a drive from its options (a root, a bucket and its keys, a server...).
DriveFactoryInterface::getName()
public function getName(): stringThe name drives are configured with: "local", "s3", "sftp", "ftp".
..
DriveFactoryInterface::create()
public function create(array $options = [], ?string $name = null): Drive$namethe drive's name (Drive::name()); the factory's when null
Drives interface
interface Drives Drives.php:12
The application's drives by name. Registry builds them from factories and options; a host gives them from its own storages (Flysystem\OperatorDrives: Symfony's flysystem-bundle storages, Laravel's disks).
Drives::get()
public function get(string $name): Drive- Throws
InvalidConfigException when no drive has that name
Drives::has()
public function has(string $name): boolDrives::names()
public function names(): array- Returns
the drives' names, as far as they are known
Registry class
final class Registry implements Drives Registry.php:18
The application's drives by name, each built once from its factory and options:
new Registry([new LocalDriveFactory(), new S3DriveFactory()], [ 'uploads' => ['factory' => 'local', 'options' => ['root' => __DIR__.'/var/uploads', 'public_url' => '/uploads']], 'archive' => ['factory' => 's3', 'options' => ['bucket' => 'archive', 'region' => 'eu-west-3', 'key' => '...', 'secret' => '...']], ]);
$registry->get('uploads')->write('avatars/1.png', $bytes);
Registry::__construct()
public function __construct(iterable $factories, readonly array $config)Registry::get()
public function get(string $name): DriveRegistry::has()
public function has(string $name): boolRegistry::names()
public function names(): arrayRegistry::options()
public function options(string $name): array- Returns
the options a drive is configured with
Registry::create()
public function create(string $name, array $overrides = []): DriveA drive built afresh, its configured options with $overrides over them. Not kept: get() still gives the configured one.
Registry::all()
public function all(): arrayRegistry::factories()
public function factories(): array- Returns
the factories installed: what
factory:may name
Visibility enum
enum Visibility Visibility.php:9
Who may read a file: anyone (a public bucket's object, a file the web server serves, 0644) or the drive's own user (0600, a private object).
case Public = 'public'case Private = 'private'
Visibility::of()
public static function of(self|string $visibility): selfA Visibility, or its name as configuration gives it ("public", "private").
Omnidrive\Exception
DriveException class
class DriveException extends RuntimeException implements OmnidriveException DriveException.php:10
A drive could not do what it was asked: the operation (one of OPERATIONS), the drive and the path are kept; the engine's own exception is the previous one.
const OPERATIONS = ['read' => 'read', 'write' => 'write', 'delete' => 'delete', 'move' => 'move', 'copy' => 'copy', 'list' => 'list', 'exists' => 'check whether there is', 'dir…public readonly string $operationpublic readonly string $drivepublic readonly string $path
DriveException::__construct()
final public function __construct(public readonly string $operation, public readonly string $drive, public readonly string $path, string $reason = '', ?\Throwable $previous = null)DriveException::of()
public static function of(string $operation, string $drive, string $path, ?\Throwable $previous = null): staticFileNotFoundException class
final class FileNotFoundException extends DriveException FileNotFoundException.php:6
The file asked for is not on the drive.
InvalidConfigException class
final class InvalidConfigException extends InvalidArgumentException implements OmnidriveException InvalidConfigException.php:6
A drive that is not configured, a factory that is not installed, an option missing.
NotSupportedException class
final class NotSupportedException extends LogicException implements OmnidriveException NotSupportedException.php:9
The drive does not do that: a public address for a drive that has none, a signed one for a drive that cannot sign. Its Capabilities say so beforehand.
NotSupportedException::operation()
public static function operation(string $drive, string $operation, string $why = ''): selfOmnidriveException interface
interface OmnidriveException extends Throwable OmnidriveException.php:6
Every exception Omnidrive throws.
Omnidrive\Flysystem
FlysystemDrive class
final class FlysystemDrive implements Drive FlysystemDrive.php:32
A Drive over a Flysystem operator: Flysystem is the engine, this class the only place that speaks to it. Its exceptions become the contract's (the engine's kept as the previous one), its attributes Entry, its visibility strings Visibility.
Built by a provider's factory (which knows its root and what it can do), or by a host over the storages it already has (of(): the root of a local adapter and the generators of public and temporary URLs read from the operator).
FlysystemDrive::__construct()
public function __construct(readonly string $name, readonly FilesystemOperator $operator, readonly ?string $localRoot = null, ?Capabilities $capabilities = null)$localRootthe directory of this machine behind the drive's paths; null for a remote drive
FlysystemDrive::of()
public static function of(string $name, FilesystemOperator $operator): selfA drive over an operator a host gives: its local root, if any, read from its adapter.
FlysystemDrive::operator()
public function operator(): FilesystemOperatorThe engine, for a host that hands it to a library that speaks Flysystem itself. An application keeps to Drive.
FlysystemDrive::name()
public function name(): stringFlysystemDrive::capabilities()
public function capabilities(): CapabilitiesFlysystemDrive::read()
public function read(string $path): stringFlysystemDrive::readStream()
public function readStream(string $path)FlysystemDrive::write()
public function write(string $path, string $contents, array $options = []): voidFlysystemDrive::writeStream()
public function writeStream(string $path, $stream, array $options = []): voidFlysystemDrive::exists()
public function exists(string $path): boolFlysystemDrive::directoryExists()
public function directoryExists(string $path): boolFlysystemDrive::delete()
public function delete(string $path): voidFlysystemDrive::deleteDirectory()
public function deleteDirectory(string $path): voidFlysystemDrive::createDirectory()
public function createDirectory(string $path, array $options = []): voidFlysystemDrive::list()
public function list(string $path = '', bool $deep = false): iterableFlysystemDrive::move()
public function move(string $from, string $to): voidFlysystemDrive::copy()
public function copy(string $from, string $to): voidFlysystemDrive::metadata()
public function metadata(string $path): EntryFlysystemDrive::size()
public function size(string $path): intFlysystemDrive::mimeType()
public function mimeType(string $path): stringFlysystemDrive::lastModified()
public function lastModified(string $path): \DateTimeImmutableFlysystemDrive::checksum()
public function checksum(string $path, string $algorithm = 'md5'): stringFlysystemDrive::visibility()
public function visibility(string $path): VisibilityFlysystemDrive::setVisibility()
public function setVisibility(string $path, Visibility $visibility): voidFlysystemDrive::publicUrl()
public function publicUrl(string $path): stringFlysystemDrive::temporaryUrl()
public function temporaryUrl(string $path, \DateTimeInterface $expiresAt): stringFlysystemDrive::localPath()
public function localPath(string $path): ?stringFlysystemDriveFactory class
abstract class FlysystemDriveFactory extends DriveFactory FlysystemDriveFactory.php:30
A provider's factory: it builds the league adapter from its options, this class the drive around it. The options every drive takes:
- public_url: where its files are served from, a prefix ("https://cdn.example.org/uploads", "/uploads") or a list of them (sharded); else the adapter's own (a bucket's);
- visibility, directory_visibility: what a file or a directory is written with by default ("public", "private");
- retain_visibility: whether a copy keeps the visibility of its source (true, Flysystem's); false copies with the drive's default visibility, for a server that cannot report a file's;
- permissions (a drive of Unix files: local, SFTP, FTP): the modes each visibility is, {file: {public: 0644, private: 0600}, dir: {public: 0755, private: 0700}}.
OperatorDrives class
final class OperatorDrives implements Drives OperatorDrives.php:20
The drives a host already has, as Flysystem operators in a PSR-11 container by name: Symfony's flysystem-bundle storages (a service locator of the services tagged flysystem.storage), Laravel's disks. Each becomes a FlysystemDrive the first time it is asked for.
Its names are those given, else those a service locator provides (getProvidedServices()); a plain container cannot list its own.
OperatorDrives::__construct()
public function __construct(readonly ContainerInterface $operators, readonly ?array $names = null)OperatorDrives::get()
public function get(string $name): DriveOperatorDrives::has()
public function has(string $name): boolOperatorDrives::names()
public function names(): arrayOmnidrive\Model
Capabilities class
final readonly class Capabilities Capabilities.php:11
What a drive can do besides reading and writing, said before it is asked: whether its files are files of this machine (Drive::localPath()), whether it has a public address (Drive::publicUrl()), whether it signs temporary ones (Drive::temporaryUrl()).
public bool $localpublic bool $publicUrlspublic bool $temporaryUrls
Capabilities::__construct()
public function __construct(public bool $local = false, public bool $publicUrls = false, public bool $temporaryUrls = false)Capabilities::toArray()
public function toArray(): arrayEntry class
final readonly class Entry Entry.php:12
A file or a directory of a drive, as a listing or metadata() gives it: what the drive told, null where it told nothing (a listing gives no type, a bucket no directory's date).
public string $pathpublic bool $directorypublic ?int $sizepublic ?\DateTimeImmutable $lastModifiedpublic ?Visibility $visibilitypublic ?string $mimeType
Entry::__construct()
public function __construct(public string $path, public bool $directory = false, public ?int $size = null, public ?\DateTimeImmutable $lastModified = null, public ?Visibility $visibility = null, public ?string $mimeType = null)Entry::isFile()
public function isFile(): boolEntry::basename()
public function basename(): stringThe last segment of the path.
Entry::toArray()
public function toArray(): arrayOmnidrive\Testing
DriveContractTests trait
trait DriveContractTests DriveContractTests.php:27
What every Drive does, as PHPUnit tests: a provider's test case (or an application's, for a drive of its own) uses this trait and gives the drive.
Each test works under a directory of its own, removed afterwards, so a shared bucket or server is left as it was.
final class LocalDriveTest extends TestCase { use DriveContractTests;
protected function drive(): Drive { return (new LocalDriveFactory())->create(['root' => sys_get_temp_dir().'/drive']); }
}Requires phpunit/phpunit (the application's, in require-dev).
DriveContractTests::testAFileIsWrittenReadAndDeleted()
public function testAFileIsWrittenReadAndDeleted(): voidDriveContractTests::testStreamsAreWrittenAndRead()
public function testStreamsAreWrittenAndRead(): voidDriveContractTests::testAFileThatIsNotThereIsNotFound()
public function testAFileThatIsNotThereIsNotFound(): voidDriveContractTests::testADirectoryIsListedShallowAndDeep()
public function testADirectoryIsListedShallowAndDeep(): voidDriveContractTests::testAFileIsMovedAndCopied()
public function testAFileIsMovedAndCopied(): voidDriveContractTests::testDirectoriesAreMadeAndDeleted()
public function testDirectoriesAreMadeAndDeleted(): voidDriveContractTests::testMetadataAndChecksumAreTheFile()
public function testMetadataAndChecksumAreTheFile(): voidDriveContractTests::testVisibilityIsWrittenAndChanged()
public function testVisibilityIsWrittenAndChanged(): voidDriveContractTests::testAddressesAndLocalPathsAreWhatTheCapabilitiesSay()
public function testAddressesAndLocalPathsAreWhatTheCapabilitiesSay(): voidInMemoryDriveFactory class
final class InMemoryDriveFactory extends FlysystemDriveFactory InMemoryDriveFactory.php:18
A drive in this process's memory, for an application's tests: what is written is read back until the process ends, nothing touches a disk or a network.
Requires league/flysystem-memory (suggested).
new Registry([new InMemoryDriveFactory()], ['uploads' => ['factory' => 'memory', 'options' => ['public_url' => '/uploads']]]);