randomstate / api
A flexible API package for PHP.
Installs: 1 525
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- league/fractal: ^0.19
Requires (Dev)
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.5
README
A flexible API package for PHP. Fits perfectly with Laravel and Laravel Doctrine. This is a barebones package that is agnostic to any given PHP application or framework. As a result, there is a lot of legwork to wire up the different components to get started.
Please see randomstate/laravel-api for an out-of-the-box integration with Laravel that does this all for you.
Installation
composer require randomstate/api
Basic Usage
Input Transformation
<?php use \RandomState\Api\Transformation\Manager; use \RandomState\Api\Transformation\Fractal\Resolver; use \RandomState\Api\Transformation\Fractal\Switchboard; use \RandomState\Api\Transformation\Adapters\Fractal\CollectionAdapter; use \RandomState\Api\Transformation\Adapters\Fractal\ItemAdapter; $manager = new Manager; $resolver = new Resolver() $resolver->bind(MyOwnEntityFromSomewhere::class, MyOwnEntityFractalTransformer::class); $switchboard = new Switchboard($resolver); $manager->register( new CollectionAdapter($switchboard), new ItemAdapter($switchboard) ); $data = new MyOwnEntityFromSomewhere; $output = $manager->transform($data); // will use MyOwnEntityFractalTransformer via Fractal to transform the data