PHPackages                             czepter/cakephp-fractal-transformer-view - 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. czepter/cakephp-fractal-transformer-view

ActiveCakephp-plugin[HTTP &amp; Networking](/categories/http)

czepter/cakephp-fractal-transformer-view
========================================

CakePHP view builder utilizing Fractal library for entities transformation

2.2.1(3y ago)03MITPHPPHP &gt;=7.2

Since Feb 29Pushed 3y agoCompare

[ Source](https://github.com/czepter/cakephp-fractal-transformer-view)[ Packagist](https://packagist.org/packages/czepter/cakephp-fractal-transformer-view)[ Docs](http://github.com/czepter/cakephp-fractal-transformer-view)[ RSS](/packages/czepter-cakephp-fractal-transformer-view/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (4)Versions (7)Used By (0)

[![Build Status](https://camo.githubusercontent.com/6abde0fa6ed77388c0552b3282a5e27e638cc9d496283d1b5776d2da0061781c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f616e6472656a2d6772696e69756b2f63616b657068702d6672616374616c2d7472616e73666f726d65722d766965772f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/andrej-griniuk/cakephp-fractal-transformer-view)[![Coverage Status](https://camo.githubusercontent.com/da0f3377c7436d4cd6f24ed52c159a85f63b579b2458e38a19ad0cd000b3eb1c/68747470733a2f2f636f6465636f762e696f2f67682f616e6472656a2d6772696e69756b2f63616b657068702d6672616374616c2d7472616e73666f726d65722d766965772f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/andrej-griniuk/cakephp-fractal-transformer-view)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

FractalTransformerView plugin for CakePHP
=========================================

[](#fractaltransformerview-plugin-for-cakephp)

This plugin is a thin wrapper for `JsonView` that allows using [Fractal transformers](http://fractal.thephpleague.com/transformers/) for your API output. What is [Fractal](http://fractal.thephpleague.com/)?

> 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.

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

[](#requirements)

- CakePHP 4.0+ (use ~1.0 for CakePHP 3.1+)

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

[](#installation)

You can install this plugin into your CakePHP application using [Composer](http://getcomposer.org).

```
composer require andrej-griniuk/cakephp-fractal-transformer-view
```

Usage
-----

[](#usage)

To enable the plugin set `FractalTransformerView.FractalTransformer` class name for viewBuilder. Then you just do what you would normally do in your [data views](http://book.cakephp.org/4/en/views/json-and-xml-views.html) - specify which view vars you want to get serialized by setting `serialize` view builder option. E.g.:

```
namespace App\Controller;

class ArticlesController extends AppController
{
    public function initialize(): void
    {
        parent::initialize();

        $this->loadComponent('RequestHandler');

        $this->viewBuilder()->setClassName('FractalTransformerView.FractalTransformer');
    }

    public function index()
    {
        // Set the view vars that have to be serialized.
        $this->set('articles', $this->paginate());
        // Specify which view vars JsonView should serialize.
        $this->viewBuilder()->setOption('serialize', ['articles']);
    }
}
```

The view will look for transformer class starting with entity name. E.g.:

```
namespace App\Model\Transformer;

use App\Model\Entity\Article;
use League\Fractal\TransformerAbstract;

class ArticleTransformer extends TransformerAbstract
{
    /**
     * Creates a response item for each instance
     *
     * @param Article $article post entity
     * @return array transformed post
     */
    public function transform(Article $article)
    {
        return [
            'title' => $article->get('title')
        ];
    }
}
```

If transformer class not found the variable is serialized the normal way.

Custom transformer class name can be set by defining `transformer` view builder option:

```
$this->viewBuilder()->setOption('transform', ['articles' => '\App\Model\Transformer\CustomArticleTransformer']);
```

You can also define if you don't want to use transformer for certain variables:

```
$this->viewBuilder()->setOption('transform', ['articles' => false]);
```

You can set a custom serializer (class name or object) via `serializer` view builder option:

```
$this->viewBuilder()->setOption('serializer', new CustomSerializer());
```

Bugs &amp; Feedback
-------------------

[](#bugs--feedback)

Credits
-------

[](#credits)

Inspired by @josegonzalez [Using Fractal to transform entities for custom api endpoints](http://josediazgonzalez.com/2015/12/01/using-fractal-to-transform-entities-for-custom-api-endpoints/).

License
-------

[](#license)

Copyright (c) 2016, [Andrej Griniuk](https://github.com/andrej-griniuk) and licensed under [The MIT License](http://www.opensource.org/licenses/mit-license.php).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 89.3% 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 ~596 days

Total

5

Last Release

1342d ago

Major Versions

v1.0 → 2.02021-01-14

PHP version history (2 changes)v1.0PHP &gt;=5.5.0

2.0PHP &gt;=7.2

### Community

Maintainers

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

---

Top Contributors

[![andrej-griniuk](https://avatars.githubusercontent.com/u/2722793?v=4)](https://github.com/andrej-griniuk "andrej-griniuk (25 commits)")[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (2 commits)")[![dakota](https://avatars.githubusercontent.com/u/83255?v=4)](https://github.com/dakota "dakota (1 commits)")

---

Tags

jsonapirestcakephpfractal

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/czepter-cakephp-fractal-transformer-view/health.svg)

```
[![Health](https://phpackages.com/badges/czepter-cakephp-fractal-transformer-view/health.svg)](https://phpackages.com/packages/czepter-cakephp-fractal-transformer-view)
```

###  Alternatives

[andrej-griniuk/cakephp-fractal-transformer-view

CakePHP view builder utilizing Fractal library for entities transformation

1890.7k](/packages/andrej-griniuk-cakephp-fractal-transformer-view)[mixerapi/mixerapi

Streamline development of API-first applications in CakePHP

4441.8k](/packages/mixerapi-mixerapi)[cakedc/cakephp-api

Api plugin for CakePHP

61100.6k](/packages/cakedc-cakephp-api)[sprintcube/cakephp-rest

Rest API plugin for CakePHP 3

256.6k](/packages/sprintcube-cakephp-rest)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2425.9k1](/packages/jsor-hal-client)

PHPackages © 2026

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