acseo / cegid-rfe-connect
Requires
- symfony/cache: ^7.2
- symfony/http-client: ^7.2
Requires (Dev)
- phpunit/phpunit: ^11.5
- symfony/dotenv: ^7.2
This package is auto-updated.
Last update: 2025-02-03 16:30:12 UTC
README
This PHP package provides functionality to interact with Azure Blob Storage using SAS tokens. It includes authentication, listing files in a folder, and retrieving a file from storage.
๐ฆ Installation
To install this package, run:
composer require acseo/cegid-rfe-connect
This will install all required dependencies, including:
symfony/http-client
symfony/cache
symfony/dotenv
(for testing)phpunit/phpunit
(for testing)
๐ Usage
Authentication
The Auth\Token
class handles authentication and retrieves an access token from the API.
$httpClient = HttpClient::create(); $cache = new FilesystemAdapter(); $tokenService = new Auth\Token($httpClient, $cache, $clientId, $username, $password, $tokenUrl, $cacheDuration); $token = $auth->getToken();
Fetching a SAS Token
The Auth\SasToken
class retrieves a SAS token to access Azure Blob Storage.
$sasTokenService = new Auth\SasToken($httpClient, $cache, $tokenService, $sasTokenUrl, $cacheDuration); $sasToken = $sasTokenService->getSasToken($tenantId, $storagePath);
Listing Files in a Folder
The RFE\Folder\ListFiles
class lists files within a given folder in the blob storage.
$listFiles = new RFE\Folder\ListFiles($httpClient, $sasToken); $files = $listFiles->listFiles($'some-folder/');
Retrieving a File
The RFE\File\GetFile
class fetches the contents of a file stored in Azure Blob Storage.
$getFile = new RFE\File\GetFile($httpClient, $sasToken); $fileContent = $getFile->getFile('some-folder/myfile.txt');
๐งช Running Tests
Create a .env.test
file by copying the .env.test.dist
template:
cp .env.test.dist .env.test
Then, update .env.test
with the required values:
CLIENT_ID=your_client_id CLIENT_SECRET=your_client_secret USERNAME=your_username PASSWORD=your_password TOKEN_URL=your_token_url CACHE_DURATION=3600 SAS_TOKEN_URL=your_sas_token_url TENANT_ID=your_tenant_id STORAGE_PATH=your_storage_path FILE_PATH=your_file_path FOLDER_PATH=your_folder_path
To execute the PHPUnit test suite, run:
composer test
This will run unit tests for authentication, SAS token retrieval, file listing, and file fetching.
๐ Notes
- Ensure your
.env.test
file contains valid credentials before running tests. - Check the Azure Blob Storage permissions when using SAS tokens.
๐ References
Enjoy using acseo/cegid-rfe-connect
! ๐