webalternatif / flysystem-openstack-swift
Flysystem v2 adapter for OpenStack Swift
Installs: 1 351
Dependents: 3
Suggesters: 1
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: 8.0.* || 8.1.* || 8.2.* || 8.3.*
- league/flysystem: ^3.0
- php-opencloud/openstack: ^3.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- league/flysystem-adapter-test-utilities: ^3.0
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.19.0
- vimeo/psalm: ^5.24
README
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
.
Installation
$ composer require webalternatif/flysystem-openstack-swift
Usage
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);
Uploading large objects
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.
Example
use Webf\Flysystem\OpenStackSwift\Config; $flysystem->writeStream($path, $content, new Config([ Config::OPTION_SEGMENT_SIZE => 52428800, // 50 MiB Config::OPTION_SEGMENT_CONTAINER => 'test_segments', ]));
Tests
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