feature #1330 Add the possibility to register forms as services (skalpa)
This PR was squashed before being merged into the 2.0.x-dev branch (closes #1330). Discussion ---------- Add the possibility to register forms as services This allows you to register your form types / form types extensions / form types guessers as Silex services: ```php $app['your.type.service'] = function ($app) { return new YourServiceFormType(); }; $app->extend('form.types', function ($types) use ($app) { $types[] = 'your.type.service'; return $types; })); ... $builder = $app['form.factory']->createBuilder('your.type.service'); ``` This is particularly useful for users of Symfony 3.x, now that `FormFactory::createBuilder()` and friends don't allow you to pass an instance of `FormTypeInterface` anymore, preventing you from loading form types that require constructor arguments lazily (without the patch you have to add objects to the `form.types` / `form.type.extensions` / `form.type.guessers` parameters which means every single form of your application will have to get instantiated whenever you use the form component). The patch contains a new `SilexFormExtension` extension class that handles the dereferencing of services names / lazy loading, new tests, and documentation fixes. Other quick notes: * No type checking is performed by the extension, but that's consistent with the way the `FormServiceProvider` works without the patch. Nevertheless, I believe this should be enhanced and will be ready to work on this after the merge if you reckon that would be a good idea. * I had to change the `DummyFormType` declaration in the tests. You used a class with a `getName()` method with Symfony < 2.8 and one without the method with 2.8+. Now the problem is that the `FormRegistry` from 2.8.x still uses the `getName()` method to store form types, which means it is still needed in some cases. Thus for my tests to pass I had to make sure the class with `getName()` was used with any 2.x version while the one without it was only used with 3.x Commits ------- cfcfa143 Add the possibility to register forms as services
Showing
Please register or sign in to comment