Instead of using the service locator (container), it is recommended to inject filesystems directly into your services via Dependency Injection.
When injecting, use the resolved service name (e.g., @oneup_flysystem.acme_filesystem) or the alias you defined. In your PHP class, type-hint against \League\Flysystem\FilesystemOperator.
Symfony 4.2+ Tip: You can use automatic dependency injection by type-hinting the specific filesystem. For a filesystem named acme, you can type-hint AcmeFilesystem (or similar depending on your autowiring setup) if you leverage ContainerBuilder::registerAliasForArgument().
services:
app.my_service:
class: App\MyService
arguments:
- '@oneup_flysystem.acme_filesystem'
use League\Flysystem\FilesystemOperator;
class MyService
{
private FilesystemOperator $filesystem;
public function __construct(FilesystemOperator $acmeFilesystem)
{
$this->filesystem = $acmeFilesystem;
}
}