Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fre5h/vichuploaderserializationbundle
📦 Provides integration between VichUploaderBundle and JMSSerializerBundle.
https://github.com/fre5h/vichuploaderserializationbundle
bundle file-upload jmsserializerbundle php serialization symfony symfony-bundle vichuploaderbundle
Last synced: 4 days ago
JSON representation
📦 Provides integration between VichUploaderBundle and JMSSerializerBundle.
- Host: GitHub
- URL: https://github.com/fre5h/vichuploaderserializationbundle
- Owner: fre5h
- License: mit
- Created: 2015-11-28T20:05:05.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2024-05-07T14:11:13.000Z (8 months ago)
- Last Synced: 2024-10-11T13:12:53.939Z (2 months ago)
- Topics: bundle, file-upload, jmsserializerbundle, php, serialization, symfony, symfony-bundle, vichuploaderbundle
- Language: PHP
- Homepage: https://github.com/fre5h/VichUploaderSerializationBundle
- Size: 146 KB
- Stars: 46
- Watchers: 3
- Forks: 11
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# VichUploaderSerializationBundle
:package: Provides integration between [VichUploaderBundle](https://github.com/dustin10/VichUploaderBundle "VichUploaderBundle") and
[JMSSerializerBundle](https://github.com/schmittjoh/JMSSerializerBundle "JMSSerializerBundle").
Allows to generate full or relative URIs to entity fields mapped with `@Vich` and `@JMS` annotations during the serialization.[![Scrutinizer Quality Score](https://img.shields.io/github/actions/workflow/status/fre5h/VichUploaderSerializationBundle/ci.yaml?branch=main&style=flat-square)](https://scrutinizer-ci.com/g/fre5h/VichUploaderSerializationBundle/)
[![Build Status](https://img.shields.io/github/workflow/status/fre5h/VichUploaderSerializationBundle/CI/main?style=flat-square)](https://github.com/fre5h/VichUploaderSerializationBundle/actions?query=workflow%3ACI+branch%3Amain+)
[![CodeCov](https://img.shields.io/codecov/c/github/fre5h/VichUploaderSerializationBundle.svg?style=flat-square)](https://codecov.io/github/fre5h/VichUploaderSerializationBundle)
[![License](https://img.shields.io/packagist/l/fresh/vich-uploader-serialization-bundle.svg?style=flat-square)](https://packagist.org/packages/fresh/vich-uploader-serialization-bundle)
[![Latest Stable Version](https://img.shields.io/packagist/v/fresh/vich-uploader-serialization-bundle.svg?style=flat-square)](https://packagist.org/packages/fresh/vich-uploader-serialization-bundle)
[![Total Downloads](https://img.shields.io/packagist/dt/fresh/vich-uploader-serialization-bundle.svg?style=flat-square)](https://packagist.org/packages/fresh/vich-uploader-serialization-bundle)
[![StyleCI](https://styleci.io/repos/47037751/shield?style=flat-square)](https://styleci.io/repos/47037751)
[![Gitter](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg?style=flat-square)](https://gitter.im/fre5h/VichUploaderSerializationBundle)## Requirements 🧐
* PHP 7.3, 7.4, 8.0, 8.1, 8.2
* Symfony 5.0, 5.1, 5.2, 5.3, 5.4, 6.0, 6.1, 6.2## Installation 🌱
```composer req fresh/vich-uploader-serialization-bundle='~3.3'```
## Usage 🧑🎓
Add the next class to the `use` section of your entity class.
```php
use Fresh\VichUploaderSerializationBundle\Annotation as Fresh;
```Bundle provides two annotations which allow the serialization of `@Vich\UploadableField` fields in your entities.
At first you have to add `@Fresh\VichSerializableClass` to the entity class which has uploadable fields.
Then you have to add `@Fresh\VichSerializableField` annotation to the uploadable field you want to serialize.Annotation `@Fresh\VichSerializableClass` does not have any option.
Annotation `@Fresh\VichSerializableField` has one required option *value* (or *field*) which value should link to the field with `@Vich\UploadableField` annotation.
It can be set like this `@Fresh\VichSerializableField("photoFile")` or `@Fresh\VichSerializableField(field="photoFile")`.
Also there is another option `includeHost`, it is not required and by default is set to **true**.
But if you need, you can exclude the host from the generated URI, just use the next variant of the annotation `@Fresh\VichSerializableField("photoFile", includeHost=false)`.And also don't forget that to serialize Vich uploadable fields they also should be marked with `@JMS` annotations to be serialized.
The generated URI by default:
```json
{
"photo": "http://example.com/uploads/users/photos/5659828fa80a7.jpg",
"cover": "http://example.com/uploads/users/covers/456428fa8g4a8.jpg",
}
```The generated URI with `includeHost` set to `false`:
```json
{
"photo": "/uploads/users/photos/5659828fa80a7.jpg",
"cover": "/uploads/users/covers/456428fa8g4a8.jpg",
}
```### Example of entity with serialized uploadable fields
```php