PHPackages                             sirroland/liip-imagine-serialization-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. [API Development](/categories/api)
4. /
5. sirroland/liip-imagine-serialization-bundle

ActiveSymfony-bundle[API Development](/categories/api)

sirroland/liip-imagine-serialization-bundle
===========================================

Provides integration between LiipImagineBundle and JMSSerializerBundle.

2.0.5(6y ago)0108MITPHPPHP &gt;=7.1.0

Since Mar 10Pushed 6y ago1 watchersCompare

[ Source](https://github.com/sirroland/LiipImagineSerializationBundle)[ Packagist](https://packagist.org/packages/sirroland/liip-imagine-serialization-bundle)[ Docs](https://github.com/bukashk0zzz/LiipImagineSerializationBundle)[ RSS](/packages/sirroland-liip-imagine-serialization-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (10)Versions (17)Used By (0)

Symfony LiipImagineSerialization Bundle
=======================================

[](#symfony-liipimagineserialization-bundle)

[![Build Status](https://camo.githubusercontent.com/a8a456862670babd69b5cb3128d02f3c33ab3aaad7aa22f807d2c384b964bdc0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f42756b6173686b307a7a7a2f4c696970496d6167696e6553657269616c697a6174696f6e42756e646c652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Bukashk0zzz/LiipImagineSerializationBundle)[![Code Coverage](https://camo.githubusercontent.com/1bc749ebf01587da2e8d5e35897a1e380aa9db504792e558e71e3e1811b7b08d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f42756b6173686b307a7a7a2f4c696970496d6167696e6553657269616c697a6174696f6e42756e646c652e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/Bukashk0zzz/LiipImagineSerializationBundle)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a494965b2036c47d364a3b4124ecdb9fbee1bcbd83a849dabb058e32de7775c2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f42756b6173686b307a7a7a2f4c696970496d6167696e6553657269616c697a6174696f6e42756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Bukashk0zzz/LiipImagineSerializationBundle/?branch=master)[![Dependency Status](https://camo.githubusercontent.com/641629004d00d7710e0421d19b4dd06c447c66a823748db24c49066dfdca2542/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3561303937656466306662323466303033313762393430612f62616467652e7376673f7374796c653d666c61742d737175617265)](https://www.versioneye.com/user/projects/5a097edf0fb24f00317b940a)[![License](https://camo.githubusercontent.com/208806ebd09eee1f5c3eb8d57c0fc943bc97c5e52734029ac751e0ed4825629b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f42756b6173686b307a7a7a2f6c6969702d696d6167696e652d73657269616c697a6174696f6e2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Bukashk0zzz/liip-imagine-serialization-bundle)[![Latest Stable Version](https://camo.githubusercontent.com/15c90d69142e290cb13c41a60ed21e559f5a8802583a8be30e3b0e20ab3ef3d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f42756b6173686b307a7a7a2f6c6969702d696d6167696e652d73657269616c697a6174696f6e2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Bukashk0zzz/liip-imagine-serialization-bundle)[![Total Downloads](https://camo.githubusercontent.com/b982468aa7c19ca61c2178388fa44179cfd243b215e207b3a88dbd3c2a0cc2b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f42756b6173686b307a7a7a2f6c6969702d696d6167696e652d73657269616c697a6174696f6e2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Bukashk0zzz/liip-imagine-serialization-bundle)

[![SensioLabsInsight](https://camo.githubusercontent.com/f386222894a52062301e189cc73aa36a0534c7462a61026576e4a5ab0fb08122/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f30313037343738342d656132642d343930322d386136322d3533613566373433626336662f736d616c6c2e706e67)](https://insight.sensiolabs.com/projects/01074784-ea2d-4902-8a62-53a5f743bc6f)[![knpbundles.com](https://camo.githubusercontent.com/7740e794f08043259a6b0a5bbdae26d3a21e705478c9fe67fc57b405db5c8dfc/687474703a2f2f6b6e7062756e646c65732e636f6d2f42756b6173686b307a7a7a2f4c696970496d6167696e6553657269616c697a6174696f6e42756e646c652f62616467652d73686f7274)](http://knpbundles.com/Bukashk0zzz/LiipImagineSerializationBundle)

About
-----

[](#about)

Provides integration between [LiipImagineBundle](https://github.com/liip/LiipImagineBundle "LiipImagineBundle") and [JMSSerializerBundle](https://github.com/schmittjoh/JMSSerializerBundle "JMSSerializerBundle"). Allows to generate full or relative URIs to entity fields mapped with `@Bukashk0zzz` and `@JMS` annotations during the serialization. Also bundle supports [VichUploaderBundle](https://github.com/dustin10/VichUploaderBundle "VichUploaderBundle") field type.

Installation Symfony Flex
-------------------------

[](#installation-symfony-flex)

```
composer config extra.symfony.allow-contrib true
composer require bukashk0zzz/liip-imagine-serialization-bundle
```

Installation without Symfony Flex
---------------------------------

[](#installation-without-symfony-flex)

```
composer require bukashk0zzz/liip-imagine-serialization-bundle
```

Add the bundle to `app/AppKernel.php`

```
$bundles = array(
	// ... other bundles
	new Bukashk0zzz\LiipImagineSerializationBundle\Bukashk0zzzLiipImagineSerializationBundle(),
);
```

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

[](#configuration)

Add this to your `config.yml`:

```
bukashk0zzz_liip_imagine_serialization:
    # Set true for generating url for vichUploader fields
    vichUploaderSerialize: false
    # Set true for generating url with host for vichUploader fields
    includeHost: false
    # Set true for adding original field value to object
    includeOriginal: false
    # Set true for adding host url to original value for vichUploader fields
    includeHostForOriginal: false
    # You can pass there your UrlNormalizer class that implements UrlNormalizerInterface
    originUrlNormalizer: null
    # You can pass there your UrlNormalizer class that implements UrlNormalizerInterface
    filteredUrlNormalizer: null
```

Usage
-----

[](#usage)

Add the next class to the `use` section of your entity class.

```
use Bukashk0zzz\LiipImagineSerializationBundle\Annotation as Bukashk0zzz;
```

Bundle provides two annotations which allow the serialization of url or `@Vich\UploadableField` fields in your entities. At first you have to add `@Bukashk0zzz\LiipImagineSerializableClass` to the entity class which has image fields. Then you have to add `@Bukashk0zzz\LiipImagineSerializableField` annotation to the field you want to serialize.

Annotation `@Bukashk0zzz\LiipImagineSerializableClass` does not have any option.
Annotation `@Bukashk0zzz\LiipImagineSerializableField` has one required option *filter* which value should link to the LiipImagine filter.

It can be set like this `@Bukashk0zzz\LiipImagineSerializableField("photoFile")` or `@Bukashk0zzz\LiipImagineSerializableField(filter="photoFile")`. *filter* can be array of filters in this case serialized field will be also array. For example if you add annotation `@Bukashk0zzz\LiipImagineSerializableField(filter={"big", "small"})` for field `image` then you get:

```
{
  "image": {
             "big": "/uploads/users/big/5659828fa80a7.jpg",
             "small": "/uploads/users/small/5659828fa80a7.jpg"
           }
}
```

Also there is another two options:

- `vichUploaderField` - If you use VichUploaderBundle for your uploads you must specify link to the field with `@Vich\UploadableField` annotation
- `virtualField` - By default serializer will override field value with link to filtered image. If you add `virtualField` option serializer will add to serialized object new field with name that you provided in this option and url to filtered image, original field in this case will be unattached. This option are required if you're using an array of filters.

Don't forget that to serialize image fields they also should be marked with `@JMS` annotations to be serialized.

The generated URI by default:

```
{
  "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`:

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

If you need to change url before passing it to LiipImagine, for example you need to swap origin name, you can use originUrlNormalizer option in bundle config.

```
bukashk0zzz_liip_imagine_serialization:
    originUrlNormalizer: AppBundle\Normalizer\UrlNormalizer
```

If you need to change url after LiipImagine processing, for example you need to swap origin domain, you can use filteredUrlNormalizer option in bundle config.

```
bukashk0zzz_liip_imagine_serialization:
    filteredUrlNormalizer: AppBundle\Normalizer\UrlNormalizer
```

UrlNormalizer class must implement [UrlNormalizerInterface](https://github.com/Bukashk0zzz/LiipImagineSerializationBundle/blob/master/Normalizer/UrlNormalizerInterface.php)

```
