├── src ├── Resources │ └── config │ │ └── services.yaml ├── HostnetFormHandlerBundle.php └── Registry │ └── LegacyHandlerRegistry.php ├── LICENSE ├── composer.json └── README.md /src/Resources/config/services.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | form_handler.provider.simple: 3 | class: Hostnet\Component\Form\Simple\SimpleFormProvider 4 | arguments: 5 | - "@form.factory" 6 | 7 | hostnet.form_handler.registry: 8 | class: Hostnet\Bundle\FormHandlerBundle\Registry\LegacyHandlerRegistry 9 | arguments: 10 | - "@service_container" 11 | - !tagged_iterator form.handler 12 | 13 | hostnet.form_handler.factory: 14 | class: Hostnet\Component\FormHandler\HandlerFactory 15 | arguments: 16 | - "@form.factory" 17 | - "@hostnet.form_handler.registry" 18 | 19 | Hostnet\Component\Form\FormProviderInterface: '@form_handler.provider.simple' 20 | Hostnet\Component\FormHandler\HandlerFactoryInterface: '@hostnet.form_handler.factory' 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Hostnetbv 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /src/HostnetFormHandlerBundle.php: -------------------------------------------------------------------------------- 1 | load('services.yaml'); 26 | 27 | parent::build($container); 28 | $container->registerForAutoconfiguration(FormHandlerInterface::class)->addTag('form.handler'); 29 | $container->registerForAutoconfiguration(HandlerTypeInterface::class)->addTag('form.handler'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Registry/LegacyHandlerRegistry.php: -------------------------------------------------------------------------------- 1 | handlers = $handlers; 31 | $this->container = $container; 32 | } 33 | 34 | /** 35 | * {@inheritdoc} 36 | */ 37 | public function getType($class) 38 | { 39 | foreach ($this->handlers as $handler) { 40 | if ($handler::class !== $class) { 41 | continue; 42 | } 43 | 44 | if ($handler instanceof FormHandlerInterface) { 45 | return new HandlerTypeAdapter($handler); 46 | } 47 | 48 | return $handler; 49 | } 50 | 51 | throw new InvalidHandlerTypeException($class); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hostnet/form-handler-bundle", 3 | "type": "symfony-bundle", 4 | "description": "Hostnet form handler to provide an easier way of handling forms in actions", 5 | "license": "MIT", 6 | "minimum-stability": "stable", 7 | "require": { 8 | "php": "^8.1", 9 | "hostnet/form-handler-component": "^1.7.3", 10 | "symfony/expression-language": "^6.4|^7.0", 11 | "symfony/http-foundation": "^6.4|^7.0" 12 | }, 13 | "require-dev": { 14 | "hostnet/phpcs-tool": "^9.1.0", 15 | "phpunit/phpunit": "^9.5.5", 16 | "symfony/browser-kit": "^6.4|^7.0", 17 | "symfony/finder": "^6.4|^7.0", 18 | "symfony/form": "^6.4|^7.0", 19 | "symfony/framework-bundle": "^6.4|^7.0", 20 | "symfony/http-kernel": "^6.4|^7.0", 21 | "symfony/phpunit-bridge": "^6.4|^7.0", 22 | "symfony/translation": "^6.4|^7.0", 23 | "symfony/validator": "^6.4|^7.0", 24 | "symfony/yaml": "^6.4|^7.0" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "Hostnet\\Bundle\\FormHandlerBundle\\": "src/" 29 | } 30 | }, 31 | "autoload-dev": { 32 | "psr-4": { 33 | "Hostnet\\Bundle\\FormHandlerBundle\\": "test/" 34 | }, 35 | "files": [ 36 | "test/Functional/Fixtures/TestKernel.php" 37 | ] 38 | }, 39 | "config": { 40 | "allow-plugins": { 41 | "hostnet/*": true, 42 | "dealerdirect/phpcodesniffer-composer-installer": false 43 | } 44 | }, 45 | "archive": { 46 | "exclude": [ 47 | "/test" 48 | ] 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
4 | 5 | 6 | The form handlers are designed to enhance the developer experience (DX) when 7 | working with Symfony forms. It makes the controllers simpler by moving the form 8 | success and failure flows to a separate class. 9 | 10 | ```php 11 | class YourController extends Controller 12 | { 13 | public function formAction(Request $request, MyEntityUser $user) 14 | { 15 | $handler = $this->get('hostnet.form_handler.factory')->create(MyFormHandler::class); 16 | 17 | if (($response = $handler->handle($request, new MyFormData())) instanceof RedirectResponse) { 18 | return $response; 19 | } 20 | 21 | // regular or in-valid flow 22 | return $this->render->renderView('/your/form.html.twig', [ 23 | 'form' => $handler->getForm()->createView() 24 | ]); 25 | } 26 | } 27 | ``` 28 | 29 | By extracting the success - and if available, the failure - flows, you reduce 30 | the amount of code in your controllers, which in turn, achieves slim 31 | controllers. The definition of a controller is according to Symfony: _["a PHP 32 | function you create that reads information from the Symfony's Request object 33 | and creates and returns a Response object"](http://symfony.com/doc/current/controller.html)_. 34 | 35 | Installation 36 | ------------ 37 | * Read the [installation guide](https://github.com/hostnet/form-handler-bundle/wiki/Installation) 38 | when using composer. 39 | * This bundle and the component follow [semantic versioning](http://semver.org/) strictly. 40 | 41 | Documentation 42 | ------------- 43 | * Read the [Getting Started guide](https://github.com/hostnet/form-handler-bundle/wiki/Getting-Started-With-Form-Handlers) if you are new to form handlers. 44 | * You can find the full documentation on our [github wiki pages](https://github.com/hostnet/form-handler-bundle/wiki). 45 | * If you are migrating from 1.1 to 1.2 or 2.x, check the [migration guide](https://github.com/hostnet/form-handler-bundle/wiki/Migration-towards-2.x). 46 | * The [legacy documentation for 1.1](https://github.com/hostnet/form-handler-bundle/wiki/Legacy-Readme) 47 | is still available but upgrading is recommended. 48 | 49 | License 50 | ------------- 51 | The `hostnet/form-handler-bundle` is licensed under the [MIT License](https://github.com/hostnet/form-handler-bundle/blob/master/LICENSE), meaning you can reuse the code within proprietary software provided that all copies of the licensed software include a copy of the MIT License terms and the copyright notice. 52 | 53 | Get in touch 54 | ------------ 55 | * We are available on the [symfony-devs](https://slackinvite.me/to/symfony-devs) 56 | slack server in [#hostnet-form-handlers](https://symfony-devs.slack.com/messages/C3SJH42QP). 57 | * Or via our email: opensource@hostnet.nl. 58 | --------------------------------------------------------------------------------