Giter VIP home page Giter VIP logo

hshnserializerextrabundle's Introduction

HshnSerializerExtraBundle

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

This bundle provides some extra features for serialization.

Exporting authorities of objects

# app/config.yml
hshn_serializer_extra:
    authority:
        classes:
            AcmeBundle\Entity\Blog:
                attributes: OWNER
/** @var $serializer JMS\Serializer\Serializer */
$json = $serializer->serialize($blog, 'json');

The access authorities provided by AuthorizationCheckerInterface::isGranted() will be exported to the attribute '_authority' when an object was serialized.

{
    "key": "value",
    "_authority": {
        "OWNER": true
    }
}

Overriding the attribute name

# app/config.yml
hshn_serializer_extra:
    authority:
        export_to: "my_authority"
{
    "key": "value",
    "my_authority": {
        "OWNER": true
    }
}

Restrict exporting the authorities by depth

# app/config.yml
hshn_serializer_extra:
    authority:
        classes:
            AcmeBundle\Entity\Blog:
                attributes: [OWNER]
                max_depth: 0 # default -1 (unlimited)
class Blog
{
}

class User
{
    /**
     * @var Blog
     */
    private $blog;
}

$serializer->serialize($blog, 'json'); // will export the blog authorities (depth 0)
$serializer->serialize($user, 'json'); // will NOT export the blog authorities (depth 1)

Export files as URLs

This feature require VichUploaderBundle

# app/config.yml
hshn_serializer_extra:
    vich_uploader:
        classes:
            AcmeBundle\Entity\Blog:
                files:
                    - { property: picture }
                    - { property: picture, export_to: image }
/** @var $serializer JMS\Serializer\Serializer */
$json = $serializer->serialize($blog, 'json');

Generated URLs will be exported when serializing an object.

{
    "picture": "/url/to/picture",
    "image": "/url/to/picture"
}

Export images as URLs

This feature require LiipImagineBundle

Adding a filter name specification to a file configuration.

# app/config.yml
hshn_serializer_extra:
    vich_uploader:
        classes:
            AcmeBundle\Entity\Blog:
                files:
                    - { property: picture }
                    - { property: picture, export_to: image, filter: thumbnail }
{
    "picture": "/url/to/picture",
    "image": "/url/to/thumbnail/picture"
}

hshnserializerextrabundle's People

Contributors

hshn avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kwn

hshnserializerextrabundle's Issues

Exporting file/image doesn't work with inherited entity

Hello,

I'm trying to export an user's avatar. My user entity extends FOSUserBundle:User. My configuration:

# app/config/config.yml
hshn_serializer_extra:
    vich_uploader:
        classes:
            "App\GeneralBundle\Entity\ProductImage": # this works without any problem
                files:
                    - { property: product, export_to: image }
                    - { property: product, export_to: thumbnail, filter: thumb_square }
            "App\GeneralBundle\Entity\User": # this doesn't work
                files:
                    - { property: avatar, export_to: avatar, filter: thumb_square }

JMS\Expose() annotation works (after using additional directory with metadata). What is more, if I set Expose() to $avatar field in User entity it exposes (as a empty object).

access vich uploader file via method

A nice feature would be to be able to access the vich uploader resource via a method instead of just the property. I need to be able to serve pdf file previews. Thats why I need to have some logic behind it. I tried to get it working by doing it on the doctrine event postLoad but I had no success.

This is how it could look in the config. It might explain what I am looking for more clearly.

hshn_serializer_extra:
    vich_uploader:
        classes:
            AppBundle\Entity\File:
                files:
                    - { property: resource, export_to: original}
                    - { accessor: getPreview, export_to: preview}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.