Skip to content

Commit

Permalink
Merge pull request #8 from headsnet/simplify-configuration
Browse files Browse the repository at this point in the history
Simplify configuration
  • Loading branch information
benr77 authored Jun 28, 2024
2 parents a7d48a2 + 3d412b9 commit 910bd0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ return [

## Features

- [Rate Limiter Attributes](#rate-limiter-attributes)
- [Form Text Fields Empty String](#form-text-fields-empty-string)
- [Apply rate limiters using attributes](#apply-rate-limiters-using-attributes)
- [Use empty strings by default on text-based form fields](#empty-string-default-for-text-based-form-fields)
- [Set various attributes on <form> elements](#set-attributes-on-form-elements)

### Rate Limiter Attributes
### Apply rate limiters using attributes

The bundle provides PHP attributes that can be used to apply the Symfony Rate Limiter component.

Expand Down Expand Up @@ -83,7 +84,7 @@ headsnet_symfony_tools:
Thanks to [this JoliCode article](https://jolicode.com/blog/rate-limit-your-symfony-apis) for the inspiration!
### Form Text Fields Empty String
### Empty string default for text-based form fields
By default Symfony uses `null` as the default value for text-based form fields. This results in `null` values being all
over the codebase.
Expand All @@ -97,8 +98,20 @@ This is an opinionated solution, so must be enabled in the bundle configuration:
```yaml
headsnet_symfony_tools:
forms:
default_empty_string:
enabled: true
default_empty_string: true
```

### Set attributes on <form> elements

The bundle provides an easy way to globally set attributes on `<form>` elements.

These must be explicitly enabled in the configuration.

```yaml
headsnet_symfony_tools:
forms:
disable_autocomplete: true # autocomplete="off"
disable_validation: true # novalidate="novalidate"
```

## License
Expand Down
10 changes: 3 additions & 7 deletions src/HeadsnetSymfonyToolsBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public function configure(DefinitionConfigurator $definition): void
->arrayNode('forms')
->addDefaultsIfNotSet()
->children()
->arrayNode('default_empty_string')
->canBeEnabled()
->end() // End default_empty_string
->booleanNode('default_empty_string')->defaultFalse()->end()
->booleanNode('disable_autocomplete')->defaultFalse()->end()
->booleanNode('disable_validation')->defaultFalse()->end()
->end()
Expand All @@ -40,9 +38,7 @@ public function configure(DefinitionConfigurator $definition): void
* @param array{
* root_namespace: string,
* forms: array{
* default_empty_string: array{
* enabled: bool
* },
* default_empty_string: bool,
* disable_autocomplete: bool,
* disable_validation: bool,
* },
Expand All @@ -58,7 +54,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
->set('headsnet_symfony_tools.rate_limiting.use_headers', $config['rate_limiting']['use_headers'])
;

if ($config['forms']['default_empty_string']['enabled']) {
if ($config['forms']['default_empty_string']) {
$container->services()
->set('headsnet_symfony_tools.forms.default_empty_string_extension')
->class(TextTypeDefaultStringExtension::class)
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
headsnet_symfony_tools:
root_namespace: App
forms:
default_empty_string:
enabled: true
default_empty_string: true
disable_validation: true
disable_autocomplete: true
rate_limiting:
Expand Down

0 comments on commit 910bd0a

Please sign in to comment.