Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify configuration #8

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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