webalternatif / flysystem-failover-bundle
A bundle to create failover Flysystem adapters.
Installs: 1 372
Dependents: 3
Suggesters: 1
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: 8.0.* || 8.1.* || 8.2.* || 8.3.*
- guzzlehttp/psr7: ^2.0
- league/flysystem: ^3.0
- nyholm/dsn: ^2.0
- symfony/config: ^4.4 || ^5.2 || ^6.0
- symfony/console: ^4.4 || ^5.2 || ^6.0
- symfony/dependency-injection: ^4.4 || ^5.2 || ^6.0
- symfony/event-dispatcher: ^4.4 || ^5.2 || ^6.0
- symfony/http-kernel: ^4.4 || ^5.2 || ^6.0
- webalternatif/flysystem-composite: ^0.2.0
Requires (Dev)
- doctrine/common: ^3.1
- doctrine/dbal: ^2.13
- doctrine/orm: ^2.9
- friendsofphp/php-cs-fixer: ^3.1
- infection/infection: ^0.25.0
- league/flysystem-memory: ^3.0
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.18.4
- symfony/serializer: ^5.3
- vimeo/psalm: ^5.19
Suggests
- symfony/serializer: To enable --format option in console commands
Conflicts
- doctrine/dbal: <2.13.1
README
This bundle allows creating failover Flysystem adapters and provides tooling to keep underlying storages synchronized.
💡 Tip: you may want to use this bundle through webalternatif/flysystem-dsn-bundle, which makes the configuration much easier.
How it works
This bundle allows you to create failover adapters for Flysystem. A failover adapter is an adapter that is built upon multiple (already existing) adapters.
When you use a failover adapter, it will forward method calls to inner adapters.
- For reading, it will use the first that works.
- For writing, it will use the first that works and will push messages into a repository to keep underlying storages of all adapters synchronized.
Messages in the repository can then be asynchronously processed by a console command call (see Processing messages section).
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
$ composer require webalternatif/flysystem-failover-bundle
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require webalternatif/flysystem-failover-bundle
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles in the
config/bundles.php
file of your project:
// config/bundles.php return [ // ... Webf\FlysystemFailoverBundle\WebfFlysystemFailoverBundle::class => ['all' => true], ];
Usage
Configuration
Failover adapters are configured under the webf_flysystem_failover.adapters
Symfony config path, and are then available as services with id
webf_flysystem_failover.adapter.{name}
.
Each failover adapter must have at least 2 inner adapters. An inner adapter could be a string to reference a service id, or an array with the following attributes:
service_id
: (required) identifier of the inner adapter service,time_shift
: a time shift for when the synchronization command compares modification dates between inner adapters.
Message repository is customizable under the
webf_flysystem_failover.message_repository_dsn
Symfony config path. For now,
only doctrine://<connection_name>
and service://<service_id>
are available.
webf_flysystem_failover: adapters: adapter1: # service: webf_flysystem_failover.adapter.adapter1 adapters: - service_id_of_adapter_1 - service_id: service_id_of_adapter_2 time_shift: 7200 # underlying storage of this adapter use a +02:00 timezone adapter2: # service: webf_flysystem_failover.adapter.adapter2 adapters: - service_id_of_adapter_3 - service_id_of_adapter_4 - service_id_of_adapter_5 message_repository_dsn: doctrine://my_connection
Run bin/console config:dump-reference webf_flysystem_failover
for more info.
Processing messages
To process messages created by failover adapters, the following command is available:
$ bin/console webf:flysystem-failover:process-messages
It will process and remove the oldest messages present in the repository.
Listing messages to be processed
To list messages without removing them from the repository, run the following command:
$ bin/console webf:flysystem-failover:list-messages
Results are paginated by default, you can use --limit
(-l
) and --page
(-p
) to configure pagination.
If symfony/serializer
is installed, the --format
(-f
) becomes
available and allows you to display output in csv
, json
or xml
.
Use --help
for more info.
Synchronize existing storages
If you start to use this bundle on an existing project, you may want to manually synchronize an existing non-empty storage with other new empty ones.
It is possible with the following command:
$ bin/console webf:flysystem-failover:sync
Use --help
for more info.
Tests
To run all tests, execute the command:
$ composer test
This will run Psalm, PHPUnit, Infection and a PHP-CS-Fixer check, but you can run them individually like this:
$ composer psalm $ composer phpunit $ composer infection $ composer cs-check