Skip to content

Commit

Permalink
Merge pull request #3 from designcise/3.6x
Browse files Browse the repository at this point in the history
PHP 8.1 Update
  • Loading branch information
designcise authored Jan 2, 2022
2 parents 0a1e06b + 2fbed78 commit 60c91de
Show file tree
Hide file tree
Showing 24 changed files with 43 additions and 65 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dist: bionic

cache:
apt: true
directories:
Expand All @@ -6,7 +8,7 @@ cache:
language: php

php:
- 8.0.0
- 8.1.0

env:
- XDEBUG_MODE=coverage
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Portions of the "BitFrame Whoops Middleware" incorporates the work by (as provid

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

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

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:

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Whoops error handler middleware to handle application or middleware specific err
$ composer require "designcise/bitframe-whoops"
```

Please note that this package requires PHP 8.0 or newer.
Please note that this package requires PHP 8.1.0 or newer.

## Quickstart

Expand Down Expand Up @@ -45,7 +45,7 @@ For example, to handle middleware-specific errors with `BitFrame\App` (or other
use BitFrame\App;
use BitFrame\Emitter\SapiEmitter;
use BitFrame\Whoops\ErrorHandler;
use \BitFrame\Whoops\Provider\HandlerProviderNegotiator;
use BitFrame\Whoops\Provider\HandlerProviderNegotiator;
use BitFrame\Factory\HttpFactory;

$app = new App();
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}
],
"require": {
"php": ">=8.0",
"filp/whoops": "~2.7",
"php": ">=8.1",
"filp/whoops": "~2.14",
"psr/http-factory": "~1.0",
"psr/http-server-handler": "~1.0",
"psr/http-server-middleware": "~1.0"
Expand Down
30 changes: 8 additions & 22 deletions src/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down Expand Up @@ -37,11 +37,6 @@ class ErrorHandler implements MiddlewareInterface

private RunInterface $whoops;

private ResponseFactoryInterface $responseFactory;

/** @var ProviderInterface|string */
private $handlerProvider;

private array $options;

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

public static function fromNegotiator(
ResponseFactoryInterface $responseFactory,
array $options = []
array $options = [],
): self {
return new self(
$responseFactory,
Expand All @@ -59,19 +54,11 @@ public static function fromNegotiator(
);
}

/**
* @param ResponseFactoryInterface $responseFactory
* @param string|ProviderInterface $handlerProvider
* @param array $options
*/
public function __construct(
ResponseFactoryInterface $responseFactory,
$handlerProvider = HandlerProviderNegotiator::class,
array $options = []
private ResponseFactoryInterface $responseFactory,
private ProviderInterface|string $handlerProvider = HandlerProviderNegotiator::class,
array $options = [],
) {
$this->responseFactory = $responseFactory;
$this->handlerProvider = $handlerProvider;

if (! is_a($this->handlerProvider, ProviderInterface::class, true)) {
throw new InvalidArgumentException(
'Handler provider must be instance of ' . ProviderInterface::class
Expand All @@ -91,7 +78,7 @@ public function __construct(
*/
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
RequestHandlerInterface $handler,
): ResponseInterface {
$this->whoops->allowQuit(false);
$this->whoops->writeToOutput($this->catchGlobalErrors);
Expand Down Expand Up @@ -131,7 +118,6 @@ public function handleException(Throwable $exception): string

$this->system->startOutputBuffering();

$handlerResponse = null;
$handlerContentType = null;
$handlerStack = array_reverse($this->whoops->getHandlers());

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

if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT])) {
if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT], true)) {
break;
}
}
Expand All @@ -156,7 +142,7 @@ public function handleException(Throwable $exception): string
}

if ($this->whoops->writeToOutput()) {
if (Misc::canSendHeaders() && $handlerContentType) {
if ($handlerContentType && Misc::canSendHeaders()) {
header("Content-Type: {$handlerContentType}", true, $this->getStatusCode());
}

Expand Down
16 changes: 3 additions & 13 deletions src/Handler/JsonpResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down Expand Up @@ -51,20 +51,13 @@ class JsonpResponseHandler extends Handler

private bool $jsonApi = false;

private string $callback;

private int $encodingOptions;

public function __construct(
string $callback,
int $encodingOptions = self::DEFAULT_ENCODING,
private string $callback,
private int $encodingOptions = self::DEFAULT_ENCODING,
) {
if (! $this->isCallbackValid($callback)) {
throw new InvalidArgumentException('Callback name is invalid');
}

$this->callback = $callback;
$this->encodingOptions = $encodingOptions;
}

public function addTraceToOutput(bool $returnFrames): self
Expand All @@ -73,9 +66,6 @@ public function addTraceToOutput(bool $returnFrames): self
return $this;
}

/**
* @return int
*/
public function handle(): int
{
$error = Formatter::formatExceptionAsDataArray(
Expand Down
2 changes: 1 addition & 1 deletion src/HandlerOptionsAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
14 changes: 7 additions & 7 deletions src/Provider/HandlerProviderNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand All @@ -19,7 +19,7 @@
use function is_a;
use function asort;
use function array_key_last;
use function strpos;
use function str_contains;

/**
* Detect any of the supported preferred formats from an
Expand All @@ -28,19 +28,19 @@
class HandlerProviderNegotiator implements ProviderInterface
{
/** @var string */
public const HTML = 'html';
final public const HTML = 'html';

/** @var string */
public const JSON = 'json';
final public const JSON = 'json';

/** @var string */
public const JSONP = 'jsonp';
final public const JSONP = 'jsonp';

/** @var string */
public const TEXT = 'text';
final public const TEXT = 'text';

/** @var string */
public const XML = 'xml';
final public const XML = 'xml';

private array $handlerProviders = [
self::HTML => HtmlHandlerProvider::class,
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/HtmlHandlerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Provider/JsonHandlerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Provider/JsonpHandlerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Provider/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Provider/TextHandlerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Provider/XmlHandlerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Asset/MiddlewareDecoratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Asset/MiddlewareHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Handler/JsonpResponseHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Provider/HandlerProviderNegotiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Provider/HtmlHandlerProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Provider/JsonHandlerProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Provider/JsonpHandlerProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Provider/TextHandlerProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Provider/XmlHandlerProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2021 Daniyal Hamid (https://designcise.com)
* @copyright Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/

Expand Down

0 comments on commit 60c91de

Please sign in to comment.