diff --git a/.travis.yml b/.travis.yml index 8fed667..b56904d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +dist: bionic + cache: apt: true directories: @@ -6,7 +8,7 @@ cache: language: php php: - - 8.0.0 + - 8.1.0 env: - XDEBUG_MODE=coverage diff --git a/LICENSE.md b/LICENSE.md index 21a2cf3..c0aae9a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -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: diff --git a/README.md b/README.md index f211b9a..8763052 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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(); diff --git a/composer.json b/composer.json index e938d38..04a9306 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/src/ErrorHandler.php b/src/ErrorHandler.php index caac548..000f591 100644 --- a/src/ErrorHandler.php +++ b/src/ErrorHandler.php @@ -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 */ @@ -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; @@ -50,7 +45,7 @@ class ErrorHandler implements MiddlewareInterface public static function fromNegotiator( ResponseFactoryInterface $responseFactory, - array $options = [] + array $options = [], ): self { return new self( $responseFactory, @@ -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 @@ -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); @@ -131,7 +118,6 @@ public function handleException(Throwable $exception): string $this->system->startOutputBuffering(); - $handlerResponse = null; $handlerContentType = null; $handlerStack = array_reverse($this->whoops->getHandlers()); @@ -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; } } @@ -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()); } diff --git a/src/Handler/JsonpResponseHandler.php b/src/Handler/JsonpResponseHandler.php index 05ffe50..b2ebd22 100644 --- a/src/Handler/JsonpResponseHandler.php +++ b/src/Handler/JsonpResponseHandler.php @@ -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 */ @@ -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 @@ -73,9 +66,6 @@ public function addTraceToOutput(bool $returnFrames): self return $this; } - /** - * @return int - */ public function handle(): int { $error = Formatter::formatExceptionAsDataArray( diff --git a/src/HandlerOptionsAwareTrait.php b/src/HandlerOptionsAwareTrait.php index a5c35e8..4843e7a 100644 --- a/src/HandlerOptionsAwareTrait.php +++ b/src/HandlerOptionsAwareTrait.php @@ -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 */ diff --git a/src/Provider/HandlerProviderNegotiator.php b/src/Provider/HandlerProviderNegotiator.php index 3471d44..9f99c11 100644 --- a/src/Provider/HandlerProviderNegotiator.php +++ b/src/Provider/HandlerProviderNegotiator.php @@ -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 */ @@ -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 @@ -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, diff --git a/src/Provider/HtmlHandlerProvider.php b/src/Provider/HtmlHandlerProvider.php index cdf0819..18efd99 100644 --- a/src/Provider/HtmlHandlerProvider.php +++ b/src/Provider/HtmlHandlerProvider.php @@ -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 */ diff --git a/src/Provider/JsonHandlerProvider.php b/src/Provider/JsonHandlerProvider.php index 9643ccc..116c64c 100644 --- a/src/Provider/JsonHandlerProvider.php +++ b/src/Provider/JsonHandlerProvider.php @@ -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 */ diff --git a/src/Provider/JsonpHandlerProvider.php b/src/Provider/JsonpHandlerProvider.php index db01703..d99e3a2 100644 --- a/src/Provider/JsonpHandlerProvider.php +++ b/src/Provider/JsonpHandlerProvider.php @@ -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 */ diff --git a/src/Provider/ProviderInterface.php b/src/Provider/ProviderInterface.php index b76c3a8..94c5154 100644 --- a/src/Provider/ProviderInterface.php +++ b/src/Provider/ProviderInterface.php @@ -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 */ diff --git a/src/Provider/TextHandlerProvider.php b/src/Provider/TextHandlerProvider.php index 29d5830..4e1fa89 100644 --- a/src/Provider/TextHandlerProvider.php +++ b/src/Provider/TextHandlerProvider.php @@ -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 */ diff --git a/src/Provider/XmlHandlerProvider.php b/src/Provider/XmlHandlerProvider.php index 38b3a29..ba994f1 100644 --- a/src/Provider/XmlHandlerProvider.php +++ b/src/Provider/XmlHandlerProvider.php @@ -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 */ diff --git a/test/Asset/MiddlewareDecoratorTrait.php b/test/Asset/MiddlewareDecoratorTrait.php index 81ca6b6..007fb88 100644 --- a/test/Asset/MiddlewareDecoratorTrait.php +++ b/test/Asset/MiddlewareDecoratorTrait.php @@ -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 */ diff --git a/test/Asset/MiddlewareHandler.php b/test/Asset/MiddlewareHandler.php index 45c0091..9f781e5 100644 --- a/test/Asset/MiddlewareHandler.php +++ b/test/Asset/MiddlewareHandler.php @@ -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 */ diff --git a/test/ErrorHandlerTest.php b/test/ErrorHandlerTest.php index e9e955f..bcdece4 100644 --- a/test/ErrorHandlerTest.php +++ b/test/ErrorHandlerTest.php @@ -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 */ diff --git a/test/Handler/JsonpResponseHandlerTest.php b/test/Handler/JsonpResponseHandlerTest.php index 5e15153..bf814a2 100644 --- a/test/Handler/JsonpResponseHandlerTest.php +++ b/test/Handler/JsonpResponseHandlerTest.php @@ -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 */ diff --git a/test/Provider/HandlerProviderNegotiatorTest.php b/test/Provider/HandlerProviderNegotiatorTest.php index 3b85698..88a5fd4 100644 --- a/test/Provider/HandlerProviderNegotiatorTest.php +++ b/test/Provider/HandlerProviderNegotiatorTest.php @@ -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 */ diff --git a/test/Provider/HtmlHandlerProviderTest.php b/test/Provider/HtmlHandlerProviderTest.php index 2cbc671..a06a25a 100644 --- a/test/Provider/HtmlHandlerProviderTest.php +++ b/test/Provider/HtmlHandlerProviderTest.php @@ -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 */ diff --git a/test/Provider/JsonHandlerProviderTest.php b/test/Provider/JsonHandlerProviderTest.php index ffd6b68..ccb853f 100644 --- a/test/Provider/JsonHandlerProviderTest.php +++ b/test/Provider/JsonHandlerProviderTest.php @@ -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 */ diff --git a/test/Provider/JsonpHandlerProviderTest.php b/test/Provider/JsonpHandlerProviderTest.php index 5b32d7f..0f8f982 100644 --- a/test/Provider/JsonpHandlerProviderTest.php +++ b/test/Provider/JsonpHandlerProviderTest.php @@ -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 */ diff --git a/test/Provider/TextHandlerProviderTest.php b/test/Provider/TextHandlerProviderTest.php index d602162..11d9b6d 100644 --- a/test/Provider/TextHandlerProviderTest.php +++ b/test/Provider/TextHandlerProviderTest.php @@ -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 */ diff --git a/test/Provider/XmlHandlerProviderTest.php b/test/Provider/XmlHandlerProviderTest.php index 235b35d..2197bb1 100644 --- a/test/Provider/XmlHandlerProviderTest.php +++ b/test/Provider/XmlHandlerProviderTest.php @@ -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 */