Skip to content

Commit b329055

Browse files
authored
Support Laravel 9 (#4)
* support php8 * fix travis redis ext * update travisci * switch to Github actions * update readme, add support for L9 * remove L7 from github actions * add redis to github actions * forward redis port * upgrade php cs fixer to v3
1 parent 2144a1e commit b329055

File tree

8 files changed

+134
-197
lines changed

8 files changed

+134
-197
lines changed

.github/workflows/test.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: run-tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
14+
runs-on: ${{ matrix.os }}
15+
16+
strategy:
17+
fail-fast: true
18+
matrix:
19+
# Disable testing on windows for now...
20+
# os: [ubuntu-latest, windows-latest]
21+
os: [ubuntu-latest]
22+
php: [7.4, 8.0, 8.1]
23+
laravel: [8.*, 9.*]
24+
#stability: [prefer-lowest, prefer-stable]
25+
stability: [prefer-stable]
26+
include:
27+
- laravel: 8.*
28+
testbench: ^6.6
29+
- laravel: 9.*
30+
testbench: 7.*
31+
# Laravel 7 has no support for PHP 8.1
32+
exclude:
33+
# Laravel 9 doesn't support < PHP 8
34+
- laravel: 9.*
35+
php: 7.4
36+
37+
services:
38+
redis:
39+
image: redis
40+
ports:
41+
- 6379:6379
42+
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
43+
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v2
47+
48+
- name: Setup PHP
49+
uses: shivammathur/setup-php@v2
50+
with:
51+
php-version: ${{ matrix.php }}
52+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
53+
coverage: none
54+
55+
- name: Setup problem matchers
56+
run: |
57+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
58+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
59+
- name: Install dependencies
60+
run: |
61+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
62+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
63+
- name: Execute tests
64+
run: vendor/bin/phpunit

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ docs
44
vendor
55
coverage
66
laravel.log
7-
.phpunit.result.cache
7+
.phpunit.result.cache
8+
.php-cs-fixer.cache

.php-cs-fixer.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
$finder = Symfony\Component\Finder\Finder::create()
4+
->notPath('vendor')
5+
->in([
6+
__DIR__ . '/src',
7+
__DIR__ . '/tests',
8+
__DIR__ . '/config',
9+
])
10+
->name('*.php')
11+
->notName('*.blade.php')
12+
->ignoreDotFiles(true)
13+
->ignoreVCS(true);
14+
15+
$config = new PhpCsFixer\Config();
16+
17+
return $config->setRules([
18+
'@PSR2' => true,
19+
'array_syntax' => ['syntax' => 'short'],
20+
'ordered_imports' => ['sort_algorithm' => 'length'],
21+
'no_unused_imports' => true,
22+
'not_operator_with_successor_space' => true,
23+
'trailing_comma_in_multiline' => true,
24+
'phpdoc_scalar' => true,
25+
'unary_operator_spaces' => true,
26+
'binary_operator_spaces' => true,
27+
'blank_line_before_statement' => [
28+
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
29+
],
30+
'phpdoc_single_line_var_spacing' => true,
31+
'phpdoc_var_without_name' => true,
32+
'class_attributes_separation' => [
33+
'elements' => [
34+
'method' => 'one',
35+
],
36+
],
37+
'method_argument_space' => [
38+
'on_multiline' => 'ensure_fully_multiline',
39+
'keep_multiple_spaces_after_comma' => true,
40+
],
41+
'single_trait_insert_per_statement' => true,
42+
])
43+
->setFinder($finder);

.php_cs

Lines changed: 0 additions & 145 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

README.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
# Idempotent endpoints in Laravel à la Stripe
1+
# Laravel Playback
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/swiftmade/playback.svg?style=flat-square)](https://packagist.org/packages/swiftmade/playback)
4-
[![Build Status](https://img.shields.io/travis/swiftmade/playback/master.svg?style=flat-square)](https://travis-ci.org/swiftmade/playback)
4+
![GitHub Actions](https://github.com/swiftmade/playback/actions/workflows/test.yml/badge.svg)
55
[![Total Downloads](https://img.shields.io/packagist/dt/swiftmade/playback.svg?style=flat-square)](https://packagist.org/packages/swiftmade/playback)
66

7-
Do you need idempotent endpoints in Laravel? This package handles just that.
7+
_Idempotent endpoints in Laravel à la Stripe._
88

9-
What's even idempotency? What should you care?
10-
- https://stripe.com/docs/api/idempotent_requests
9+
Playback gives you idempotent endpoints in Laravel, using Redis locks. [What's even idempotency, and why should I care?](https://stripe.com/docs/api/idempotent_requests)
1110

1211
## Features
1312

14-
- Apply it to a single route, or apply to your whole API...
15-
- Works only for POST requests. Other endpoints are ignored.
16-
- Smart enough to verify path + headers + body is identical before returning the response.
17-
- Will record and play back 2xx and 5xx responses, without touching your controller again.
18-
- Doesn't remember the response if there was a validation error (4xx). So it's safe to retry.
19-
- Prevents race conditions using Laravel's support for cache locks.
13+
- 📼 Records and plays back 2xx and 5xx responses, without running your controller code again.
14+
- 🔐 Built-in validation to prevent attacks by stolen/guessed idempotency keys.
15+
- ⚠️ Won't store the response if there was a validation error (4xx).
16+
- 🏎 Prevents race conditions using atomical Redis locks.
2017

2118
## Installation
2219

23-
> 💡 Currently, we only support Laravel 8.x.
20+
> 💡 Supports Laravel 8.x, Laravel 9.x on PHP 7.4, 8.0 or 8.1
2421
2522
1. You can install the package via composer:
2623

@@ -45,7 +42,7 @@ Open `config/cache.php` and add a new store.
4542
'driver' => 'redis',
4643
// 👇🏻 Caution!
4744
// You probably don't want to use the cache connection in production.
48-
// Playback cache can grow to a huge size for busy applications.
45+
// Playback cache can grow to a big size for busy applications.
4946
// Make sure your redis instance is ready.
5047
'connection' => 'cache',
5148
],
@@ -56,7 +53,7 @@ Open `config/cache.php` and add a new store.
5653

5754
Just apply the `Swiftmade\Playback\Playback` middleware to your endpoints. There are many ways of doing it, so here's a link to the docs:
5855

59-
- https://laravel.com/docs/8.x/middleware
56+
- https://laravel.com/docs/9.x/middleware
6057

6158
## Use
6259

@@ -72,17 +69,17 @@ If the key is not found during the lookup, a race begins. The first request to a
7269

7370
#### Errors:
7471

75-
+ **400 Bad Request**
76-
If you get back status `400`, it means your request was not identical to the cached one. It's the client's responsibility to repeat the exact same request. This is also why another user can't steal a response just by stealing/guessing the idempotency key. The cookies/authentication token would be different, which fails the signature check.
72+
- **400 Bad Request**
73+
If you get back status `400`, it means your request was not identical to the cached one. It's the client's responsibility to repeat the exact same request. This is also why another user can't steal a response just by stealing/guessing the idempotency key. The cookies/authentication token would be different, which fails the signature check.
7774

78-
+ **425 Too Early**
79-
If you get this error, it means you retried too fast after your initial attempt. Don't panic and try again a second later or so. It's perfectly safe to do so!
75+
- **425 Too Early**
76+
If you get this error, it means you retried too fast after your initial attempt. Don't panic and try again a second later or so. It's perfectly safe to do so!
8077

8178
🚨 Pro tip: If your controller action returns 4xx or 3xx status code, Playback won't cache the response. It's your responsibility to ensure no side effects take place (or they are rolled back) if a validation fails, a related db record was not found, etc and therefore the response status is 4xx or 3xx.
8279

8380
### Testing
8481

85-
``` bash
82+
```bash
8683
composer test
8784
```
8885

@@ -100,9 +97,9 @@ If you discover any security related issues, please email [email protected] ins
10097

10198
## Credits
10299

103-
- [Ahmet Özisik](https://github.com/swiftmade)
104-
- [All Contributors](../../contributors)
100+
- [Ahmet Özisik](https://github.com/swiftmade)
101+
- [All Contributors](../../contributors)
105102

106103
## License
107104

108-
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
105+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

0 commit comments

Comments
 (0)