2017 © Pedro Peláez
 

symfony-bundle dataview-bundle

Make configuring different serialization views for your entities easy and maintainable.

image

samson/dataview-bundle

Make configuring different serialization views for your entities easy and maintainable.

  • Tuesday, August 26, 2014
  • by SamsonIT
  • Repository
  • 13 Watchers
  • 9 Stars
  • 726 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

README

Example of use

// class
class SampleDataView extends AbstractType
{
    public function getName()
    {
        return 'sample';
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name_of_key', 'type_of_key', array('property_path' => 'optionalPath', /** other options */))
            ->add('children', 'collection', array('type' => new ChildDataView())
        ;

        $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $e) {
            $e->getForm()->add('new_key', 'type_of_key', array('mapped' => false, 'data' => $e->getData()->getSomeCustomData());
        }

        // or you can use this convenience method:
        $builder->addFixed('new_key', 'type_of_key', function($data) { return $data->getSomeCustomData(); });
    }
}

// use
$view = $container->get('samson.dataview.factory')->create(new SampleDataView(), $sample);
$data = $view->createView()->getData();

// $data is now something like:
// array( 'name_of_key' => 'value_of_$entity->getOptionalPath()', 'children' => array(array(), array(), array(), 'etc' ), 'new_key' => 'value_of_$entity->getSomeCustomData()' );

If your object is a doctrine entity, you can let the guessers so the work for you:, (*1)

class SampleDataView extends AbstractType
{
    public function getName()
    {
        return 'sample';
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name_of_key')
            ->add('children')
        ;
    }
}

By default, if a one-to-many or many-to-many collection is encountered, the type "collection" will be setup with the option type set to entity. The entity type by default will try to convert your entity to an array with keys id and name, the latter being the object cast to string., (*2)

Introduction

The DataViewBundle is based in great upon the Form component in symfony. It makes use of the FormView part to convert an object scheme into a basic array, making full use of the flexibility the Form component offers., (*3)

A problem often encountered, for example, is having a situation where you want to serialize a "Project" entity with all it's "Product" children in one controller, and a "Product" entity with it's "Product" parent in the other. In order to prevent an endless serialization loop, either make use of the options to tell each type what to include and what not, or simply add the relevant fields to the View from the controller., (*4)

The Versions

26/08 2014

dev-master

9999999-dev https://github.com/SamsonIT/DataViewBundle

Make configuring different serialization views for your entities easy and maintainable.

  Sources   Download

MIT

The Requires

 

by Erik Roelofs

serializer symfony view

21/03 2014

2.0.0

2.0.0.0 https://github.com/SamsonIT/DataViewBundle

Make configuring different serialization views for your entities easy and maintainable.

  Sources   Download

MIT

The Requires

 

by Erik Roelofs

serializer symfony view

14/11 2013

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/SamsonIT/DataViewBundle

Make configuring different serialization views for your entities easy and maintainable.

  Sources   Download

MIT

The Requires

 

by Erik Roelofs

serializer symfony view

14/11 2013

1.0.1

1.0.1.0 https://github.com/SamsonIT/DataViewBundle

Make configuring different serialization views for your entities easy and maintainable.

  Sources   Download

MIT

The Requires

 

by Erik Roelofs

serializer symfony view

18/07 2013

1.0.0

1.0.0.0 https://github.com/SamsonIT/DataViewBundle

Make configuring different serialization views for your entities easy and maintainable.

  Sources   Download

MIT

The Requires

 

by Erik Roelofs

serializer symfony view