PHPackages                             nebkam/symfony-traits - 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. nebkam/symfony-traits

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

nebkam/symfony-traits
=====================

Helper trait to ease writing APIs in Symfony

4.1.2(5mo ago)156.7k↓25%2MITPHPCI passing

Since Mar 22Pushed 5mo ago3 watchersCompare

[ Source](https://github.com/nebkam/symfony-traits)[ Packagist](https://packagist.org/packages/nebkam/symfony-traits)[ RSS](/packages/nebkam-symfony-traits/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (27)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/a5f66bea84340b5da860c6761e6102c78993bc2ffceef38d1d0c5ce454124ec5/68747470733a2f2f706f7365722e707567782e6f72672f6e65626b616d2f73796d666f6e792d7472616974732f76)](//packagist.org/packages/nebkam/symfony-traits)

Symfony Traits
==============

[](#symfony-traits)

Few helper traits for quicker API development in Symfony

FormTrait
---------

[](#formtrait)

### `handleJSONForm`

[](#handlejsonform)

- controller helper method for JSON data sent in `POST`, `PUT` or `PATCH` request content
- generally speaking, sending JSON content is more flexible than forms, for CRUD with JS frameworks.

```
public function create(Request $request)
	{
	$entity = new Entity();
	$this->handleJSONForm($request, $entity, EntityType::class, $options = [], $clearMissingFields = true);
	// persist and flush $entity
```

```
public function edit(Request $request,Entity $entity)
	{
	$this->handleJSONForm($request, $entity, EntityType::class, $options = [], $clearMissingFields = true);
	// flush entity
```

### `handleForm`

[](#handleform)

- controller helper method for traditional form data in `GET` or `POST`
- I advice using traditional form data only when JSON is out of place (i.e. `GET` params)

```
public function example(Request $request)
	{
	$domain = new Domain();
	if ($request->query->count() > 0)
		{
		$this->handleForm($request, $params, DomainType::class, $options = [], $clearMissingFields = true);
		}

	// do something with $domain
```

### `handleUpload`

[](#handleupload)

- controller helper method to validate a single file upload
- a lightweight alternative to a [File constraint](http://symfony.com/doc/current/reference/constraints/File.html), when you need just one file, not the whole form

```
public function uploadImage(Request $request)
	{
	$file = $this->handleUpload($request, 'image');

	// do something with $file
	}
```

### `ValidationExceptionListener`

[](#validationexceptionlistener)

Since all `handle*` methods in this trait throw a `Nebkam\SymfonyTraits\ValidationException`, you have to catch it, either via `try {..} catch` in the controller or via global exception listener. To ease this, this package includes a sample exception listener, which returns validation errors in JSON. You just have to register it as a service:

```
Nebkam\SymfonyTraits\EventListener\ValidationExceptionListener:
    tags:
        - { name: kernel.event_listener, event: kernel.exception }
```

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance71

Regular maintenance activity

Popularity32

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 56% 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 ~112 days

Recently: every ~129 days

Total

26

Last Release

163d ago

Major Versions

1.1.2 → 2.0.02019-12-12

2.0.0 → 3.0.02020-02-14

3.1.0 → 4.0.02022-03-16

### Community

Maintainers

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

---

Top Contributors

[![zidar-bot](https://avatars.githubusercontent.com/u/85165793?v=4)](https://github.com/zidar-bot "zidar-bot (14 commits)")[![nebkam](https://avatars.githubusercontent.com/u/1735290?v=4)](https://github.com/nebkam "nebkam (9 commits)")[![shkabo](https://avatars.githubusercontent.com/u/1276333?v=4)](https://github.com/shkabo "shkabo (2 commits)")

---

Tags

formhelperssymfony

### Embed Badge

![Health badge](/badges/nebkam-symfony-traits/health.svg)

```
[![Health](https://phpackages.com/badges/nebkam-symfony-traits/health.svg)](https://phpackages.com/packages/nebkam-symfony-traits)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-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)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

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