Skip to content

Commit

Permalink
Uploaded version 2 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
flugg committed Aug 8, 2017
1 parent f8044ca commit 6aa0859
Show file tree
Hide file tree
Showing 115 changed files with 6,823 additions and 4,847 deletions.
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
/.idea
/vendor
composer.lock
.DS_STORE
.*.swo
.*.swp
.swo
.swp
*.sublime-project
*.sublime-workspace
composer.lock
61 changes: 8 additions & 53 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Scrutinizer CI configuration
filter:
excluded_paths: [tests/*]

checks:
php:
code_rating: true
Expand All @@ -19,60 +17,17 @@ checks:
fix_identation_4spaces: true
fix_doc_comments: true
uppercase_constants: true
simplify_boolean_return: true
return_doc_comments: true
parameter_doc_comments: true
classes_in_camel_caps: true
variable_existence: true
verify_property_names: false
use_self_instead_of_fqcn: true
properties_in_camelcaps: true
phpunit_assertions: true
parameters_in_camelcaps: true
optional_parameters_at_the_end: true
no_new_line_at_end_of_file: true
encourage_single_quotes: true
avoid_multiple_statements_on_same_line: true

coding_style:
php:
spaces:
before_parentheses:
closure_definition: true
around_operators:
concatenation: true
negation: true
within:
brackets: true
function_call: true
function_declaration: true
if: true
for: true
while: true
switch: true
catch: true
braces:
classes_functions:
class: new-line
function: new-line
closure: end-of-line
if:
opening: end-of-line
for:
opening: end-of-line
while:
opening: end-of-line
do_while:
opening: end-of-line
switch:
opening: end-of-line
try:
opening: end-of-line
upper_lower_casing:
keywords:
general: lower
constants:
true_false_null: lower
build:
environment:
php: 7.0.6
php: 7.1.0
tests:
override:
-
command: 'vendor/bin/phpunit --coverage-clover=coverage'
coverage:
file: 'coverage'
format: 'clover'
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Travis CI configuration
language: php
php:
- '7.0'
- 7.0
- 7.1
before_script:
- composer self-update
- composer install --prefer-source --no-interaction
- composer dump-autoload

script:
- vendor/bin/phpunit
73 changes: 73 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 2.0.0 (2017-08-01)

Version `2.0.0` has been a complete rewrite of the package and brings a lot new stuff to the table, including this very new changelog. The documentation has also been revamped and explains all the new features in greater details. If you're upgrading from an earlier version, make sure to remove your `config/responder.php` file and rerun `php artisan vendor:publish --provider="Flugg\Responder\ResponderServiceProvider"` to publish the new configuration file.

### Breaking Changes

* Fractal requirement changed to `0.16.0`
* Moved `Flugg\Responder\Transformer` to `Flugg\Responder\Transformers\Transformer`
* Changed `Flugg\Responder\Traits\RespondsWithJson` to `Flugg\Responder\Http\Controllers\MakesResponses`
* Changed `Flugg\Responder\Traits\HandlesApiErrors` to `Flugg\Responder\Exceptions\ConvertsExceptions`
* Moved `Flugg\Responder\Traits\MakesApiRequests` to `Flugg\Responder\Testing\MakesApiRequests`
* Removed `Flugg\Responder\Traits\ConvertsParameter`, use new `ConvertToSnakeCase` middleware instead
* Removed `Flugg\Responder\Traits\ThrowsApiErrors`, manually override form requests to replicate
* Changed `Flugg\Responder\Exceptions\Http\ApiException` to `Flugg\Responder\Exceptions\Http\HttpException`
* Renamed `$statusCode` property of the `HttpException` exceptions to `$status`
* Removed `Flugg\Responder\Exceptions\Http\ResourceNotFoundException`, handler now points to `PageNotFoundException`
* Renamed `Flugg\Responder\Serializers\ApiSerializer` to `Flugg\Responder\Serializers\SuccessSerializer`
* Renamed `successResponse` method of the `MakesResponses` trait to `success`
* Renamed `errorResponse` method of the `MakesResponses` trait to `error`
* Return `SuccessResponseBuilder` from `success` method instead of `JsonResponse`
* Return `ErrorResponseBuilder` from `error` method instead of `JsonResponse`
* Renamed `include` method to `with` on `SuccessResponseBuilder`
* Renamed `addMeta` method to `meta` on `SuccessResponseBuilder`
* Removed `transform` method on `SuccessResponseBuilder`, use `success` instead
* Removed `getManager` and `getResource` methods from `SuccessResponseBuilder`
* Changed `transformer` method of the `Transformable` interface to non-static
* Added an `include` prefix to include methods in transformers
* Renamed `transformException` of exception handler trait to `convertDefaultException`
* Renamed `renderApiError` of exception handler trait to `renderResponse`

### Features

* Added configurable response decorators
* Added a `recursion_limit` configuration option
* Allow transforming raw arrays and collections
* Allow sending transformers to the `success` method
* Allow sending resources as data to the `success` method
* Added a `only` method to `SuccessResponseBuilder` to replicate Fractal's `parseFieldsets`
* Added a `cursor` method to `SuccessResponseBuilder` for setting cursors
* Added a `paginator` method to `SuccessResponseBuilder` for setting paginators
* Added a `without` method to `SuccessResponseBuilder` to replicate Fractal's `parseExcludes`
* Relationships are now automatically eager loaded
* Changed `with` method to allow eager loading closures
* Added a `filter_fields_parameter` configuration option for automatic data filtering
* Added a `PageNotFoundException` exception
* Added a `page_not_found` default error code
* Added a `ConvertToSnakeCase` middleware to convert request parameters to snake case
* Added a `Flugg\Responder\Transformer` service to transform without serializing
* Added a `Transformer` facade to transform without serializing
* Added a `transform` helper method to transform without serializing
* Added a `NullSerializer` serializer to serialize without modifying the data
* Added an `ErrorSerializer` contract for serializing errors
* Added a default `Flugg\Responder\Serializers\ErrorSerializer`
* Added a `$load` property to transformers to replicate Fractal's `$defaultIncludes`
* Added a dynamic method in transformers to filter relations: `filterRelationName`
* Allow converting custom exceptions using the `convert` method of the `ConvertsExceptions` trait
* Added a shortcut `-m` to the `--model` modifier of the `make:transformer` command
* Added a `--plain` (and `-p`) option to `make:transformer` to make plain transformers
* Added possibility to bind transformers to models using the `TransformerResolver` class
* Added possibility to bind error messages to error codes using tne `ErrorMessageResolver` class
* Decoupled Fractal from the package by introducing a `TransformFactory` adapter
* Changed `success` to transform using an item resource if passed a has-one relation
* Added a `resource` method to the base `Transformer` for creating related resources

### Bug Fixes

* Remove extra field added from deeply nested relations (fixes #33)
* Relations are not eager loaded when automatically including relations (fixes #48)

### Performance Improvements

* Add a new caching layer to transformers, increasing performance with deeply nested relations
* The relation inclusion code has been drastically improved
39 changes: 28 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "flugger/laravel-responder",
"description": "A Laravel package for APIs, wrapping the Fractal library behind an elegant Laravel API.",
"description": "A Fractal Laravel package for building API responses, giving you the power of Fractal and the elegancy of Laravel.",
"keywords": [
"laravel",
"lumen",
"responder",
"fractal",
"transformer",
"api",
"json",
"response",
"fractal",
"transformer"
"responder"
],
"homepage": "https://github.com/flugger/laravel-responder",
"license": "MIT",
Expand All @@ -21,25 +20,43 @@
],
"require": {
"php": "^7.0",
"illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"league/fractal": ">=0.14.0"
"illuminate/contracts": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*",
"illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*",
"league/fractal": "^0.16.0"
},
"require-dev": {
"phpunit/phpunit": "^5.4",
"illuminate/database": "5.1.* || 5.2.* || 5.3.*",
"illuminate/database": "5.4.*",
"orchestra/testbench": "~3.0",
"mockery/mockery": "^0.9.5",
"fzaninotto/faker": "^1.6",
"doctrine/dbal": "^2.5"
"doctrine/dbal": "^2.5",
"phpunit/phpunit": "^6.1"
},
"autoload": {
"psr-4": {
"Flugg\\Responder\\": "src"
}
},
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"Flugg\\Responder\\Tests\\": "tests"
}
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Flugg\\Responder\\ResponderServiceProvider"
],
"aliases": {
"Responder": "Flugg\\Responder\\Facades\\Responder",
"Transformer": "Flugg\\Responder\\Facades\\Transformer"
}
}
}
}
76 changes: 76 additions & 0 deletions config/responder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Serializer Class Paths
|--------------------------------------------------------------------------
|
| The full class path to the serializer classes you want to use for both
| success- and error responses. The success serializer must implement
| Fractal's serializer. You can override these for every response.
|
*/

'serializers' => [
'success' => Flugg\Responder\Serializers\SuccessSerializer::class,
'error' => \Flugg\Responder\Serializers\ErrorSerializer::class,
],

/*
|--------------------------------------------------------------------------
| Response Decorators
|--------------------------------------------------------------------------
|
| Response decorators are used to decorate both your success- and error
| responses. A decorator can be disabled by removing it from the list
| below. You may additionally add your own decorators to the list.
|
*/

'decorators' => [
\Flugg\Responder\Http\Responses\Decorators\StatusCodeDecorator::class,
\Flugg\Responder\Http\Responses\Decorators\SuccessFlagDecorator::class,
],

/*
|--------------------------------------------------------------------------
| Autoload Relationships With Query String
|--------------------------------------------------------------------------
|
| The package can automatically load relationships from the query string
| and will look for a query string parameter with the name configured
| below. You can set the value to null to disable the autoloading.
|
*/

'load_relations_parameter' => 'with',

/*
|--------------------------------------------------------------------------
| Filter Fields With Query String
|--------------------------------------------------------------------------
|
| The package can automatically filter the fields of transformed data
| from a query string parameter configured below. The technique is
| also known as sparse fieldsets. Set it to null to disable it.
|
*/

'filter_fields_parameter' => 'only',

/*
|--------------------------------------------------------------------------
| Recursion Limit
|--------------------------------------------------------------------------
|
| When transforming data, you may be including relations recursively.
| By setting the value below, you can limit the amount of times it
| should include relationships recursively. Five might be good.
|
*/

'recursion_limit' => 5,

];
4 changes: 2 additions & 2 deletions license.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)

Copyright (c) 2016 Alexander Tømmerås
Copyright (c) 2017 Alexander Tømmerås

> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ Copyright (c) 2016 Alexander Tømmerås
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
> SOFTWARE.
13 changes: 11 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Laravel Responder Test Suite">
<directory>./tests/</directory>
<testsuite name="Unit">
<directory>./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory>./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
Loading

0 comments on commit 6aa0859

Please sign in to comment.