PHP code example of 1tomany / storage-bundle

1. Go to this page and download the library: Download 1tomany/storage-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

1tomany / storage-bundle example snippets




namespace App\File\Action\Handler;

use OneToMany\StorageBundle\Record\RemoteFileRecord;
use OneToMany\StorageBundle\Request\UploadFileRequest;
use OneToMany\StorageBundle\Service\StorageServiceInterface;

final readonly class UploadFileHandler
{
    public function __construct(private StorageServiceInterface $storageService)
    {
        // $storageService is an instance of OneToMany\StorageBundle\Service\AwsStorageService
        // if the STORAGE_SERVICE environment variable is set to "aws".
    }

    public function __invoke(string $filePath, string $remoteKey): void
    {
        $record = $this->storageService->upload(
            UploadFileRequest::public(...[
                'filePath' => $filePath,
                'remoteKey' => $remoteKey,
            ])
        );

        // assert($record instanceof RemoteFileRecord);
    }
}



namespace App\File\Action\Handler;

use OneToMany\StorageBundle\Action\UploadFileAction;
use OneToMany\StorageBundle\Record\RemoteFileRecord;
use OneToMany\StorageBundle\Request\UploadFileRequest;

final readonly class UploadFileHandler
{
    public function __construct(private UploadFileAction $uploadFileAction)
    {
    }

    public function __invoke(string $filePath, string $remoteKey): void
    {
        $record = $this->uploadFileAction->act(
            UploadFileRequest::public(...[
                'filePath' => $filePath,
                'remoteKey' => $remoteKey,
            ])
        );

        // assert($record instanceof RemoteFileRecord);
    }
}

composer