2017 © Pedro Pelรกez
 

symfony-bundle vich-uploader-serialization-bundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

image

fresh/vich-uploader-serialization-bundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  • Monday, January 1, 2018
  • by Fresh
  • Repository
  • 2 Watchers
  • 23 Stars
  • 30,499 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 4 Open issues
  • 20 Versions
  • 23 % Grown

The README.md

VichUploaderSerializationBundle

:package: Provides integration between VichUploaderBundle and JMSSerializerBundle. Allows to generate full or relative URIs to entity fields mapped with @Vich and @JMS annotations during the serialization., (*1)

Scrutinizer Quality Score Build Status CodeCov License Latest Stable Version Total Downloads StyleCI Gitter, (*2)

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', (*3)

Usage ๐Ÿง‘โ€๐ŸŽ“

Add the next class to the use section of your entity class., (*4)

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., (*5)

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)., (*6)

And also don't forget that to serialize Vich uploadable fields they also should be marked with @JMS annotations to be serialized., (*7)

The generated URI by default:, (*8)

{
  "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:, (*9)

{
  "photo": "/uploads/users/photos/5659828fa80a7.jpg",
  "cover": "/uploads/users/covers/456428fa8g4a8.jpg",
}

Example of entity with serialized uploadable fields

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Fresh\VichUploaderSerializationBundle\Annotation as Fresh;
use JMS\Serializer\Annotation as JMS;
use Vich\UploaderBundle\Mapping\Annotation as Vich;

/**
 * @ORM\Table(name="users")
 * @ORM\Entity()
 *
 * @Vich\Uploadable
 * 
 * @Fresh\VichSerializableClass
 */
class User
{
    /**
     * @var string
     *
     * @ORM\Column(type="string", length=255)
     *
     * @JMS\Expose
     * @JMS\SerializedName("photo")
     *
     * @Fresh\VichSerializableField("photoFile")
     */
    private $photoName;

    /**
     * @var File
     *
     * @JMS\Exclude
     *
     * @Vich\UploadableField(mapping="user_photo_mapping", fileNameProperty="photoName")
     */
    private $photoFile;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=255)
     *
     * @JMS\Expose
     * @JMS\SerializedName("cover")
     *
     * @Fresh\VichSerializableField("coverFile", includeHost=false)
     */
    private $coverName;

    /**
     * @var File
     *
     * @JMS\Exclude
     *
     * @Vich\UploadableField(mapping="user_cover_mapping", fileNameProperty="coverName")
     */
    private $coverFile;    
}

Don't make a mistake!

Additional example of a wrong usage of provided annotations to attract your attention. Use @Fresh\VichSerializableField only with the field which is mapped with @ORM\Column, because this field is mapped to a database and keeps the name of the stored file. Don't use the @Fresh\VichSerializableField with a field which also mapped with @Vich\UploadableField, this is a wrong use case and will throw an exception!, (*10)

So the next example is the incorrect usage of provided annotations! Don't do so!, (*11)

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Fresh\VichUploaderSerializationBundle\Annotation as Fresh;
use JMS\Serializer\Annotation as JMS;
use Vich\UploaderBundle\Mapping\Annotation as Vich;

/**
 * @ORM\Table(name="users")
 * @ORM\Entity()
 *
 * @Vich\Uploadable
 * 
 * @Fresh\VichSerializableClass
 */
class User
{
    /**
     * @var string
     *
     * @ORM\Column(type="string", length=255)
     */
    private $photoName;

    /**
     * @var File
     *
     * !!! Next three annotations should be moved to the `photoName` property
     * @JMS\Expose
     * @JMS\SerializedName("photo")
     * @Fresh\VichSerializableField("photoFile")
     *
     * !!! This annotation should be left here
     * @Vich\UploadableField(mapping="user_photo_mapping", fileNameProperty="photoName")
     */
    private $photoFile;  
}

Contributing ๐Ÿค

See CONTRIBUTING file., (*12)

The Versions

01/01 2018
11/12 2017
11/12 2017

2.x-dev

2.9999999.9999999.9999999-dev https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Artem Henvald

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

08/12 2017
04/12 2017

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Artem Henvald

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

04/12 2017

v1.1.1

1.1.1.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Artem Henvald

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

04/12 2017

v1.1.0

1.1.0.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Artem Henvald

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

03/08 2017

v1.0.11

1.0.11.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

03/08 2017

dev-develop

dev-develop https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

12/11 2016

v1.0.10

1.0.10.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

07/10 2016

v1.0.9

1.0.9.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

09/06 2016

v1.0.8

1.0.8.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

08/06 2016

v1.0.7

1.0.7.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

01/06 2016

v1.0.6

1.0.6.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

21/03 2016

v1.0.5

1.0.5.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

07/01 2016

v1.0.4

1.0.4.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

18/12 2015

v1.0.3

1.0.3.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

17/12 2015

v1.0.2

1.0.2.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

03/12 2015

v1.0.1

1.0.1.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle

29/11 2015

v1.0.0

1.0.0.0 https://github.com/fre5h/VichUploaderSerializationBundle

Provides integration between VichUploaderBundle and JMSSerializerBundle.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle serialization symfony upload file upload integration jmsserializerbundle vichuploaderbundle