PHPackages                             somnambulist/fractal-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. [API Development](/categories/api)
4. /
5. somnambulist/fractal-bundle

ActiveSymfony-bundle[API Development](/categories/api)

somnambulist/fractal-bundle
===========================

A port of samj/fractal-bundle for integrating TheLeague Fractal into Symfony

2.1.2(1y ago)328.9k↓20.9%11MITPHPPHP &gt;=8.1CI passing

Since Sep 30Pushed 1y ago3 watchersCompare

[ Source](https://github.com/somnambulist-tech/fractal-bundle)[ Packagist](https://packagist.org/packages/somnambulist/fractal-bundle)[ RSS](/packages/somnambulist-fractal-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (8)Used By (1)

Somnambulist Fractal Bundle
===========================

[](#somnambulist-fractal-bundle)

[![GitHub Actions Build Status](https://camo.githubusercontent.com/df1c1787667aadfcc18d323ab3efcf16e71722b53c6792b42fde6d6d4d307bf3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736f6d6e616d62756c6973742d746563682f6672616374616c2d62756e646c652f74657374732e796d6c3f6c6f676f3d676974687562266272616e63683d6d61696e)](https://github.com/somnambulist-tech/fractal-bundle/actions?query=workflow%3Atests)[![Issues](https://camo.githubusercontent.com/e43d267a8146caa1c6a6e7bb2f24787cf4a4492fbcccd555e0405160290938e9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f736f6d6e616d62756c6973742d746563682f6672616374616c2d62756e646c653f6c6f676f3d676974687562)](https://github.com/somnambulist-tech/fractal-bundle/issues)[![License](https://camo.githubusercontent.com/7383cc5f4df3333c034b403faa8313ca535b32efb79516064c191878b6b9fdb7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736f6d6e616d62756c6973742d746563682f6672616374616c2d62756e646c653f6c6f676f3d676974687562)](https://github.com/somnambulist-tech/fractal-bundle/blob/main/LICENSE)[![PHP Version](https://camo.githubusercontent.com/8a742b12703e791915002c2bc02ecc559613c40fb3bbda64cb69c7a7aa7bd254/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736f6d6e616d62756c6973742f6672616374616c2d62756e646c653f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/somnambulist/fractal-bundle)[![Current Version](https://camo.githubusercontent.com/db8b318a14c4a1c83fa1d69ab1aff5c495737e324e451e56e90eea92c9576172/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6d6e616d62756c6973742f6672616374616c2d62756e646c653f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/somnambulist/fractal-bundle)

A fork and re-write of [samj/fractal-bundle](https://github.com/samjarrett/FractalBundle) to provide [Fractal](https://fractal.thephpleague.com)integration with the Symfony Framework.

Requirements
------------

[](#requirements)

- PHP 8.2+
- symfony/framework-bundle 6.4+

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

[](#installation)

Install using composer, or checkout / pull the files from github.com.

- composer require somnambulist/fractal-bundle

Usage
-----

[](#usage)

Add the `SomnambulistFractalBundle` to your `bundles.php` list if not registered by Symfony Flex.

Using Transformers as Services
------------------------------

[](#using-transformers-as-services)

This bundle allows auto-wiring / auto-configuring transformers as services. This allows you to take advantage of Symfonys container to resolve dependencies and reference transformers by class name (or service alias).

So long as the transformer extends from `League\Fractal\TransformerAbstract` or is tagged with `somnambulist.fractal_bundle.transformer`, it will be available to the Fractal Manager instance.

```
services:
    App\Http\Api\Transformers\:
        resource: '%kernel.project_dir%/Http/Api/Transformers/'
```

If transformers don't extend the `TransformerAbstract` be sure to tag them:

```
services:
    App\Http\Api\Transformers\:
        resource: '%kernel.project_dir%/Http/Api/Transformers/'
        tags: ['somnambulist.fractal_bundle.transformer']
```

**Note:** if your transformer is not registered as a service or passed as a valid callable or instance of `TransformerAbstract`, this library will raise an exception.

For example: to add an auth check to a `UserTransformer` (example from samj readme):

```
use League\Fractal\TransformerAbstract;

class UserTransformer extends TransformerAbstract
{
    public function __construct(private AuthorizationChecker $authorizationChecker)
    {
    }

    public function transform(User $user)
    {
        $data = [
            'id' => $user->id(),
            'name' => $user->name(),
        ];

        if ($this->authorizationChecker->isGranted(UserVoter::SEE_EMAIL, $user)) {
            $data['email'] = $user->email();
        }

        return $data;
    }
}
```

Reference the transformer by either a service alias name, or the class name:

```
$resource = new Collection($users, UserTransformer::class);
```

This works in includes as well:

```
public function includeFriends(User $user)
{
    return $this->collection($user->friends(), UserTransformer::class);
}
```

Look in the [sample application](tests/Fixtures) for some further examples.

Tests
-----

[](#tests)

PHPUnit 9+ is used for testing. Run tests via `vendor/bin/phpunit`.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance46

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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 ~215 days

Recently: every ~282 days

Total

7

Last Release

401d ago

Major Versions

1.1.0 → 2.0.02022-03-10

PHP version history (2 changes)1.0.0PHP &gt;=8.0

2.1.0PHP &gt;=8.1

### Community

Maintainers

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

---

Top Contributors

[![dave-redfern](https://avatars.githubusercontent.com/u/1477147?v=4)](https://github.com/dave-redfern "dave-redfern (10 commits)")

---

Tags

symfonyfractal

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/somnambulist-fractal-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/somnambulist-fractal-bundle/health.svg)](https://phpackages.com/packages/somnambulist-fractal-bundle)
```

###  Alternatives

[flugger/laravel-responder

A Laravel Fractal package for building API responses, giving you the power of Fractal and the elegancy of Laravel.

8901.5M5](/packages/flugger-laravel-responder)[yajra/laravel-datatables-fractal

Laravel DataTables Fractal Plugin.

966.9M29](/packages/yajra-laravel-datatables-fractal)[cravler/maxmind-geoip-bundle

Bundle integrating MaxMind GeoIP2 database into symfony application

27615.8k2](/packages/cravler-maxmind-geoip-bundle)[nanofelis/json-rpc-bundle

This bundle provides a JSON RPC 2.0 implementation for Symfony

1176.1k](/packages/nanofelis-json-rpc-bundle)[stfalcon-studio/api-bundle

Base classes and helper services to build API application via Symfony.

1032.1k](/packages/stfalcon-studio-api-bundle)[ufo-tech/json-rpc-sdk-bundle

The Symfony bundle for simple usage Json-RPC api with dynamic SDK

172.5k](/packages/ufo-tech-json-rpc-sdk-bundle)

PHPackages © 2026

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