Download the PHP package somnambulist/fractal-bundle without Composer
On this page you can find all versions of the php package somnambulist/fractal-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download somnambulist/fractal-bundle
More information about somnambulist/fractal-bundle
Files in somnambulist/fractal-bundle
Package fractal-bundle
Short Description A port of samj/fractal-bundle for integrating TheLeague Fractal into Symfony
License MIT
Informations about the package fractal-bundle
Somnambulist Fractal Bundle
A fork and re-write of samj/fractal-bundle to provide Fractal integration with the Symfony Framework.
Requirements
- PHP 8.2+
- symfony/framework-bundle 6.4+
Installation
Install using composer, or checkout / pull the files from github.com.
- composer require somnambulist/fractal-bundle
Usage
Add the SomnambulistFractalBundle
to your bundles.php
list if not registered by Symfony Flex.
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.
If transformers don't extend the TransformerAbstract
be sure to tag them:
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):
Reference the transformer by either a service alias name, or the class name:
This works in includes as well:
Look in the sample application for some further examples.
Tests
PHPUnit 9+ is used for testing. Run tests via vendor/bin/phpunit
.