PHPackages                             headsnet/symfony-tools-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. headsnet/symfony-tools-bundle

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

headsnet/symfony-tools-bundle
=============================

Tools and helpers for functionality needed in larger Symfony projects

v0.4.0(1y ago)031.8k↓42.3%[1 issues](https://github.com/headsnet/symfony-tools-bundle/issues)MITPHPPHP &gt;=8.2

Since Jun 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/headsnet/symfony-tools-bundle)[ Packagist](https://packagist.org/packages/headsnet/symfony-tools-bundle)[ Docs](https://github.com/headsnet/symfony-tools-bundle)[ RSS](/packages/headsnet-symfony-tools-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (11)Versions (5)Used By (0)

Symfony Bundle Template
=======================

[](#symfony-bundle-template)

[![Build Status](https://github.com/headsnet/symfony-tools-bundle/actions/workflows/ci.yml/badge.svg)](https://github.com/headsnet/symfony-tools-bundle/actions/workflows/ci.yml/badge.svg)[![Coverage](https://raw.githubusercontent.com/headsnet/symfony-tools-bundle/image-data/coverage.svg)](https://raw.githubusercontent.com/headsnet/symfony-tools-bundle/image-data/coverage.svg)[![Latest Stable Version](https://camo.githubusercontent.com/95e5a719655018dc382f36dbf987de3c156a52c1dd9297d73d7d86b271be006f/68747470733a2f2f706f7365722e707567782e6f72672f68656164736e65742f73796d666f6e792d746f6f6c732d62756e646c652f76)](//packagist.org/packages/headsnet/symfony-tools-bundle)[![Total Downloads](https://camo.githubusercontent.com/9cb88c6af44e77d1b80319dced7fb58eebb8c3738d546173b2b3d80e208f5e57/68747470733a2f2f706f7365722e707567782e6f72672f68656164736e65742f73796d666f6e792d746f6f6c732d62756e646c652f646f776e6c6f616473)](//packagist.org/packages/headsnet/symfony-tools-bundle)[![License](https://camo.githubusercontent.com/850cdfc6ed99ec3d4540a418e86463506e80bc499a898908b831fe0253a1bee9/68747470733a2f2f706f7365722e707567782e6f72672f68656164736e65742f73796d666f6e792d746f6f6c732d62756e646c652f6c6963656e7365)](//packagist.org/packages/headsnet/symfony-tools-bundle)[![PHP Version Require](https://camo.githubusercontent.com/ccaaa4c4c65d991eb5a1385f8e3106eca8afd5d7b616ffb79b1fe92a59c93165/687474703a2f2f706f7365722e707567782e6f72672f68656164736e65742f73796d666f6e792d746f6f6c732d62756e646c652f726571756972652f706870)](//packagist.org/packages/headsnet/symfony-tools-bundle)

A collection of useful tools and functions for Symfony projects.

Features
--------

[](#features)

- [Apply rate limiters using attributes](#apply-rate-limiters-using-attributes)
- [Store Twig templates next to production code](#store-twig-templates-next-to-production-code)
- [Use empty strings by default on text-based form fields](#empty-string-default-for-text-based-form-fields)
- [Set various attributes on &lt;form&gt; elements](#set-attributes-on-form-elements)

Installation
------------

[](#installation)

```
composer require headsnet/symfony-tools-bundle
```

If your Symfony installation does not auto-register bundles, add it manually:

```
// bundles.php
return [
    ...
    Headsnet\DoctrineToolsBundle\HeadsnetSymfonyToolsBundle::class => ['all' => true],
];
```

### Apply rate limiters using attributes

[](#apply-rate-limiters-using-attributes)

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

**IMPORTANT:** The rate limiter is currently based on the client IP address only. If you are behind a proxy such as Cloudflare you will need to handle accessing the [originating client IP address](https://symfony.com/doc/current/deployment/proxies.html).

First, define the rate limiter that you want to use:

```
# config/packages/framework.yaml

framework:
    rate_limiter:
        anonymous_api:
            policy: 'sliding_window'
            limit: 100
            interval: '60 seconds'
```

Then add the annotation to the controller you want to protect, specifying the name of the rate limiter in the attribute:

```
// src/Controllers/ApiController.php

#[RateLimiting('anonymous_api')]
#[Route('/create')]
public function createAccount(): JsonResponse
{
  // your controller logic...
}
```

#### Rate Limiter HTTP Headers

[](#rate-limiter-http-headers)

The bundle also provides a listener to add HTTP headers indicating the status of the rate limiter. E.g.

```
rate-limit-limit: 1
rate-limit-remaining: 0
rate-limit-reset: -7

```

This can be disabled in the bundle configuration if desired:

```
headsnet_symfony_tools:
    rate_limiting:
        use_headers: false
```

Thanks to [this JoliCode article](https://jolicode.com/blog/rate-limit-your-symfony-apis) for the inspiration!

### Store Twig templates next to production code

[](#store-twig-templates-next-to-production-code)

As [discussed on our blog](https://headsnet.com/blog/move-templates-closer-to-the-code), often it is desirable to store related things together (cohesion). You may want to apply to this your Twig templates.

This bundle provides a compiler pass that will search for multiple Twig `tpl` directories and add them to the Twig configuration automatically.

This behaviour must be enabled in the configuration by setting the `base_dir` option:

```
headsnet_symfony_tools:
    twig:
        import_feature_dirs:
            base_dir: 'src/Feature'
```

You can then refer to your Twig templates that live in your production code directories using the following syntax:

```
@SendRegistrationEmail/hello.html.twig
@Billing->Invoicing->Create/invoice.html.twig

```

### Empty string default for text-based form fields

[](#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.

An easy way to fix this is to change the default behaviour so text-based fields return an empty string `''` instead of `null`. Then, class properties can be typed `string` instead of `string|null` and this can eliminate a lot of null checks in the client code.

This is an opinionated solution, so must be enabled in the bundle configuration:

```
headsnet_symfony_tools:
    forms:
        default_empty_string: true
```

### Set attributes on &lt;form&gt; elements

[](#set-attributes-on-form-elements)

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

These must be explicitly enabled in the configuration.

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

License
-------

[](#license)

Released under the [MIT License](LICENSE).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~51 days

Total

4

Last Release

536d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/baad3e4bf78f55c3242e2e84839614395ce22d21da10fd4379a57fcf2608611d?d=identicon)[benr77](/maintainers/benr77)

---

Top Contributors

[![benr77](https://avatars.githubusercontent.com/u/2156742?v=4)](https://github.com/benr77 "benr77 (22 commits)")

---

Tags

phpsymfony

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/headsnet-symfony-tools-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/headsnet-symfony-tools-bundle/health.svg)](https://phpackages.com/packages/headsnet-symfony-tools-bundle)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[pugx/autocompleter-bundle

Add an autocomplete type to forms

93861.6k3](/packages/pugx-autocompleter-bundle)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[a2lix/translation-form-bundle

Translate your doctrine objects easily with some helpers

3376.9M38](/packages/a2lix-translation-form-bundle)[pentatrion/vite-bundle

Vite integration for your Symfony app

2725.3M13](/packages/pentatrion-vite-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
