{"id":16233563,"url":"https://github.com/fre5h/vichuploaderserializationbundle","last_synced_at":"2025-10-17T12:35:27.302Z","repository":{"id":45069065,"uuid":"47037751","full_name":"fre5h/VichUploaderSerializationBundle","owner":"fre5h","description":"📦 Provides integration between VichUploaderBundle and JMSSerializerBundle.","archived":false,"fork":false,"pushed_at":"2024-05-07T14:11:13.000Z","size":149,"stargazers_count":46,"open_issues_count":5,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-11T13:12:53.939Z","etag":null,"topics":["bundle","file-upload","jmsserializerbundle","php","serialization","symfony","symfony-bundle","vichuploaderbundle"],"latest_commit_sha":null,"homepage":"https://github.com/fre5h/VichUploaderSerializationBundle","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fre5h.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"fre5h"}},"created_at":"2015-11-28T20:05:05.000Z","updated_at":"2024-09-03T14:13:29.000Z","dependencies_parsed_at":"2024-01-01T14:48:38.671Z","dependency_job_id":"44c0c153-2b28-4e19-a45a-3ae14cab3973","html_url":"https://github.com/fre5h/VichUploaderSerializationBundle","commit_stats":{"total_commits":138,"total_committers":7,"mean_commits":"19.714285714285715","dds":"0.28260869565217395","last_synced_commit":"0b563f9c72a13a7e94fcf12bed6830871ce7f79e"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fre5h%2FVichUploaderSerializationBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fre5h%2FVichUploaderSerializationBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fre5h%2FVichUploaderSerializationBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fre5h%2FVichUploaderSerializationBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fre5h","download_url":"https://codeload.github.com/fre5h/VichUploaderSerializationBundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248666929,"owners_count":21142345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bundle","file-upload","jmsserializerbundle","php","serialization","symfony","symfony-bundle","vichuploaderbundle"],"created_at":"2024-10-10T13:13:05.779Z","updated_at":"2025-10-17T12:35:22.271Z","avatar_url":"https://github.com/fre5h.png","language":"PHP","funding_links":["https://github.com/sponsors/fre5h"],"categories":[],"sub_categories":[],"readme":"# VichUploaderSerializationBundle\n\n:package: Provides integration between [VichUploaderBundle](https://github.com/dustin10/VichUploaderBundle \"VichUploaderBundle\") and\n[JMSSerializerBundle](https://github.com/schmittjoh/JMSSerializerBundle \"JMSSerializerBundle\").\nAllows to generate full or relative URIs to entity fields mapped with `@Vich` and `@JMS` annotations during the serialization.\n\n[![Scrutinizer Quality Score](https://img.shields.io/github/actions/workflow/status/fre5h/VichUploaderSerializationBundle/ci.yaml?branch=main\u0026style=flat-square)](https://scrutinizer-ci.com/g/fre5h/VichUploaderSerializationBundle/)\n[![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+)\n[![CodeCov](https://img.shields.io/codecov/c/github/fre5h/VichUploaderSerializationBundle.svg?style=flat-square)](https://codecov.io/github/fre5h/VichUploaderSerializationBundle)\n[![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)\n[![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)\n[![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)\n[![StyleCI](https://styleci.io/repos/47037751/shield?style=flat-square)](https://styleci.io/repos/47037751)\n[![Gitter](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg?style=flat-square)](https://gitter.im/fre5h/VichUploaderSerializationBundle)\n\n## Requirements 🧐\n\n* PHP 7.3, 7.4, 8.0, 8.1, 8.2\n* Symfony 5.0, 5.1, 5.2, 5.3, 5.4, 6.0, 6.1, 6.2\n\n## Installation 🌱\n\n```composer req fresh/vich-uploader-serialization-bundle='~3.3'```\n\n## Usage 🧑‍🎓\n\nAdd the next class to the `use` section of your entity class.\n\n```php\nuse Fresh\\VichUploaderSerializationBundle\\Annotation as Fresh;\n```\n\nBundle provides two annotations which allow the serialization of `@Vich\\UploadableField` fields in your entities.\nAt first you have to add `@Fresh\\VichSerializableClass` to the entity class which has uploadable fields.\nThen you have to add `@Fresh\\VichSerializableField` annotation to the uploadable field you want to serialize.\n\nAnnotation `@Fresh\\VichSerializableClass` does not have any option.  \nAnnotation `@Fresh\\VichSerializableField` has one required option *value* (or *field*) which value should link to the field with `@Vich\\UploadableField` annotation.\nIt can be set like this `@Fresh\\VichSerializableField(\"photoFile\")` or `@Fresh\\VichSerializableField(field=\"photoFile\")`.\nAlso there is another option `includeHost`, it is not required and by default is set to **true**.\nBut 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)`.\n\nAnd also don't forget that to serialize Vich uploadable fields they also should be marked with `@JMS` annotations to be serialized.\n\nThe generated URI by default:\n\n```json\n{\n  \"photo\": \"http://example.com/uploads/users/photos/5659828fa80a7.jpg\",\n  \"cover\": \"http://example.com/uploads/users/covers/456428fa8g4a8.jpg\",\n}\n```\n\nThe generated URI with `includeHost` set to `false`:\n\n```json\n{\n  \"photo\": \"/uploads/users/photos/5659828fa80a7.jpg\",\n  \"cover\": \"/uploads/users/covers/456428fa8g4a8.jpg\",\n}\n```\n\n### Example of entity with serialized uploadable fields\n\n```php\n\u003c?php\n\nnamespace AppBundle\\Entity;\n\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Fresh\\VichUploaderSerializationBundle\\Annotation as Fresh;\nuse JMS\\Serializer\\Annotation as JMS;\nuse Vich\\UploaderBundle\\Mapping\\Annotation as Vich;\n\n/**\n * @ORM\\Table(name=\"users\")\n * @ORM\\Entity()\n *\n * @Vich\\Uploadable\n * \n * @Fresh\\VichSerializableClass\n */\nclass User\n{\n    /**\n     * @var string\n     *\n     * @ORM\\Column(type=\"string\", length=255)\n     *\n     * @JMS\\Expose\n     * @JMS\\SerializedName(\"photo\")\n     *\n     * @Fresh\\VichSerializableField(\"photoFile\")\n     */\n    private $photoName;\n\n    /**\n     * @var File\n     *\n     * @JMS\\Exclude\n     *\n     * @Vich\\UploadableField(mapping=\"user_photo_mapping\", fileNameProperty=\"photoName\")\n     */\n    private $photoFile;\n    \n    /**\n     * @var string\n     *\n     * @ORM\\Column(type=\"string\", length=255)\n     *\n     * @JMS\\Expose\n     * @JMS\\SerializedName(\"cover\")\n     *\n     * @Fresh\\VichSerializableField(\"coverFile\", includeHost=false)\n     */\n    private $coverName;\n\n    /**\n     * @var File\n     *\n     * @JMS\\Exclude\n     *\n     * @Vich\\UploadableField(mapping=\"user_cover_mapping\", fileNameProperty=\"coverName\")\n     */\n    private $coverFile;    \n}\n```\n\n### Don't make a mistake!\n\nAdditional example of a **wrong usage** of provided annotations to attract your attention.\nUse `@Fresh\\VichSerializableField` **only with** the field which is mapped with `@ORM\\Column`,\nbecause this field is mapped to a database and keeps the name of the stored file.\nDon't use the `@Fresh\\VichSerializableField` with a field which also mapped with `@Vich\\UploadableField`,\nthis is a wrong use case and will throw an exception!\n\nSo the next example is the **incorrect** usage of provided annotations! Don't do so!\n\n```php\n\u003c?php\n\nnamespace AppBundle\\Entity;\n\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Fresh\\VichUploaderSerializationBundle\\Annotation as Fresh;\nuse JMS\\Serializer\\Annotation as JMS;\nuse Vich\\UploaderBundle\\Mapping\\Annotation as Vich;\n\n/**\n * @ORM\\Table(name=\"users\")\n * @ORM\\Entity()\n *\n * @Vich\\Uploadable\n * \n * @Fresh\\VichSerializableClass\n */\nclass User\n{\n    /**\n     * @var string\n     *\n     * @ORM\\Column(type=\"string\", length=255)\n     */\n    private $photoName;\n\n    /**\n     * @var File\n     *\n     * !!! Next three annotations should be moved to the `photoName` property\n     * @JMS\\Expose\n     * @JMS\\SerializedName(\"photo\")\n     * @Fresh\\VichSerializableField(\"photoFile\")\n     *\n     * !!! This annotation should be left here\n     * @Vich\\UploadableField(mapping=\"user_photo_mapping\", fileNameProperty=\"photoName\")\n     */\n    private $photoFile;  \n}\n```\n\n***\n\n## Contributing 🤝\n\nSee [CONTRIBUTING](https://github.com/fre5h/VichUploaderSerializationBundle/blob/master/.github/CONTRIBUTING.md) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffre5h%2Fvichuploaderserializationbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffre5h%2Fvichuploaderserializationbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffre5h%2Fvichuploaderserializationbundle/lists"}