PHPackages                             devture/symfony-storer-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. devture/symfony-storer-bundle

ActiveSymfony-bundle[File &amp; Storage](/categories/file-storage)

devture/symfony-storer-bundle
=============================

Symfony bundle that lets you deal with uploaded files in a relatively sane and storage-provider-independent way

058PHP

Since Jul 1Pushed 6y ago1 watchersCompare

[ Source](https://github.com/devture/symfony-storer-bundle)[ Packagist](https://packagist.org/packages/devture/symfony-storer-bundle)[ RSS](/packages/devture-symfony-storer-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Description
===========

[](#description)

A Symfony bundle that lets you deal with uploaded files in a relatively sane and storage-provider-independent way.

The [Gaufrette](https://github.com/KnpLabs/Gaufrette) library is used for storage abstraction.

Currently, the following storage adapters can be used through the bundle:

- the local filesystem
- Amazon S3 or Minio
- Azure Blob storage

With minor code changes, all other Gaufrette-supported adapters (see `Helper/AdapterFactory.php`) could be made to work. Pull requests are welcome!

Installation
============

[](#installation)

Install through composer (`composer require --dev devture/symfony-web-command-bundle`).

Add to `config/bundles.php`:

```
Devture\Bundle\StorerBundle\DevtureStorerBundle::class => ['all' => true],
```

Depending on the storage provider that you'd like to use, you may need to install additional libraries (e.g. `aws/aws-sdk-php`, etc.)

Configuration
-------------

[](#configuration)

Drop the following config in `config/packages/devture_storer.yaml`

```
devture_storer:
  adapter_url: '%env(resolve:DEVTURE_STORER_ADAPTER_URL)%'
  validation_max_size_megabytes: 20
```

You then need to define an environment variable `DEVTURE_STORER_ADAPTER_URL`, which would specify which storage adapter you'd like to use.

Example (`.env`):

```
# Local and remote adapters are supported.
#
# Remote URLs usually require that their secrets be urlencoded and percentage-sign-escaped (`/` turned to `%%2F`).
# Reason: `/` found in secrets breaks URL-parsing, so we urlencode it. Symfony thinks % is a parameter, so we escape it (as %%).
#
# Example of S3-compatible Minio URL:
#	DEVTURE_STORER_ADAPTER_URL=s3://access.key:key%%2Fwith%%2Furlencoded%%2Fslashes@us-east-1.localhost:9000/bucket.name
#
# Example of actual Amazon S3 URL:
#	DEVTURE_STORER_ADAPTER_URL=s3://access.key:key%%2Fwith%%2Furlencoded%%2Fslashes@ap-northeast-1.s3.amazonaws.com/bucket.name
#
# Example of actual Azure Blob URL:
#	DEVTURE_STORER_ADAPTER_URL=azure-blob://account-name:account-key%%2Fwith%%2Furlencoded%%2Fslashes@account.blob.core.windows.net/container
DEVTURE_STORER_ADAPTER_URL=file://%kernel.project_dir%/var/devture-storer

```

You also need to register a Doctrine type like this (in `config/doctrine.yaml`):

```
doctrine:
    dbal:
        # Other stuff here ...
        types:
            devture_storer.file: Devture\Bundle\StorerBundle\Doctrine\StorerFileType
```

Usage example
=============

[](#usage-example)

Entity
------

[](#entity)

```
/**
 * @ORM\Table(name="user")
 */
class User implements \Devture\Bundle\StorerBundle\Entity\StorerFilesContainerInterface {

	/**
	 * @ORM\Id
	 * @ORM\Column(type="integer")
	 * @ORM\GeneratedValue(strategy="AUTO")
	 */
	private $id;

	/**
	 * @ORM\Column(type="devture_storer.file", length=191, nullable=true)
	 * @Devture\Bundle\StorerBundle\Validator\Constraints\Image()
	 * @Devture\Bundle\StorerBundle\Validator\Constraints\MaximumSize(maxSizeMegabytes=10)
	 */
	private $photo;

	public function getPhoto(): ?\Devture\Bundle\StorerBundle\Entity\FileInterface {
		return $this->photo;
	}

	public function setPhoto(?\Devture\Bundle\StorerBundle\Entity\FileInterface $photo) {
		$this->photo = $photo;
	}

	/**
	 * {@inheritDoc}
	 * @see \Devture\Bundle\StorerBundle\Entity\StorerFilesContainerInterface::getContainedStorerFiles()
	 */
	public function getContainedStorerFiles(): array {
		$files = [];
		if ($this->photo !== null) {
			$files[] = $this->photo;
		}
		return $files;
	}

}
```

Form Type
---------

[](#form-type)

```
