├── .gitignore ├── LICENSE.md ├── README.md ├── composer.json └── src ├── Commands └── MakeTransformer.php ├── TransformerMakerServiceProvider.php └── stubs └── transformer.stub /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | composer.lock 3 | vendor -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Metric Loop, LLC 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A quick way to create Fractal Transformers 2 | 3 | [![Latest Version](https://img.shields.io/github/release/metricloop/laravel-transformer-maker.svg?style=flat-square)](https://github.com/metricloop/laravel-transformer-maker/releases) 4 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 5 | [![Build Status](https://img.shields.io/travis/metricloop/laravel-transformer-maker/master.svg?style=flat-square)](https://travis-ci.org/metricloop/laravel-transformer-maker) 6 | [![Total Downloads](https://img.shields.io/packagist/dt/metricloop/laravel-transformer-maker.svg?style=flat-square)](https://packagist.org/packages/metricloop/laravel-transformer-maker) 7 | 8 | This package gives you a quick way to create [Transformers](http://fractal.thephpleague.com/transformers/) for your Eloquent models when using [Fractal](http://fractal.thephpleague.com/). 9 | 10 | ## Installation And Usage 11 | 12 | Issue the command: 13 | 14 | ``` 15 | composer require "metricloop/laravel-transformer-maker" 16 | ``` 17 | 18 | Then register the service provider: 19 | 20 | ``` 21 | // config/app.php 22 | 23 | 'providers' => [ 24 | // ... 25 | MetricLoop\TransformerMaker\TransformerMakerServiceProvider::class, 26 | ]; 27 | ``` 28 | 29 | Then just use it like any other Artisan `make` command: 30 | 31 | ``` 32 | php artisan make:transformer Person 33 | ``` 34 | 35 | And get the stubbed out `PersonTransformer.php` in `App/Transformers`! 36 | 37 | ## Shout Out 38 | To Phil Sturgeon and the team at the PHP League for Fractal. And if you haven't already, go check out Phil's book about building APIs: [Build APIs You Won't Hate](https://apisyouwonthate.com/). 39 | 40 | ## About Metric Loop 41 | Metric Loop is an Austin based technology company that strives to create value by helping its clients reduce overhead, simplify their hardware procurement, and run their businesses more efficiently. 42 | 43 | ## License 44 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metricloop/laravel-transformer-maker", 3 | "description": "A Laravel 5 package to create Fractal Transformers", 4 | "keywords": [ 5 | "metricloop", 6 | "fractal", 7 | "transformer", 8 | "api" 9 | ], 10 | "homepage": "https://github.com/metricloop/laravel-transformer-maker", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Patrick Guevara", 15 | "email": "pguevara@metricloop.com", 16 | "homepage": "https://metricloop.com", 17 | "role": "Developer" 18 | } 19 | ], 20 | "require": { 21 | "php": "^7.0", 22 | "illuminate/console": "5.5.* || 5.6.* || 5.7.*", 23 | "illuminate/support": "5.5.* || 5.6.* || 5.7.*" 24 | }, 25 | "require-dev": { 26 | "phpunit/phpunit": "~6.0" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "MetricLoop\\TransformerMaker\\": "src" 31 | } 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { 35 | "MetricLoop\\TransformerMaker\\Test\\": "tests" 36 | } 37 | }, 38 | "scripts": { 39 | "test": "vendor/bin/phpunit" 40 | }, 41 | "config": { 42 | "sort-packages": true 43 | }, 44 | "extra": { 45 | "laravel": { 46 | "providers": [ 47 | "MetricLoop\\TransformerMaker\\TransformerMakerServiceProvider" 48 | ] 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Commands/MakeTransformer.php: -------------------------------------------------------------------------------- 1 | getNameInput()), $stub); 63 | } 64 | 65 | /** 66 | * Append "Transformer" to name input. 67 | * 68 | * @param string $name 69 | * @return string 70 | */ 71 | protected function getPath($name) 72 | { 73 | return parent::getPath($name . 'Transformer'); 74 | } 75 | } -------------------------------------------------------------------------------- /src/TransformerMakerServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->bind('command.make:transformer', MakeTransformer::class); 25 | 26 | $this->commands([ 27 | 'command.make:transformer', 28 | ]); 29 | 30 | // $this->app->singleton(ConsoleOutput::class); 31 | } 32 | } -------------------------------------------------------------------------------- /src/stubs/transformer.stub: -------------------------------------------------------------------------------- 1 | [ 32 | [ 33 | 'rel' => 'self', 34 | 'href' => url('path/to/resource'), 35 | ], 36 | ] 37 | ]; 38 | } 39 | } 40 | --------------------------------------------------------------------------------