basilicom/flysystem-pdo

Flysystem v3 adapter for PDO

v1.1.1 2023-02-13 11:52 UTC

This package is auto-updated.

Last update: 2024-04-13 14:24:05 UTC


README

Psalm coverage Psalm level

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