{"id":16960683,"url":"https://github.com/bukashk0zzz/liipimagineserializationbundle","last_synced_at":"2025-07-09T13:09:58.185Z","repository":{"id":5582536,"uuid":"53334450","full_name":"Bukashk0zzz/LiipImagineSerializationBundle","owner":"Bukashk0zzz","description":"Provides integration between LiipImagineBundle and JMSSerializerBundle","archived":false,"fork":false,"pushed_at":"2022-01-26T06:49:43.000Z","size":101,"stargazers_count":25,"open_issues_count":2,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-20T13:56:00.647Z","etag":null,"topics":["bundle","jmsserializerbundle","liipimaginebundle","php","symfony","symfony-bundle","symfony3-bundle","vichuploaderbundle"],"latest_commit_sha":null,"homepage":null,"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/Bukashk0zzz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-07T15:06:47.000Z","updated_at":"2024-07-25T09:33:21.000Z","dependencies_parsed_at":"2022-08-06T19:00:31.771Z","dependency_job_id":null,"html_url":"https://github.com/Bukashk0zzz/LiipImagineSerializationBundle","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/Bukashk0zzz/LiipImagineSerializationBundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bukashk0zzz%2FLiipImagineSerializationBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bukashk0zzz%2FLiipImagineSerializationBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bukashk0zzz%2FLiipImagineSerializationBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bukashk0zzz%2FLiipImagineSerializationBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bukashk0zzz","download_url":"https://codeload.github.com/Bukashk0zzz/LiipImagineSerializationBundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bukashk0zzz%2FLiipImagineSerializationBundle/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264465878,"owners_count":23612584,"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","jmsserializerbundle","liipimaginebundle","php","symfony","symfony-bundle","symfony3-bundle","vichuploaderbundle"],"created_at":"2024-10-13T22:49:47.833Z","updated_at":"2025-07-09T13:09:58.169Z","avatar_url":"https://github.com/Bukashk0zzz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Symfony LiipImagineSerialization Bundle\n\n[![Build Status](https://img.shields.io/scrutinizer/build/g/Bukashk0zzz/LiipImagineSerializationBundle.svg?style=flat-square)](https://travis-ci.org/Bukashk0zzz/LiipImagineSerializationBundle)\n[![Code Coverage](https://img.shields.io/codecov/c/github/Bukashk0zzz/LiipImagineSerializationBundle.svg?style=flat-square)](https://codecov.io/github/Bukashk0zzz/LiipImagineSerializationBundle)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/Bukashk0zzz/LiipImagineSerializationBundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/Bukashk0zzz/LiipImagineSerializationBundle/?branch=master)\n[![License](https://img.shields.io/packagist/l/Bukashk0zzz/liip-imagine-serialization-bundle.svg?style=flat-square)](https://packagist.org/packages/Bukashk0zzz/liip-imagine-serialization-bundle)\n[![Latest Stable Version](https://img.shields.io/packagist/v/Bukashk0zzz/liip-imagine-serialization-bundle.svg?style=flat-square)](https://packagist.org/packages/Bukashk0zzz/liip-imagine-serialization-bundle)\n[![Total Downloads](https://img.shields.io/packagist/dt/Bukashk0zzz/liip-imagine-serialization-bundle.svg?style=flat-square)](https://packagist.org/packages/Bukashk0zzz/liip-imagine-serialization-bundle)\n\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/01074784-ea2d-4902-8a62-53a5f743bc6f/small.png)](https://insight.sensiolabs.com/projects/01074784-ea2d-4902-8a62-53a5f743bc6f)\n\nAbout\n-----\n\nProvides integration between [LiipImagineBundle](https://github.com/liip/LiipImagineBundle \"LiipImagineBundle\") and\n[JMSSerializerBundle](https://github.com/schmittjoh/JMSSerializerBundle \"JMSSerializerBundle\").\nAllows to generate full or relative URIs to entity fields mapped with `@Bukashk0zzz` and `@JMS` annotations during the serialization.\nAlso bundle supports [VichUploaderBundle](https://github.com/dustin10/VichUploaderBundle \"VichUploaderBundle\") field type.\n\nInstallation Symfony Flex\n------------\n\n```bash\ncomposer config extra.symfony.allow-contrib true\ncomposer require bukashk0zzz/liip-imagine-serialization-bundle\n```\n\nInstallation without Symfony Flex\n------------\n\n```bash\ncomposer require bukashk0zzz/liip-imagine-serialization-bundle\n```\n\nAdd the bundle to `app/AppKernel.php`\n\n```php\n$bundles = array(\n\t// ... other bundles\n\tnew Bukashk0zzz\\LiipImagineSerializationBundle\\Bukashk0zzzLiipImagineSerializationBundle(),\n);\n```\n\nConfiguration\n-------------\n\nAdd this to your `config.yml`:\n\n```yaml\nbukashk0zzz_liip_imagine_serialization:\n    # Set true for generating url for vichUploader fields\n    vichUploaderSerialize: false\n    # Set true for generating url with host for vichUploader fields\n    includeHost: false\n    # Set true for adding original field value to object\n    includeOriginal: false\n    # Set true for adding host url to original value for vichUploader fields\n    includeHostForOriginal: false\n    # You can pass there your UrlNormalizer class that implements UrlNormalizerInterface\n    originUrlNormalizer: null\n    # You can pass there your UrlNormalizer class that implements UrlNormalizerInterface\n    filteredUrlNormalizer: null\n```\n\n\nUsage\n-----\n\nAdd the next class to the `use` section of your entity class.\n\n```php\nuse Bukashk0zzz\\LiipImagineSerializationBundle\\Annotation as Bukashk0zzz;\n```\n\nBundle provides two annotations which allow the serialization of url or `@Vich\\UploadableField` fields in your entities.\nAt first you have to add `@Bukashk0zzz\\LiipImagineSerializableClass` to the entity class which has image fields.\nThen you have to add `@Bukashk0zzz\\LiipImagineSerializableField` annotation to the field you want to serialize.\n\nAnnotation `@Bukashk0zzz\\LiipImagineSerializableClass` does not have any option.  \nAnnotation `@Bukashk0zzz\\LiipImagineSerializableField` has one required option *filter* which value should link to the LiipImagine filter.\n\nIt can be set like this `@Bukashk0zzz\\LiipImagineSerializableField(\"photoFile\")` or `@Bukashk0zzz\\LiipImagineSerializableField(filter=\"photoFile\")`. \n*filter* can be array of filters in this case serialized field will be also array.\nFor example if you add annotation `@Bukashk0zzz\\LiipImagineSerializableField(filter={\"big\", \"small\"})` for field `image`  then you get:\n\n```json\n{\n  \"image\": {\n             \"big\": \"/uploads/users/big/5659828fa80a7.jpg\",\n             \"small\": \"/uploads/users/small/5659828fa80a7.jpg\"\n           }\n}\n```\n\nAlso there is another two options: \n- `vichUploaderField` - If you use VichUploaderBundle for your uploads you must specify link to the field with `@Vich\\UploadableField` annotation \n- `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.\n\nDon't forget that to serialize image 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\nIf 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.\n```yaml\nbukashk0zzz_liip_imagine_serialization:\n    originUrlNormalizer: AppBundle\\Normalizer\\UrlNormalizer\n```\n\nIf you need to change url after LiipImagine processing, for example you need to swap origin domain, you can use filteredUrlNormalizer option in bundle config.\n```yaml\nbukashk0zzz_liip_imagine_serialization:\n    filteredUrlNormalizer: AppBundle\\Normalizer\\UrlNormalizer\n```\n\nUrlNormalizer class must implement [UrlNormalizerInterface](https://github.com/Bukashk0zzz/LiipImagineSerializationBundle/blob/master/Normalizer/UrlNormalizerInterface.php)\n\n```php\n\u003c?php\n\nnamespace AppBundle\\Normalizer;\n\nuse Bukashk0zzz\\LiipImagineSerializationBundle\\Normalizer\\UrlNormalizerInterface;\n\n/**\n * Url normalizer\n */\nclass UrlNormalizer implements UrlNormalizerInterface\n{    \n    /**\n    * {@inheritdoc} \n    */\n    public function normalize($url){\n        return str_replace('photo.jpg', 'my_photo.jpg', $url);\n    }\n}\n```\n\nEvents\n-------\nThere are two events:\n- bukashk0zzz_liip_imagine.event_pre_origin_normalize // Dispatch before origin url normalization\n- bukashk0zzz_liip_imagine.event_pre_filtered_normalize // Dispatch before filtered url normalization\n\n**Example subscriber:**\n```yaml\nservices:\n    app.liip_imagine_serialization_subscriber:\n        class: AppBundle\\Subscribers\\LiipImagineSerializationEventSubscriber\n        tags:\n            - { name: bukashk0zzz_liip_imagine_subscriber }\n```\n\n```php\n\u003c?php\n\nnamespace AppBundle\\Subscribers;\n\nuse Bukashk0zzz\\LiipImagineSerializationBundle\\Event\\UrlNormalizerEvent;\nuse Symfony\\Component\\EventDispatcher\\EventSubscriberInterface;\n\n/**\n * LiipImagineSerializationEventSubscriber\n */\nclass LiipImagineSerializationEventSubscriber implements EventSubscriberInterface\n{\n    /**\n     * @return array\n     */\n    public static function getSubscribedEvents()\n    {\n        return [\n            UrlNormalizerEvent::ORIGIN =\u003e [\n                ['normalizeOrigin', 10],\n            ],\n            UrlNormalizerEvent::FILTERED =\u003e [\n                ['normalizeFiltered', 10],\n            ],\n        ];\n    }\n\n    /**\n     * @param UrlNormalizerEvent $event\n     */\n    public function normalizeOrigin(UrlNormalizerEvent $event)\n    {\n        $event-\u003esetUrl(str_replace('photo', 'newPhoto', $event-\u003egetUrl()));\n    }\n\n    /**\n     * @param UrlNormalizerEvent $event\n     */\n    public function normalizeFiltered(UrlNormalizerEvent $event)\n    {\n        $event-\u003esetUrl(str_replace('example.com', 'img.example.com', $event-\u003egetUrl()));\n    }\n}\n```\n\n\nExample\n-------\n\n```php\n\u003c?php\n\nnamespace AppBundle\\Entity;\n\nuse Doctrine\\ORM\\Mapping as ORM;\nuse JMS\\Serializer\\Annotation as JMS;\nuse Vich\\UploaderBundle\\Mapping\\Annotation as Vich;\nuse Bukashk0zzz\\LiipImagineSerializationBundle\\Annotation as Bukashk0zzz;\nuse Symfony\\Component\\HttpFoundation\\File\\File;\n\n/**\n * User Entity\n *\n * @ORM\\Table(name=\"users\")\n * @ORM\\Entity()\n *\n * @Vich\\Uploadable\n * @Bukashk0zzz\\LiipImagineSerializableClass\n */\nclass User\n{    \n    /**\n     * @var string $coverUrl Cover url\n     *\n     * @ORM\\Column(type=\"string\", length=255)\n     *\n     * @JMS\\Expose\n     * @JMS\\SerializedName(\"cover\")\n     *\n     * @Bukashk0zzz\\LiipImagineSerializableField(\"thumb_filter\")\n     */\n    public $coverUrl; \n    \n    /**\n     * @var string $photoName Photo name\n     *\n     * @ORM\\Column(type=\"string\", length=255)\n     *\n     * @JMS\\Expose\n     * @JMS\\SerializedName(\"photo\")\n     *\n     * @Bukashk0zzz\\LiipImagineSerializableField(\"thumb_filter\", vichUploaderField=\"photoFile\")\n     */\n    public $photoName;\n\n    /**\n     * @var File $photoFile Photo file\n     *\n     * @JMS\\Exclude\n     *\n     * @Vich\\UploadableField(mapping=\"user_photo_mapping\", fileNameProperty=\"photoName\")\n     */\n    public $photoFile;\n}\n```\n\nCopyright / License\n-------------------\n\nSee [LICENSE](https://github.com/bukashk0zzz/LiipImagineSerializationBundle/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbukashk0zzz%2Fliipimagineserializationbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbukashk0zzz%2Fliipimagineserializationbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbukashk0zzz%2Fliipimagineserializationbundle/lists"}