lzakrzewski / symfony-form-generator
Generic solution to create forms "on the fly" basing on class metadata
0.0.3
2016-02-07 14:10 UTC
Requires
- php: >=5.5
- doctrine/annotations: ~1.0
- phpdocumentor/reflection-docblock: ~2.0
- phpdocumentor/type-resolver: ~0.1
- symfony/form: ~2.6
- symfony/validator: ~2.6
Requires (Dev)
- mathiasverraes/money: ~1.0
- phpunit/phpunit: ~4.8
- ramsey/uuid: ~3.0
- satooshi/php-coveralls: ^0.6.1
This package is not auto-updated.
Last update: 2024-11-09 19:19:53 UTC
README
This package adds feature for generating symfony
forms "on the fly" basing on class metadata like:
Form
annotations,- type hints,
- phpdoc comments,
- validator annotations.
Created forms are able to submit with raw data (boolean
, integer
, string
, array
, real
, double
, float
).
Example
Object of given class:
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:
$form = GeneratorFactory::createGenerator() ->generateFormBuilder(ObjectWithMixedMetadata::class) ->getForm();
will have form
equivalent:
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
.
generator_*
types are custom form types for better support raw values.
Documentation
Topics: