Skip to content

Commit 60c91de

Browse files
authoredJan 2, 2022
Merge pull request #3 from designcise/3.6x
PHP 8.1 Update
2 parents 0a1e06b + 2fbed78 commit 60c91de

24 files changed

+43
-65
lines changed
 

‎.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
dist: bionic
2+
13
cache:
24
apt: true
35
directories:
@@ -6,7 +8,7 @@ cache:
68
language: php
79

810
php:
9-
- 8.0.0
11+
- 8.1.0
1012

1113
env:
1214
- XDEBUG_MODE=coverage

‎LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Portions of the "BitFrame Whoops Middleware" incorporates the work by (as provid
55

66
All other copyright for the "BitFrame Whoops Middleware" are held by:
77

8-
* Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
8+
* Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
99

1010
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:
1111

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Whoops error handler middleware to handle application or middleware specific err
1111
$ composer require "designcise/bitframe-whoops"
1212
```
1313

14-
Please note that this package requires PHP 8.0 or newer.
14+
Please note that this package requires PHP 8.1.0 or newer.
1515

1616
## Quickstart
1717

@@ -45,7 +45,7 @@ For example, to handle middleware-specific errors with `BitFrame\App` (or other
4545
use BitFrame\App;
4646
use BitFrame\Emitter\SapiEmitter;
4747
use BitFrame\Whoops\ErrorHandler;
48-
use \BitFrame\Whoops\Provider\HandlerProviderNegotiator;
48+
use BitFrame\Whoops\Provider\HandlerProviderNegotiator;
4949
use BitFrame\Factory\HttpFactory;
5050

5151
$app = new App();

‎composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=8.0",
14-
"filp/whoops": "~2.7",
13+
"php": ">=8.1",
14+
"filp/whoops": "~2.14",
1515
"psr/http-factory": "~1.0",
1616
"psr/http-server-handler": "~1.0",
1717
"psr/http-server-middleware": "~1.0"

‎src/ErrorHandler.php

+8-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

@@ -37,11 +37,6 @@ class ErrorHandler implements MiddlewareInterface
3737

3838
private RunInterface $whoops;
3939

40-
private ResponseFactoryInterface $responseFactory;
41-
42-
/** @var ProviderInterface|string */
43-
private $handlerProvider;
44-
4540
private array $options;
4641

4742
private bool $catchGlobalErrors;
@@ -50,7 +45,7 @@ class ErrorHandler implements MiddlewareInterface
5045

5146
public static function fromNegotiator(
5247
ResponseFactoryInterface $responseFactory,
53-
array $options = []
48+
array $options = [],
5449
): self {
5550
return new self(
5651
$responseFactory,
@@ -59,19 +54,11 @@ public static function fromNegotiator(
5954
);
6055
}
6156

62-
/**
63-
* @param ResponseFactoryInterface $responseFactory
64-
* @param string|ProviderInterface $handlerProvider
65-
* @param array $options
66-
*/
6757
public function __construct(
68-
ResponseFactoryInterface $responseFactory,
69-
$handlerProvider = HandlerProviderNegotiator::class,
70-
array $options = []
58+
private ResponseFactoryInterface $responseFactory,
59+
private ProviderInterface|string $handlerProvider = HandlerProviderNegotiator::class,
60+
array $options = [],
7161
) {
72-
$this->responseFactory = $responseFactory;
73-
$this->handlerProvider = $handlerProvider;
74-
7562
if (! is_a($this->handlerProvider, ProviderInterface::class, true)) {
7663
throw new InvalidArgumentException(
7764
'Handler provider must be instance of ' . ProviderInterface::class
@@ -91,7 +78,7 @@ public function __construct(
9178
*/
9279
public function process(
9380
ServerRequestInterface $request,
94-
RequestHandlerInterface $handler
81+
RequestHandlerInterface $handler,
9582
): ResponseInterface {
9683
$this->whoops->allowQuit(false);
9784
$this->whoops->writeToOutput($this->catchGlobalErrors);
@@ -131,7 +118,6 @@ public function handleException(Throwable $exception): string
131118

132119
$this->system->startOutputBuffering();
133120

134-
$handlerResponse = null;
135121
$handlerContentType = null;
136122
$handlerStack = array_reverse($this->whoops->getHandlers());
137123

@@ -147,7 +133,7 @@ public function handleException(Throwable $exception): string
147133
? $handler->contentType()
148134
: null;
149135

150-
if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT])) {
136+
if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT], true)) {
151137
break;
152138
}
153139
}
@@ -156,7 +142,7 @@ public function handleException(Throwable $exception): string
156142
}
157143

158144
if ($this->whoops->writeToOutput()) {
159-
if (Misc::canSendHeaders() && $handlerContentType) {
145+
if ($handlerContentType && Misc::canSendHeaders()) {
160146
header("Content-Type: {$handlerContentType}", true, $this->getStatusCode());
161147
}
162148

‎src/Handler/JsonpResponseHandler.php

+3-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

@@ -51,20 +51,13 @@ class JsonpResponseHandler extends Handler
5151

5252
private bool $jsonApi = false;
5353

54-
private string $callback;
55-
56-
private int $encodingOptions;
57-
5854
public function __construct(
59-
string $callback,
60-
int $encodingOptions = self::DEFAULT_ENCODING,
55+
private string $callback,
56+
private int $encodingOptions = self::DEFAULT_ENCODING,
6157
) {
6258
if (! $this->isCallbackValid($callback)) {
6359
throw new InvalidArgumentException('Callback name is invalid');
6460
}
65-
66-
$this->callback = $callback;
67-
$this->encodingOptions = $encodingOptions;
6861
}
6962

7063
public function addTraceToOutput(bool $returnFrames): self
@@ -73,9 +66,6 @@ public function addTraceToOutput(bool $returnFrames): self
7366
return $this;
7467
}
7568

76-
/**
77-
* @return int
78-
*/
7969
public function handle(): int
8070
{
8171
$error = Formatter::formatExceptionAsDataArray(

‎src/HandlerOptionsAwareTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎src/Provider/HandlerProviderNegotiator.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

@@ -19,7 +19,7 @@
1919
use function is_a;
2020
use function asort;
2121
use function array_key_last;
22-
use function strpos;
22+
use function str_contains;
2323

2424
/**
2525
* Detect any of the supported preferred formats from an
@@ -28,19 +28,19 @@
2828
class HandlerProviderNegotiator implements ProviderInterface
2929
{
3030
/** @var string */
31-
public const HTML = 'html';
31+
final public const HTML = 'html';
3232

3333
/** @var string */
34-
public const JSON = 'json';
34+
final public const JSON = 'json';
3535

3636
/** @var string */
37-
public const JSONP = 'jsonp';
37+
final public const JSONP = 'jsonp';
3838

3939
/** @var string */
40-
public const TEXT = 'text';
40+
final public const TEXT = 'text';
4141

4242
/** @var string */
43-
public const XML = 'xml';
43+
final public const XML = 'xml';
4444

4545
private array $handlerProviders = [
4646
self::HTML => HtmlHandlerProvider::class,

‎src/Provider/HtmlHandlerProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎src/Provider/JsonHandlerProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎src/Provider/JsonpHandlerProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎src/Provider/ProviderInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎src/Provider/TextHandlerProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎src/Provider/XmlHandlerProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎test/Asset/MiddlewareDecoratorTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎test/Asset/MiddlewareHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎test/ErrorHandlerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎test/Handler/JsonpResponseHandlerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎test/Provider/HandlerProviderNegotiatorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎test/Provider/HtmlHandlerProviderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎test/Provider/JsonHandlerProviderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎test/Provider/JsonpHandlerProviderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎test/Provider/TextHandlerProviderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

‎test/Provider/XmlHandlerProviderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* BitFrame Framework (https://www.bitframephp.com)
55
*
66
* @author Daniyal Hamid
7-
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
7+
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
88
* @license https://bitframephp.com/about/license MIT License
99
*/
1010

0 commit comments

Comments
 (0)