2017 © Pedro Peláez
 

library symfony-form-generator

Generic solution to create forms "on the fly" basing on class metadata

image

lzakrzewski/symfony-form-generator

Generic solution to create forms "on the fly" basing on class metadata

  • Sunday, February 7, 2016
  • by lzakrzewski
  • Repository
  • 0 Watchers
  • 1 Stars
  • 38 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Symfony Form Generator Build Status Coverage Status

This package adds feature for generating symfony forms "on the fly" basing on class metadata like: - Form annotations, - type hints, - phpdoc comments, - validator annotations., (*1)

Created forms are able to submit with raw data (boolean, integer, string, array, real, double, float)., (*2)

Example

Object of given class:, (*3)

use Lzakrzewski\SymfonyFormGenerator\Annotation\Form;
use Symfony\Component\Validator\Constraints as Assert;

class ObjectWithMixedMetadata
{
    /**
     * @var bool
     */
    public $propertyBoolean;

    /**
     * @Assert\Count(max="5")
     */
    public $propertyArray;

    /**
     * @Form\Field("integer", options={"label"="Property Integer"})
     */
    public $propertyInteger;

    public $propertyDateTime;

    public $propertyUndefined;

    public function __construct($propertyBoolean, $propertyArray, $propertyInteger, \DateTime $propertyDateTime, $propertyUndefined)
    {
        $this->propertyBoolean   = $propertyBoolean;
        $this->propertyArray     = $propertyArray;
        $this->propertyInteger   = $propertyInteger;
        $this->propertyDateTime  = $propertyDateTime;
        $this->propertyUndefined = $propertyUndefined;
    }
}

after:, (*4)

$form = GeneratorFactory::createGenerator()
    ->generateFormBuilder(ObjectWithMixedMetadata::class)
    ->getForm();

will have form equivalent:, (*5)

use Lzakrzewski\SymfonyFormGenerator\Form\Type\GeneratorFormType;
use Lzakrzewski\SymfonyFormGenerator\ObjectWithMixedMetadata;
use Symfony\Component\Form\Forms;

Forms::createFormFactory()->createBuilder()
    ->create('form', new GeneratorFormType(ObjectWithMixedMetadata::class))
    ->add('propertyBoolean', 'checkbox')
    ->add('propertyArray', 'generator_array')
    ->add('propertyInteger', 'integer')
    ->add('propertyDateTime', 'generator_datetime')
    ->add('propertyUndefined', 'generator_string');

generator_array type extends collection, generator_datetime type extends datetime, generator_string type extends text., (*6)

generator_* types are custom form types for better support raw values., (*7)

Documentation

Topics: - Installation - Usage - Supported value objects - Guess priorities - Form annotation guess - PHPDoc comment guess - Validator guess - Type hint guess - Custom mapping, (*8)

The Versions

07/02 2016