-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9a06c28
Showing
32 changed files
with
10,343 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
|
||
[*.php] | ||
indent_size = 4 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor/ | ||
*.cache | ||
build/logs/clover.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->notPath('vendor') | ||
->in(__DIR__) | ||
->name('*.php') | ||
->ignoreDotFiles(true) | ||
->ignoreVCS(true) | ||
; | ||
|
||
$config = new PhpCsFixer\Config(); | ||
|
||
$config | ||
->setLineEnding("\n") | ||
->setCacheFile(__DIR__.'/.php-cs-fixer.cache') | ||
->setIndent(' ') | ||
->setRules([ | ||
'@Symfony' => true, | ||
'binary_operator_spaces' => ['operators' => ['=>' => 'align']], | ||
'array_syntax' => ['syntax' => 'short'], | ||
'array_indentation' => true, | ||
'linebreak_after_opening_tag' => true, | ||
'not_operator_with_successor_space' => true, | ||
'ordered_imports' => true, | ||
'phpdoc_order' => true, | ||
]) | ||
->setFinder($finder); | ||
|
||
return $config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
preset: laravel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
language: php | ||
|
||
cache: | ||
directories: | ||
- $HOME/.cache/pip | ||
- $HOME/.composer/cache/files | ||
|
||
php: | ||
- 8.0 | ||
|
||
env: | ||
- ILLUMINATE_VERSION=^6.0 PHPUNIT_VERSION=^8.5.0 TESTBENCH_VERSION=^4.0 | ||
- ILLUMINATE_VERSION=^7.0 PHPUNIT_VERSION=^8.5.0 TESTBENCH_VERSION=^5.0 | ||
- ILLUMINATE_VERSION=^8.0 PHPUNIT_VERSION=^9.0.0 TESTBENCH_VERSION=^6.7 COVERAGE=true | ||
|
||
before_install: | ||
- echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini | ||
- cp ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ~/xdebug.ini | ||
- phpenv config-rm xdebug.ini | ||
- composer require "illuminate/http:${ILLUMINATE_VERSION}" "illuminate/support:${ILLUMINATE_VERSION}" "orchestra/testbench:${TESTBENCH_VERSION}" "phpunit/phpunit:${PHPUNIT_VERSION}" --no-update --prefer-dist | ||
|
||
install: travis_retry composer install --no-interaction --prefer-dist | ||
|
||
before_script: phpenv config-add ~/xdebug.ini | ||
|
||
script: composer verify | ||
|
||
after_success: | ||
- | | ||
if [[ $COVERAGE == true && ${TRAVIS_PHP_VERSION:0:3} == "8.0" ]]; then | ||
php vendor/bin/php-coveralls | ||
fi | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"php-cs-fixer.onsave": true, | ||
"editor.formatOnSave": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Audun Rundberg | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Export JSON responses from Laravel to CSV | ||
|
||
[![Build Status](https://app.travis-ci.com/audunru/export-response.svg?branch=master)](https://app.travis-ci.com/audunru/export-response) | ||
[![Coverage Status](https://coveralls.io/repos/github/audunru/export-response/badge.svg?branch=master)](https://coveralls.io/github/audunru/export-response?branch=master) | ||
[![StyleCI](https://github.styleci.io/repos/407671897/shield?branch=master)](https://github.styleci.io/repos/407671897) | ||
|
||
Currently supported: | ||
|
||
- JsonResponse to CSV | ||
|
||
# Installation | ||
|
||
## Step 1: Install with Composer | ||
|
||
```bash | ||
composer require audunru/export-response | ||
``` | ||
|
||
This package depends on [league/csv](https://csv.thephpleague.com/) for the export to CSV. You will have to install this separately. (In the future, this package may support other export formats such as Excel, and not everyone user of this package will need CSV support.) | ||
|
||
```bash | ||
composer require league/csv | ||
``` | ||
|
||
## Step 2: Add middleware to your routes | ||
|
||
To support CSV exports for all your API endpoints, add it to `Kernel.php`: | ||
|
||
```php | ||
'api' => [ | ||
'throttle:api', | ||
\Illuminate\Routing\Middleware\SubstituteBindings::class, | ||
\audunru\ExportResponse\Middleware\ExportCsv::class, | ||
], | ||
``` | ||
|
||
To add it to one particular API resource, you can use this in `api.php`: | ||
|
||
```php | ||
Route::apiResource('documents', DocumentController::class)->middleware(ExportCsv::class)->name('documents'); | ||
``` | ||
|
||
In order to retrieve an API response as CSV instead of JSON, send a request to your API with the `Accept` header set to `text/csv`. | ||
|
||
# Development | ||
|
||
## Testing | ||
|
||
Run tests: | ||
|
||
```bash | ||
composer test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"name": "audunru/export-response", | ||
"description": "Export Laravel JSON to responses to other formats, e.g. CSV", | ||
"keywords": [ | ||
"export", | ||
"laravel", | ||
"json", | ||
"csv" | ||
], | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Audun Rundberg", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0", | ||
"illuminate/http": "^6.0|^7.0|^8.0", | ||
"illuminate/support": "^6.0|^7.0|^8.0", | ||
"spatie/enum": "^3.9", | ||
"spatie/laravel-package-tools": "^1.9" | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^3.0", | ||
"league/csv": "^9.7", | ||
"orchestra/testbench": "^4.0|^5.0|^6.7", | ||
"php-coveralls/php-coveralls": "^2.2", | ||
"phpmd/phpmd": "^2.10", | ||
"phpunit/phpunit": "^8.5|^9.0", | ||
"roave/security-advisories": "dev-latest" | ||
}, | ||
"config": { | ||
"optimize-autoloader": true, | ||
"preferred-install": "dist", | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"autoload": { | ||
"psr-4": { | ||
"audunru\\ExportResponse\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"audunru\\ExportResponse\\Tests\\": "tests/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"audunru\\ExportResponse\\ExportServiceProvider" | ||
] | ||
} | ||
}, | ||
"scripts": { | ||
"test": [ | ||
"php ./vendor/bin/phpunit" | ||
], | ||
"test-with-coverage": [ | ||
"XDEBUG_MODE=coverage php ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml" | ||
], | ||
"fix": [ | ||
"php ./vendor/bin/php-cs-fixer fix --config .php-cs-fixer.dist.php" | ||
], | ||
"verify": [ | ||
"php ./vendor/bin/php-cs-fixer fix --config .php-cs-fixer.dist.php --dry-run", | ||
"php ./vendor/bin/phpmd config,src,tests ansi phpmd-ruleset.xml", | ||
"XDEBUG_MODE=coverage php ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml" | ||
] | ||
} | ||
} |
Oops, something went wrong.