basilicom / flysystem-pdo
Flysystem v3 adapter for PDO
v1.1.1
2023-02-13 11:52 UTC
Requires
- php: 8.0.* || 8.1.* || 8.2.*
- ext-pdo: *
- league/flysystem: ^3.0
- thecodingmachine/safe: ^2.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- league/flysystem-adapter-test-utilities: ^3.0
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.16.1
- vimeo/psalm: ^4.9
README
A (very simple) Flysystem v3 adapter for PDO/MySQL`. Based on the https://github.com/thephpleague/flysystem-memory implementation.
Installation
$ 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)
);
Usage
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);
Example
$path = 'my/path/to/file.txt'; $contents = 'Lorem Ipsum'; $flysystem->write($path, $contents);
Tests
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