Skip to content

Instantly share code, notes, and snippets.

@norberttech
Last active July 21, 2024 14:43
Show Gist options
  • Save norberttech/53ce0548842bf10173aa2087b90c9bf6 to your computer and use it in GitHub Desktop.
Save norberttech/53ce0548842bf10173aa2087b90c9bf6 to your computer and use it in GitHub Desktop.
<?php
use function Flow\Azure\SDK\DSL\azure_blob_service;
use function Flow\Azure\SDK\DSL\azure_blob_service_config;
use function Flow\Azure\SDK\DSL\azure_shared_key_authorization_factory;
use function Flow\Filesystem\Bridge\Azure\DSL\azure_filesystem;
use function Flow\Filesystem\Bridge\Azure\DSL\azure_filesystem_options;
use function Flow\Filesystem\DSL\fstab;
use function Flow\Filesystem\DSL\path;
use function Flow\Filesystem\DSL\protocol;
require __DIR__ . '/vendor/autoload.php';
$account = $_ENV['AZURE_STORAGE_ACCOUNT'];
$accountKey = $_ENV['AZURE_STORAGE_ACCOUNT_KEY'];
$container = $_ENV['AZURE_STORAGE_CONTAINER'];
$fstab = fstab(
azure_filesystem(
azure_blob_service(
azure_blob_service_config($account, $container),
azure_shared_key_authorization_factory($account, $accountKey),
),
azure_filesystem_options()
)
);
$stream = $fstab->for(protocol('azure-blob'))->writeTo(path('azure-blob://orders.csv'));
$stream->append('id,name,active');
$stream->append('1,norbert,true');
$stream->append('2,john,true');
$stream->append('3,jane,true');
$stream->close();
<?php
<?php
use function Flow\Azure\SDK\DSL\{azure_blob_service, azure_blob_service_config, azure_shared_key_authorization_factory};
use function Flow\Filesystem\Bridge\Azure\DSL\{azure_filesystem, azure_filesystem_options};
use function Flow\Filesystem\DSL\{fstab, path, protocol};
require __DIR__ . '/vendor/autoload.php';
$account = $_ENV['AZURE_STORAGE_ACCOUNT'];
$accountKey = $_ENV['AZURE_STORAGE_ACCOUNT_KEY'];
$container = $_ENV['AZURE_STORAGE_CONTAINER'];
$fstab = fstab(
azure_filesystem(
azure_blob_service(
azure_blob_service_config($account, $container),
azure_shared_key_authorization_factory($account, $accountKey),
),
azure_filesystem_options()
)
);
$stream = $fstab->for(protocol('azure-blob'))->writeTo(path('azure-blob://orders.csv'));
$stream->append('id,name,active');
$stream->append('1,norbert,true');
$stream->append('2,john,true');
$stream->append('3,jane,true');
$stream->close();
<?php
use Flow\Azure\SDK\AuthorizationFactory\SharedKeyFactory;
use Flow\Azure\SDK\BlobService;
use Flow\Azure\SDK\BlobService\Configuration;
use Flow\Azure\SDK\HttpFactory;
use Flow\Filesystem\Bridge\Azure\AzureBlobFilesystem;
use Flow\Filesystem\Bridge\Azure\Options;
use Flow\Filesystem\FilesystemTable;
use Flow\Filesystem\Path;
use Flow\Filesystem\Protocol;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Log\NullLogger;
require __DIR__ . '/../../vendor/autoload.php';
$account = $_ENV['AZURE_STORAGE_ACCOUNT'];
$accountKey = $_ENV['AZURE_STORAGE_ACCOUNT_KEY'];
$container = $_ENV['AZURE_STORAGE_CONTAINER'];
$fstab = new FilesystemTable(
new AzureBlobFilesystem(
new BlobService(
new Configuration($account, $container),
Psr18ClientDiscovery::find(),
new HttpFactory(Psr17FactoryDiscovery::findRequestFactory(), Psr17FactoryDiscovery::findStreamFactory()),
new BlobService\URLFactory\AzureURLFactory(),
new SharedKeyFactory($account, $accountKey),
new NullLogger(),
),
new Options()
)
);
$stream = $fstab->for(new Protocol('azure-blob'))->writeTo(new Path('azure-blob://orders.csv'));
$stream->append('id,name,active');
$stream->append('1,norbert,true');
$stream->append('2,john,true');
$stream->append('3,jane,true');
$stream->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment