PHPackages                             php-open-source-saver/fractal - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. php-open-source-saver/fractal

ActiveLibrary[HTTP &amp; Networking](/categories/http)

php-open-source-saver/fractal
=============================

Handle the output of complex data structures ready for API output.

v1.0.1(4mo ago)4251.6k—1.2%21MITPHPPHP &gt;=8.1CI passing

Since Dec 30Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/PHP-Open-Source-Saver/fractal)[ Packagist](https://packagist.org/packages/php-open-source-saver/fractal)[ Docs](https://github.com/PHP-Open-Source-Saver/fractal)[ GitHub Sponsors](https://github.com/specialtactics)[ RSS](/packages/php-open-source-saver-fractal/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (9)Versions (7)Used By (1)

Fractal
=======

[](#fractal)

[![Latest Version](https://camo.githubusercontent.com/a8d8e6834cf5023e92830f7d19654bb82745370cb3aa8e2982c42f286ade6970/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f5048502d4f70656e2d536f757263652d53617665722f6672616374616c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/PHP-Open-Source-Saver/fractal/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![CI Tests](https://github.com/PHP-Open-Source-Saver/fractal/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/PHP-Open-Source-Saver/fractal/actions)[![Development Version](https://camo.githubusercontent.com/ef459a3c9dc344d0c7d3e3ff568804fe64010eb0f524e006a47c19664308ea1a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f5048502d4f70656e2d536f757263652d53617665722f6672616374616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHP-Open-Source-Saver/fractal)

Credits
-------

[](#credits)

[This repository is a fork from original thephpleague/fractal](https://fractal.thephpleague.com/), we decided to make an independent fork due to the lack of updates to the original package, and lack of a process for volunteers to become maintainers within the php league ecosystem of packages.

Migrating from [`thephpleague/fractal`](https://github.com/thephpleague/fractal)
--------------------------------------------------------------------------------

[](#migrating-from-thephpleaguefractal)

This uses different namespace to `thephpleague/fractal`, but overall, provides the same API, that makes migration to this repository pretty easy:

1. Run `composer remove thephpleague/fractal`> **Info** An error will appear because the package is still in use, ignore it.
2. Replace all the occurrences of `League\Fractal` with `PHPOpenSourceSaver\Fractal`. > **Tip**: You can use *Find and Replace* feature of your IDE. Try it with Ctrl + Shift + R
3. Run `composer require php-open-source-saver/fractal`

Notes
-----

[](#notes)

Fractal provides a presentation and transformation layer for complex data output, the like found in RESTful APIs, and works really well with JSON. Think of this as a view layer for your JSON/YAML/etc.

When building an API it is common for people to just grab stuff from the database and pass it to `json_encode()`. This might be passable for "trivial" APIs but if they are in use by the public, or used by mobile applications then this will quickly lead to inconsistent output.

Goals
-----

[](#goals)

- Create a protective shield between source data and output, so schema changes do not affect users
- Systematic type-casting of data, to avoid `foreach()`ing through and `(bool)`ing everything
- Include (a.k.a embedding, nesting or side-loading) relationships for complex data structures
- Work with standards like HAL and JSON-API but also allow custom serialization
- Support the pagination of data results, for small and large data sets alike
- Generally ease the subtle complexities of outputting data in a non-trivial API

This package is compliant with [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md), [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) and [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md). If you notice compliance oversights, please send a patch via pull request.

Install
-------

[](#install)

Via Composer

```
$ composer require php-open-source-saver
```

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

[](#requirements)

The following versions of PHP are supported by this version:

&gt;= PHP 8.1

Documentation
-------------

[](#documentation)

Fractal has [full documentation](http://fractal.thephpleague.com), powered by [Jekyll](http://jekyllrb.com/).

Contribute to this documentation in the [gh-pages branch](https://github.com/thephpleague/fractal/tree/gh-pages/).

Testing
-------

[](#testing)

```
$ phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/thephpleague/fractal/blob/master/CONTRIBUTING.md) and [CONDUCT](https://github.com/thephpleague/fractal/blob/master/CONDUCT.md) for details.

Maintainers
-----------

[](#maintainers)

- [Max Snow](https://github.com/specialtactics)

Credits
-------

[](#credits-1)

- [Graham Daniels](https://github.com/greydnls)
- [Andrew Willis](https://github.com/willishq)
- [Phil Sturgeon](https://github.com/philsturgeon)
- [Korvin Szanto](https://github.com/korvinszanto)
- [Matt Trask](https://github.com/matthewtrask)
- [All Contributors](https://github.com/thephpleague/fractal/contributors)

Reporting a Vulnerability
-------------------------

[](#reporting-a-vulnerability)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/thephpleague/fractal/blob/master/LICENSE) for more information.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance76

Regular maintenance activity

Popularity41

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor6

6 contributors hold 50%+ of commits

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

Total

4

Last Release

131d ago

Major Versions

v0.22.0 → v1.0.02025-01-12

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2955754?v=4)[Max](/maintainers/specialtactics)[@specialtactics](https://github.com/specialtactics)

---

Top Contributors

[![philsturgeon](https://avatars.githubusercontent.com/u/67381?v=4)](https://github.com/philsturgeon "philsturgeon (49 commits)")[![willishq](https://avatars.githubusercontent.com/u/1564903?v=4)](https://github.com/willishq "willishq (34 commits)")[![greydnls](https://avatars.githubusercontent.com/u/1276798?v=4)](https://github.com/greydnls "greydnls (27 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (20 commits)")[![specialtactics](https://avatars.githubusercontent.com/u/2955754?v=4)](https://github.com/specialtactics "specialtactics (16 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (15 commits)")[![livkiss](https://avatars.githubusercontent.com/u/256075?v=4)](https://github.com/livkiss "livkiss (14 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (12 commits)")[![matthewtrask](https://avatars.githubusercontent.com/u/4731244?v=4)](https://github.com/matthewtrask "matthewtrask (11 commits)")[![duythien](https://avatars.githubusercontent.com/u/1762691?v=4)](https://github.com/duythien "duythien (11 commits)")[![KorvinSzanto](https://avatars.githubusercontent.com/u/1007419?v=4)](https://github.com/KorvinSzanto "KorvinSzanto (8 commits)")[![ipalaus](https://avatars.githubusercontent.com/u/248183?v=4)](https://github.com/ipalaus "ipalaus (8 commits)")[![vanbrabantf](https://avatars.githubusercontent.com/u/12281411?v=4)](https://github.com/vanbrabantf "vanbrabantf (6 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (6 commits)")[![marcaddeo](https://avatars.githubusercontent.com/u/199649?v=4)](https://github.com/marcaddeo "marcaddeo (6 commits)")[![webda2l](https://avatars.githubusercontent.com/u/517753?v=4)](https://github.com/webda2l "webda2l (5 commits)")[![niden](https://avatars.githubusercontent.com/u/1073784?v=4)](https://github.com/niden "niden (5 commits)")[![ceeram](https://avatars.githubusercontent.com/u/111448?v=4)](https://github.com/ceeram "ceeram (4 commits)")[![elliotfehr](https://avatars.githubusercontent.com/u/5550991?v=4)](https://github.com/elliotfehr "elliotfehr (4 commits)")[![bencorlett](https://avatars.githubusercontent.com/u/181919?v=4)](https://github.com/bencorlett "bencorlett (4 commits)")

---

Tags

jsonapilaravelrestleague

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/php-open-source-saver-fractal/health.svg)

```
[![Health](https://phpackages.com/badges/php-open-source-saver-fractal/health.svg)](https://phpackages.com/packages/php-open-source-saver-fractal)
```

###  Alternatives

[givebutter/laravel-keyable

Add API keys to your Laravel models

187144.5k2](/packages/givebutter-laravel-keyable)[guanguans/laravel-api-response

Normalize and standardize Laravel API response data structure. - 规范化和标准化 Laravel API 响应数据结构。

485.6k](/packages/guanguans-laravel-api-response)

PHPackages © 2026

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