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: 5 months 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 (over 10 years ago)
- Default Branch: main
- Last Pushed: 2024-05-07T14:11:13.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T13:12:53.939Z (over 1 year 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.
[](https://scrutinizer-ci.com/g/fre5h/VichUploaderSerializationBundle/)
[](https://github.com/fre5h/VichUploaderSerializationBundle/actions?query=workflow%3ACI+branch%3Amain+)
[](https://codecov.io/github/fre5h/VichUploaderSerializationBundle)
[](https://packagist.org/packages/fresh/vich-uploader-serialization-bundle)
[](https://packagist.org/packages/fresh/vich-uploader-serialization-bundle)
[](https://packagist.org/packages/fresh/vich-uploader-serialization-bundle)
[](https://styleci.io/repos/47037751)
[](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