webalternatif/flysystem-openstack-swift

Flysystem v2 adapter for OpenStack Swift

v0.3.2 2024-05-06 13:44 UTC

This package is auto-updated.

Last update: 2024-11-06 15:04:10 UTC


README

Source code Software license GitHub issues Test status Psalm coverage Psalm level

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