I have created a Symfony bundle here https://github.com/TorqIT/pimcore-flysystem-azure-bundle that is meant to allow Pimcore (https://pimcore.com/en) to utilize Flysystem to read/write files in an Azure Storage Account. For those who aren't aware, Pimcore is a Symfony-based PIM/CMS/DAM. It contains its own Flysystem configuration, the configuration for which can be seen here https://github.com/pimcore/pimcore/blob/11.x/bundles/CoreBundle/config/pimcore/flysystem.yaml.
My aim is to have my custom bundle's Flysystem configuration override Pimcore's. I am doing this by simply placing my bundle's config.yaml in the config/pimcore directory. It is inconsistent in overriding, however. Sometimes I will find files being written to the filesystem rather than to Azure, but I'm unsure what is causing this. Also, whenever I run bin/console debug:container flysystem or bin/console debug:config flysystem, sometimes I will see the LocalFilesystemAdapter being loaded (i.e. from Pimcore's flysystem.yaml), and sometimes my custom TorqAzureBlobStorageAdapter.
I have looked into Compiler Passes (https://symfony.com/doc/current/service_container/compiler_passes.html) and attempted to implement one like this:
final class FlysystemAzurePass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$pimcoreAdapterServiceIdsToCustomAdapters = [
// Mapping the Pimcore Flysystem Adapter service IDs to our custom adapter classes (see services.yaml)
'flysystem.adapter.pimcore.document_static.storage' => 'document_static_adapter',
'flysystem.adapter.pimcore.asset.storage' => 'assets_adapter',
'flysystem.adapter.pimcore.asset_cache.storage' => 'asset_cache_adapter',
'flysystem.adapter.pimcore.thumbnail.storage' => 'thumbnail_adapter',
'flysystem.adapter.pimcore.version.storage' => 'version_adapter',
'flysystem.adapter.pimcore.recycle_bin.storage' => 'recycle_bin_adapter',
'flysystem.adapter.pimcore.admin.storage' => 'admin_adapter',
'flysystem.adapter.pimcore.email_log.storage' => 'email_log_adapter',
'flysystem.adapter.pimcore.temp.storage' => 'tmp_adapter',
'flysystem.adapter.pimcore.application_log.storage' => 'application_log_adapter',
];
foreach ($pimcoreAdapterServiceIdsToCustomAdapters as $pimcoreServiceId => $customAdapter) {
$definition = $container->getDefinition($pimcoreServiceId);
$definition->setClass($container->getDefinition($customAdapter)->getClass());
}
}
}
However, this results in errors about my custom adapter class not being passed the correct arguments when the container builds it:
Message: TorqIT\FlysystemAzureBundle\TorqAzureBlobStorageAdapter::__construct(): Argument #1 ($client) must be of type MicrosoftAzure\Storage\Blob\BlobRestProxy, string given, called in /var/www/html/var/cache/dev/ContainerQ320XmG/getPimcore_Asset_StorageService.php on line 29
Any thoughts on how I can accomplish this? Thanks in advance.
EDIT: Adding some more context - when I debug, I can see that the arguments being passed to my custom adapter inside the container are the parameters usually intended for the LocalFilesystemAdapter. I have attempted to use the setArgument method in my Compiler Pass to override the arguments, but the container still loads the original arguments, I am assuming due to the order that things are being loaded. I'm unsure if there's another spot I should be doing this, or if I'm off-base entirely on how to override the original config file.