A Flysystem v3 adapter for OpenStack Swift, using
php-opencloud/openstack
.
If you're looking for a Flysystem v1 adapter, see
chrisnharvey/flysystem-openstack-swift
.
$ composer require webalternatif/flysystem-openstack-swift
use League\Flysystem\Filesystem;
use OpenStack\OpenStack;
use Webf\Flysystem\OpenStackSwift\OpenStackSwiftAdapter;
$openstack = new OpenStack([
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => [
'id' => '{userId}',
'password' => '{password}',
],
'scope' => ['project' => ['id' => '{projectId}']],
]);
$adapter = new OpenStackSwiftAdapter($openstack, '{containerName}');
$flysystem = new Filesystem($adapter);
In order to use the createLargeObject
method of the underlying OpenStack
library to upload large objects (which is mandatory for files over 5 GB),
you must use the writeStream
method and define the segment_size
config
option.
The segment_container
option is also available if you want to upload segments
in another container.
use Webf\Flysystem\OpenStackSwift\Config;
$flysystem->writeStream($path, $content, new Config([
Config::OPTION_SEGMENT_SIZE => 52428800, // 50 MiB
Config::OPTION_SEGMENT_CONTAINER => 'test_segments',
]));
This library uses the FilesystemAdapterTestCase
provided by
league/flysystem-adapter-test-utilities
, so it performs integration tests
that need a real OpenStack Swift container.
To run tests, duplicate the phpunit.xml.dist
file into phpunit.xml
and fill
all the environment variables, then run:
$ composer test
This will run Psalm and PHPUnit, but you can run them individually like this:
$ composer psalm
$ composer phpunit