A (very simple) Flysystem v3 adapter for PDO/MySQL`. Based on the https://github.com/thephpleague/flysystem-memory implementation.
$ composer require basilicom/flysystem-pdo`
Prepare a (MySQL) table:
create table files (
bucket varchar(32) not null default 'default',
path varchar(255) not null,
isFile tinyint not null default 1,
mimeType varchar(64) not null default '',
contents longblob not null,
size int unsigned not null default 0,
checksum varchar(256) not null,
lastModified datetime,
visibility varchar(64),
PRIMARY KEY(bucket, path)
);
use League\Flysystem\Filesystem;
use Basilicom\Flysystem\Pdo\PdoAdapter;
$pdo = new PDO('mysql:host=mysql;dbname=mydb', 'myuser', 'mypass');
$adapter = new \Basilicom\Flysystem\Pdo\PdoAdapter($pdo);
$flysystem = new Filesystem($adapter);
$path = 'my/path/to/file.txt';
$contents = 'Lorem Ipsum';
$flysystem->write($path, $contents);
This library uses the FilesystemAdapterTestCase
provided by
league/flysystem-adapter-test-utilities
, so it performs integration tests
that need a real PDO connection.
To run tests, provide a MySQL database with the files
table schema,
duplicate the phpunit.xml.dist
file into phpunit.xml
and fill
all the environment variables, then run:
$ composer test
This will run PHP-CS-Fixer,[Psalm][3] and [PHPUnit][4], but you can run them individually like this:
$ composer phpcsfixer
$ composer psalm
$ composer phpunit