Download the PHP package 1tomany/storage-bundle without Composer

On this page you can find all versions of the php package 1tomany/storage-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package storage-bundle

Storage Bundle for Symfony

This bundle makes it easy to upload files to remote storage services like Amazon S3, Cloudflare R2, Google Cloud Storage, and Azure Blob Storage. Additionally, it provides a mock storage client to easily test your integrations without requiring a network connection.

Installation

Install the bundle using Composer:

If you're using Amazon S3 or an S3 compatible provider like Cloudflare R2, you'll also need to install the AWS SDK bundle provided by Amazon:

Going forward, any mention of Amazon S3 or AWS assumes you're using Amazon S3 itself or a compatible provider.

Configuration

Below is the complete configuration for this bundle. To customize it for your Symfony application, create a file named onetomany_storage.yaml in config/packages/ and make the necessary changes.

onetomany_storage.client

The storage client to use. Possible values are:

These values correspond to the key for each service with the tag onetomany.storage.client. You can add your own client by implementing the OneToMany\StorageBundle\Contract\Client\ClientInterface interface and tagging it with the tag onetomany.storage.client and a key value other than the ones above.

onetomany_storage.client

The bucket where files will be uploaded.

onetomany_storage.custom_url

The URL used to reference the uploaded file instead of the canonical URL returned by the storage service. Set this value if you use Amazon CloudFront or a public Cloudflare R2 bucket domain to get a publicly accessible file URL:

When set, if an object with the key users/10/files/avatar.png was uploaded, the following URL would be returned:

Configuring Amazon S3

Installing the aws/aws-sdk-php-symfony package will create a file named config/packages/aws.yaml and update the .env file with following section:

You should add the following environment variable for modern versions of Symfony as well:

I highly recommend taking advantage of Symfony secrets to store encrypted values of the AWS_KEY and AWS_SECRET environment variables and removing them directly from the .env file.

Configuring Cloudflare R2

The Cloudflare R2 service is an Amazon S3 compatible provider, which means you can use the AWS SDK and bundle as is with one additional environment variable:

Replace <account_id> with the account ID found in the Cloudflare R2 dashboard; it's usually a 32 character hexadecimal string like 45242ae44b7b9f01930a43d617f9f7a8.

You'll also have to update the config/packages/aws.yaml file to use a different region and this environment variable. Change the region key from us-east-1 to auto, and add the endpoint key:

Using actions

This bundle registers a factory in the the Symfony container that will create a storage client object. Each storage client class implements a common interface: OneToMany\StorageBundle\Contract\Client\ClientInterface. When an object of this type is injected into a class, the Symfony container will create the client object defined by the value stored in the onetomany_storage.client property.

However, I do not recommend using an instance of the OneToMany\StorageBundle\Contract\Client\ClientInterface interface directly. Instead, you should use an action class. There are three action interfaces:

Each of these expose a single public function, act(), which calls the underlying OneToMany\StorageBundle\Contract\Client\ClientInterface method to perform the action requested.

The code above would be rewritten as follows:

Action philosophy

The difference is subtle, but I prefer using the action classes for a few reasons:

  1. The interface name indicates the action being performed. By injecting an object of type OneToMany\StorageBundle\Contract\Action\UploadActionInterface, it's clear that you intend for this service to upload a file.
  2. Any non-client-specific pre or post-processing can be handled in the act() method rather than reimplementing it in each storage client class.
  3. They can be mocked in tests easier. Because a concrete object is being injected, only the act() method needs to be mocked. Mocking (or creating an anonymous class of) the OneToMany\StorageBundle\Contract\Client\ClientInterface is more difficult and often overkill for a test that's only testing one action.

Credits

License

The MIT License


All versions of storage-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
ext-fileinfo Version *
psr/container Version ^2.0
psr/http-message Version ^2.0
symfony/config Version ^7.2|^8.0|^8.1
symfony/dependency-injection Version ^7.2|^8.0|^8.1
symfony/filesystem Version ^7.2|^8.0|^8.1
symfony/http-kernel Version ^7.2|^8.0|^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package 1tomany/storage-bundle contains the following files

Loading the files please wait ...