Skip to content

feat: add Azure OSS adapter#181

Open
jonag wants to merge 2 commits into
thephpleague:3.xfrom
jonag:feat/178
Open

feat: add Azure OSS adapter#181
jonag wants to merge 2 commits into
thephpleague:3.xfrom
jonag:feat/178

Conversation

@jonag

@jonag jonag commented Mar 29, 2025

Copy link
Copy Markdown
Contributor

Hello,
Here is my attempt to add support for azure-oss/storage-blob-flysystem to the bundle (#178).
I am not sure about the name I chose to identify the adapter (azureoss), maybe you have a better suggestion?

Jonag

@jonag jonag force-pushed the feat/178 branch 2 times, most recently from 818c9a7 to 1425a52 Compare March 29, 2025 18:16
@jonag

jonag commented Mar 29, 2025

Copy link
Copy Markdown
Contributor Author

Should I find a way to tell PHPUnit to ignore the test if running with PHP < 8.1?

@jonag

jonag commented Mar 29, 2025

Copy link
Copy Markdown
Contributor Author

Actually, since the issue arises from composer install I'm not sure how to fix it without bumping the minimum required PHP version (which we probably want to avoid)...

Removed azure-oss/storage-blob-flysystem from composer.json when testing with PHP 8.0 due to compatibility issues.
@jonag

jonag commented Mar 31, 2025

Copy link
Copy Markdown
Contributor Author

I found a working workaround: removing the dependency from the composer.json when using PHP 8.0. Let me know if you can think of a better solution...

@ZZromanZZ

Copy link
Copy Markdown

Wow, thank you very much @jonag

@maxhelias

Copy link
Copy Markdown
Collaborator

Hi!

Shouldn't we deprecate the use of the old adapter?

This is the second external adapter (BunnyCDN), I think we shloud consider allowing the registration of a custom adapter in the bundle configuration, a bit like Symfony's security component for firewalls.

I'm a bit busy at the moment, but I'd like to explore this possibility before merging them, to avoid any back-and-forth or introducing a BC break.

@jonag

jonag commented Apr 11, 2025

Copy link
Copy Markdown
Contributor Author

Yes I think the old adapter should be deprecated since the "official" blob storage adapter is now abandonned.

Regarding your other comment, if I understand correctly, it means that each custom adapter should create its own bundle that will add its configuration to this bundle? Something like this for example?

@maxhelias

Copy link
Copy Markdown
Collaborator

@jonag Yes exactly. Or another solution if it is better to extend this list: https://github.com/thephpleague/flysystem-bundle/blob/3.x/src/Adapter/AdapterDefinitionFactory.php#L31-L43

jonag added a commit to jonag/flysystem-bundle that referenced this pull request Apr 12, 2025
This PR implements a solution to the issue discussed in thephpleague#181, enabling external bundles to register their custom storage adapters with Flysystem Bundle without requiring them to be directly added to the main bundle's codebase.

I had to remove the  `@internal` annotation from `AdapterDefinitionBuilderInterface` and `AbstractAdapterDefinitionBuilder` to allow them to be referenced by other bundles.

## Usage Example
External bundles can now register their adapters as follows:
``` php
class AzureBlobStorageAdapterBundle extends Bundle
{
    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container): void
    {
        parent::build($container);

        /** @var FlysystemExtension $extension */
        $extension = $container->getExtension('flysystem');
        $extension->addAdapterDefinitionBuilder(new AzureOssAdapterDefinitionBuilder());
    }
}
```
@cancan101

Copy link
Copy Markdown

What is the status of the PR? I would love to see it merged so we can start using the new Azure adapter.

@maxhelias

Copy link
Copy Markdown
Collaborator

I would like to see this approche instead #182

@cancan101

Copy link
Copy Markdown

any updates on getting this merged?

@maxhelias

Copy link
Copy Markdown
Collaborator

Please read my previous message and #186

maxhelias pushed a commit to maxhelias/flysystem-bundle that referenced this pull request Aug 25, 2025
This PR implements a solution to the issue discussed in thephpleague#181, enabling external bundles to register their custom storage adapters with Flysystem Bundle without requiring them to be directly added to the main bundle's codebase.

I had to remove the  `@internal` annotation from `AdapterDefinitionBuilderInterface` and `AbstractAdapterDefinitionBuilder` to allow them to be referenced by other bundles.

## Usage Example
External bundles can now register their adapters as follows:
``` php
class AzureBlobStorageAdapterBundle extends Bundle
{
    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container): void
    {
        parent::build($container);

        /** @var FlysystemExtension $extension */
        $extension = $container->getExtension('flysystem');
        $extension->addAdapterDefinitionBuilder(new AzureOssAdapterDefinitionBuilder());
    }
}
```
@cancan101

Copy link
Copy Markdown

Any updates here? Given the old adapter is deprecated, would be great to use this new Azure library in a Symfony application.

maxhelias pushed a commit to maxhelias/flysystem-bundle that referenced this pull request Feb 5, 2026
This PR implements a solution to the issue discussed in thephpleague#181, enabling external bundles to register their custom storage adapters with Flysystem Bundle without requiring them to be directly added to the main bundle's codebase.

I had to remove the  `@internal` annotation from `AdapterDefinitionBuilderInterface` and `AbstractAdapterDefinitionBuilder` to allow them to be referenced by other bundles.

## Usage Example
External bundles can now register their adapters as follows:
``` php
class AzureBlobStorageAdapterBundle extends Bundle
{
    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container): void
    {
        parent::build($container);

        /** @var FlysystemExtension $extension */
        $extension = $container->getExtension('flysystem');
        $extension->addAdapterDefinitionBuilder(new AzureOssAdapterDefinitionBuilder());
    }
}
```
maxhelias pushed a commit to maxhelias/flysystem-bundle that referenced this pull request Feb 5, 2026
This PR implements a solution to the issue discussed in thephpleague#181, enabling external bundles to register their custom storage adapters with Flysystem Bundle without requiring them to be directly added to the main bundle's codebase.

I had to remove the  `@internal` annotation from `AdapterDefinitionBuilderInterface` and `AbstractAdapterDefinitionBuilder` to allow them to be referenced by other bundles.

## Usage Example
External bundles can now register their adapters as follows:
``` php
class AzureBlobStorageAdapterBundle extends Bundle
{
    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container): void
    {
        parent::build($container);

        /** @var FlysystemExtension $extension */
        $extension = $container->getExtension('flysystem');
        $extension->addAdapterDefinitionBuilder(new AzureOssAdapterDefinitionBuilder());
    }
}
```
maxhelias pushed a commit to maxhelias/flysystem-bundle that referenced this pull request Mar 27, 2026
This PR implements a solution to the issue discussed in thephpleague#181, enabling external bundles to register their custom storage adapters with Flysystem Bundle without requiring them to be directly added to the main bundle's codebase.

I had to remove the  `@internal` annotation from `AdapterDefinitionBuilderInterface` and `AbstractAdapterDefinitionBuilder` to allow them to be referenced by other bundles.

External bundles can now register their adapters as follows:
``` php
class AzureBlobStorageAdapterBundle extends Bundle
{
    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container): void
    {
        parent::build($container);

        /** @var FlysystemExtension $extension */
        $extension = $container->getExtension('flysystem');
        $extension->addAdapterDefinitionBuilder(new AzureOssAdapterDefinitionBuilder());
    }
}
```
maxhelias added a commit to maxhelias/flysystem-bundle that referenced this pull request Mar 27, 2026
This PR implements a solution to the issue discussed in thephpleague#181, enabling external bundles to register their custom storage adapters with Flysystem Bundle without requiring them to be directly added to the main bundle's codebase.

I had to remove the  `@internal` annotation from `AdapterDefinitionBuilderInterface` and `AbstractAdapterDefinitionBuilder` to allow them to be referenced by other bundles.

External bundles can now register their adapters as follows:
``` php
class AzureBlobStorageAdapterBundle extends Bundle
{
    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container): void
    {
        parent::build($container);

        /** @var FlysystemExtension $extension */
        $extension = $container->getExtension('flysystem');
        $extension->addAdapterDefinitionBuilder(new AzureOssAdapterDefinitionBuilder());
    }
}
```
maxhelias added a commit that referenced this pull request Mar 27, 2026
This PR implements a solution to the issue discussed in #181, enabling external bundles to register their custom storage adapters with Flysystem Bundle without requiring them to be directly added to the main bundle's codebase.

I had to remove the  `@internal` annotation from `AdapterDefinitionBuilderInterface` and `AbstractAdapterDefinitionBuilder` to allow them to be referenced by other bundles.

External bundles can now register their adapters as follows:
``` php
class AzureBlobStorageAdapterBundle extends Bundle
{
    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container): void
    {
        parent::build($container);

        /** @var FlysystemExtension $extension */
        $extension = $container->getExtension('flysystem');
        $extension->addAdapterDefinitionBuilder(new AzureOssAdapterDefinitionBuilder());
    }
}
```
@maxhelias

Copy link
Copy Markdown
Collaborator

I just released this PR: #186

@cancan101

Copy link
Copy Markdown

Heads up: I've taken a stab at the package-side implementation @maxhelias hinted at in the comment above, using the AdapterDefinitionBuilderInterface plug-in mechanism shipped in flysystem-bundle 3.7 via #186.

Lives in a new azure-oss/storage-blob-flysystem-symfony sub-package proposed against the azure-oss monorepo: php-oss-for-azure/azure-php#34

If/when that lands and tags a release, this PR can be closed in favour of the package-side implementation — Symfony users would install azure-oss/storage-blob-flysystem-symfony (Symfony Flex auto-registers the bundle) and use the new discoverable config format under flysystem.storages.<name>.azure_oss, without flysystem-bundle needing to ship the Azure-OSS adapter itself.

Posting in case it's useful context for closing the loop on this thread.

cancan101 added a commit to cancan101/azure-storage-php-monorepo that referenced this pull request May 24, 2026
…em adapter

Introduces a new sub-package `azure-oss/storage-blob-flysystem-symfony`
that registers an `azure_oss` adapter shortcut with
`league/flysystem-bundle` 3.7+'s pluggable `AdapterDefinitionBuilderInterface`
(thephpleague/flysystem-bundle#186). This is the canonical extension
point: per-adapter builders now live in the adapter package rather than
being merged into flysystem-bundle's core builder list. The author of
PR thephpleague/flysystem-bundle#181 ("feat: add Azure OSS adapter") was
pointed at #186 as the recommended approach; this package implements
that.

New sub-package: src/BlobFlysystemSymfony/
- AzureOssAdapterDefinitionBuilder: maps the `azure_oss` config key to
  a BlobContainerClient (built via a user-supplied BlobServiceClient
  service id) and the AzureBlobStorageAdapter.
- AzureOssFlysystemBundle: extends Symfony's Bundle and registers the
  builder on flysystem-bundle's FlysystemExtension during build(),
  mirroring how FlysystemBundle wires its own built-in adapters.
- composer.json declares `type: symfony-bundle` so Symfony Flex
  auto-registers the bundle for users who have flex installed.

Configuration shape (see src/BlobFlysystemSymfony/README.md for the
full reference):

    flysystem:
      storages:
        default.storage:
          azure_oss:
            client: azure_blob_service_client
            container: '%env(AZURE_STORAGE_CONTAINER)%'
            # optional: prefix, mime_type_detector,
            # visibility_handling (throw|ignore), public_container

Tests under tests/BlobFlysystemSymfony/:
- AzureOssAdapterDefinitionBuilderTest extends flysystem-bundle's
  AbstractAdapterDefinitionBuilderTest (the same base used by the
  bundle's built-in builders), driving minimal and full option
  fixtures through the Config tree and asserting on the resulting
  Definition objects. Adds extra coverage for getName(),
  getRequiredPackages(), and the null-mime-type-detector path.
- AzureOssFlysystemBundleTest boots a ContainerBuilder, runs both
  FlysystemBundle::build() and AzureOssFlysystemBundle::build() in the
  same order Symfony's Kernel would, and asserts that the azure_oss
  builder is registered on the FlysystemExtension.

Root composer.json gains four require-dev entries needed by the new
package's CI path: `league/flysystem-bundle`, `symfony/config`,
`symfony/dependency-injection`, `symfony/http-kernel`. No other
config changes — autoload PSR-4 `AzureOss\\Storage\\` -> `src/`
already covers the new directory; phpunit.xml's `tests/` glob picks
up the new test suite; phpstan and pint configs apply unchanged.

The new package follows the existing conventions:
- final class with @internal PHPDoc, declare(strict_types=1)
- pint Laravel preset with declare_strict_types + final_internal_class
- PHPStan level 10 + strict-rules clean (no asserts/@var/ignores)

Verification:
- vendor/bin/phpstan analyse --memory-limit=2G : OK
- vendor/bin/phpunit --filter 'BlobFlysystemSymfony' : 8 tests / 32 assertions, all green
- vendor/bin/pint src tests --test : PASS (146 files)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants