Skip to content

Commit 2604972

Browse files
authored
Merge pull request #2 from quick-order/v1.13.0
Upgrade fork to resemble upstream at tag 1.13.0
2 parents 3f2b1c0 + 67f683c commit 2604972

19 files changed

+299
-93
lines changed
File renamed without changes.

.github/SECURITY.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Security Policy
2+
3+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.

.github/workflows/php-cs-fixer.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Check & fix styling
2+
3+
on: [push]
4+
5+
jobs:
6+
style:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v2
12+
13+
- name: Fix style
14+
uses: docker://oskarstark/php-cs-fixer-ga
15+
with:
16+
args: --config=.php_cs --allow-risky=yes
17+
18+
- name: Extract branch name
19+
shell: bash
20+
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
21+
id: extract_branch
22+
23+
- name: Commit changes
24+
uses: stefanzweifel/[email protected]
25+
with:
26+
commit_message: Fix styling
27+
branch: ${{ steps.extract_branch.outputs.branch }}
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/run-tests.yml

+6-12
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,23 @@ jobs:
99
strategy:
1010
fail-fast: true
1111
matrix:
12-
php: [7.4]
13-
laravel: [7.*, 6.*, 5.8.*]
14-
os: [ubuntu-latest, windows-latest]
12+
php: [8.0, 7.4]
13+
laravel: [8.*, 7.*, 6.*]
14+
os: [ubuntu-latest]
1515
dependency-version: [prefer-lowest, prefer-stable]
1616
include:
17+
- laravel: 8.*
18+
testbench: 6.*
1719
- laravel: 7.*
1820
testbench: 5.*
1921
- laravel: 6.*
2022
testbench: 4.*
21-
- laravel: 5.8.*
22-
testbench: 3.8.*
2323

2424
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
2525

2626
steps:
2727
- name: Checkout code
28-
uses: actions/checkout@v1
29-
30-
- name: Cache dependencies
31-
uses: actions/cache@v1
32-
with:
33-
path: ~/.composer/cache/files
34-
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
28+
uses: actions/checkout@v2
3529

3630
- name: Setup PHP
3731
uses: shivammathur/setup-php@v2

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ composer.lock
33
docs
44
vendor
55
coverage
6-
.idea/
6+
.php_cs.cache
7+
.idea/

.php_cs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
$finder = Symfony\Component\Finder\Finder::create()
4+
->notPath('bootstrap/*')
5+
->notPath('storage/*')
6+
->notPath('vendor')
7+
->in([
8+
__DIR__ . '/src',
9+
__DIR__ . '/tests',
10+
])
11+
->name('*.php')
12+
->notName('*.blade.php')
13+
->ignoreDotFiles(true)
14+
->ignoreVCS(true);
15+
16+
return PhpCsFixer\Config::create()
17+
->setRules([
18+
'@PSR2' => true,
19+
'array_syntax' => ['syntax' => 'short'],
20+
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
21+
'no_unused_imports' => true,
22+
'not_operator_with_successor_space' => true,
23+
'trailing_comma_in_multiline_array' => 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', 'property',
35+
],
36+
],
37+
'method_argument_space' => [
38+
'on_multiline' => 'ensure_fully_multiline',
39+
'keep_multiple_spaces_after_comma' => true,
40+
]
41+
])
42+
->setFinder($finder);

.scrutinizer.yml

-19
This file was deleted.

.styleci.yml

-5
This file was deleted.

CHANGELOG.md

+40
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,46 @@
22

33
All notable changes to `laravel-webhook-server` will be documented in this file
44

5+
## 1.13.0 - 2021-04-28
6+
7+
- add `dispatchSync`
8+
9+
## 1.12.0 - 2021-04-20
10+
11+
- pass Guzzle TransferStats into resulting Event (#81)
12+
13+
## 1.11.3 - 2021-04-02
14+
15+
- fix for missing default headers when using withHeaders (#79)
16+
17+
## 1.11.2 - 2021-03-17
18+
19+
- dispatch should return the PendingDispatch (#74)
20+
21+
## 1.11.1 - 2020-12-15
22+
23+
- fix exception name for invalid signers (#67)
24+
25+
## 1.11.0 - 2020-11-28
26+
27+
- add support for PHP 8
28+
29+
## 1.10.0 - 2020-10-04
30+
31+
- add `getUuid`
32+
33+
## 1.9.3 - 2020-09-09
34+
35+
- support Guzzle 7
36+
37+
## 1.9.2 - 2020-09-09
38+
39+
- support Laravel 8
40+
41+
## 1.9.1 - 2020-04-10
42+
43+
- do not use body in GET request (#43)
44+
545
## 1.9.0 - 2020-03-19
646

747
- add `doNotSign`

README.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-webhook-server.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-webhook-server)
44
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/spatie/laravel-webhook-server/run-tests?label=tests)
5-
[![Quality Score](https://img.shields.io/scrutinizer/g/spatie/laravel-webhook-server.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/laravel-webhook-server)
6-
[![StyleCI](https://github.styleci.io/repos/191252974/shield?branch=master)](https://github.styleci.io/repos/191252974)
75
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-webhook-server.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-webhook-server)
86

97
A webhook is a way for an app to provide information to another app about a particular event. The way the two apps communicate is with a simple HTTP request.
@@ -14,7 +12,9 @@ If you need to receive and process webhooks take a look at our [laravel-webhook-
1412

1513
## Support us
1614

17-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
15+
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-webhook-server.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-webhook-server)
16+
17+
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
1818

1919
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
2020

@@ -115,7 +115,6 @@ WebhookCall::create()
115115
->dispatchNow();
116116
```
117117

118-
119118
### How signing requests works
120119

121120
When setting up, it's common to generate, store, and share a secret between your app and the app that wants to receive webhooks. Generating the secret could be done with `Illuminate\Support\Str::random()`, but it's entirely up to you. The package will use the secret to sign a webhook call.
@@ -143,7 +142,6 @@ WebhookCall::create()
143142

144143
By calling this method, the `Signature` header will not be set.
145144

146-
147145
### Customizing signing requests
148146

149147
If you want to customize the signing process, you can create your own custom signer. A signer is any class that implements `Spatie\WebhookServer\Signer`.
@@ -220,7 +218,6 @@ WebhookCall::create()
220218

221219
Under the hood, the retrying of the webhook calls is implemented using [delayed dispatching](https://laravel.com/docs/master/queues#delayed-dispatching). Amazon SQS only has support for a small maximum delay. If you're using Amazon SQS for your queues, make sure you do not configure the package in a way so there are more than 15 minutes between each attempt.
222220

223-
224221
### Customizing the HTTP verb
225222

226223
By default, all webhooks will use the `post` method. You can customize that by specifying the HTTP verb you want in the `http_verb` key of the `webhook-server` config file.
@@ -289,7 +286,7 @@ WebhookCall::create()
289286
### Exception handling
290287
By default, the package will not log any exceptions that are thrown when sending a webhook.
291288

292-
To handle exceptions you need to create listen for the `Spatie\WebhookServer\Events\WebhookCallFailedEvent` and/or `Spatie\WebhookServer\Events|FinalWebhookCallFailedEvent` events.
289+
To handle exceptions you need to create listeners for the `Spatie\WebhookServer\Events\WebhookCallFailedEvent` and/or `Spatie\WebhookServer\Events\FinalWebhookCallFailedEvent` events.
293290

294291
### Events
295292

@@ -332,7 +329,7 @@ If you discover any security-related issues, please email [email protected] instea
332329

333330
You're free to use this package, but if it makes it to your production environment, we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
334331

335-
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
332+
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
336333

337334
We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).
338335

composer.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
}
1919
],
2020
"require": {
21-
"php": "^7.3",
21+
"php": "^8.0|^7.4",
2222
"ext-json": "*",
23-
"guzzlehttp/guzzle": "^7.0.1",
24-
"illuminate/bus": "^5.8|^6.0|^7.0|^8.0",
25-
"illuminate/queue": "^5.8|^6.0|^7.0|^8.0",
26-
"illuminate/support": "^5.8|^6.0|^7.0|^8.0"
23+
"guzzlehttp/guzzle": "^6.3|^7.0",
24+
"illuminate/bus": "^6.0|^7.0|^8.0",
25+
"illuminate/queue": "^6.0|^7.0|^8.0",
26+
"illuminate/support": "^6.0|^7.0|^8.0"
2727
},
2828
"require-dev": {
29-
"mockery/mockery": "^1.3",
30-
"orchestra/testbench": "^3.8|^4.0|^5.0|^6.0",
31-
"phpunit/phpunit": "^8.4|^9.0",
32-
"spatie/test-time": "^1.0"
29+
"mockery/mockery": "^1.4",
30+
"orchestra/testbench": "^4.0|^5.0|^6.0",
31+
"phpunit/phpunit": "^9.4",
32+
"spatie/test-time": "^1.2"
3333
},
3434
"autoload": {
3535
"psr-4": {

phpunit.xml.dist

+14-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
verbose="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false">
12-
<testsuites>
13-
<testsuite name="Spatie Test Suite">
14-
<directory>tests</directory>
15-
</testsuite>
16-
</testsuites>
17-
<php>
18-
<env name="QUEUE_CONNECTION" value="database"/>
19-
</php>
20-
<filter>
21-
<whitelist>
22-
<directory suffix=".php">src/</directory>
23-
</whitelist>
24-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Spatie Test Suite">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<php>
14+
<env name="QUEUE_CONNECTION" value="database"/>
15+
</php>
2516
</phpunit>

src/CallWebhookJob.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use GuzzleHttp\Exception\ConnectException;
88
use GuzzleHttp\Exception\RequestException;
99
use GuzzleHttp\Psr7\Response;
10+
use GuzzleHttp\TransferStats;
1011
use Illuminate\Bus\Queueable;
1112
use Illuminate\Contracts\Queue\ShouldQueue;
1213
use Illuminate\Foundation\Bus\Dispatchable;
@@ -59,20 +60,28 @@ class CallWebhookJob implements ShouldQueue
5960

6061
private $errorMessage = null;
6162

62-
public function handle() {
63+
private ?TransferStats $transferStats = null;
6364

65+
public function handle()
66+
{
6467
/** @var \GuzzleHttp\Client $client */
6568
$client = app(Client::class);
6669

6770
$lastAttempt = $this->attempts() >= $this->tries;
6871

6972
try {
70-
$this->response = $client->request($this->httpVerb, $this->webhookUrl, [
73+
$body = strtoupper($this->httpVerb) === 'GET'
74+
? ['query' => $this->payload]
75+
: ['body' => json_encode($this->payload)];
76+
77+
$this->response = $client->request($this->httpVerb, $this->webhookUrl, array_merge([
7178
'timeout' => $this->requestTimeout,
72-
'body' => json_encode($this->payload),
7379
'verify' => $this->verifySsl,
7480
'headers' => $this->headers,
75-
]);
81+
'on_stats' => function (TransferStats $stats) {
82+
$this->transferStats = $stats;
83+
},
84+
], $body));
7685

7786
if (! Str::startsWith($this->response->getStatusCode(), 2)) {
7887
throw new Exception('Webhook call failed');
@@ -135,7 +144,8 @@ private function dispatchEvent(string $eventClass)
135144
$this->response,
136145
$this->errorType,
137146
$this->errorMessage,
138-
$this->uuid
147+
$this->uuid,
148+
$this->transferStats
139149
));
140150
}
141151
}

0 commit comments

Comments
 (0)