diff --git a/.travis.yml b/.travis.yml index 47134ff..07342d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,8 @@ language: php php: - - '7.3' - - '7.4' + - '8.0' before_script: - - yes '' | pecl install yaml - composer install script: diff --git a/CHANGELOG.md b/CHANGELOG.md index e616d5c..31608d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 3.1.0 - 2021-04-03 + +### Added +- Support for PHP8 + +### Changed +- Support from `ulrack/services` to `grizz-it/services`. + ## 3.0.1 - 2021-01-17 ### Fixed @@ -43,7 +51,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The initial implementation of the package. # Versions -- [3.0.1 > Unreleased](https://github.com/ulrack/web/compare/3.0.1...HEAD) +- [3.1.0 > Unreleased](https://github.com/ulrack/web/compare/3.1.0...HEAD) +- [3.0.1 > 3.1.0](https://github.com/ulrack/web/compare/3.0.1...3.1.0) - [3.0.0 > 3.0.1](https://github.com/ulrack/web/compare/3.0.0...3.0.1) - [2.0.0 > 3.0.0](https://github.com/ulrack/web/compare/2.0.0...3.0.0) - [1.0.1 > 2.0.0](https://github.com/ulrack/web/compare/1.0.1...2.0.0) diff --git a/composer.json b/composer.json index 3c4b4f4..93e65e1 100644 --- a/composer.json +++ b/composer.json @@ -11,13 +11,13 @@ "prefer-stable": true, "minimum-stability": "stable", "require": { - "php": "^7.3", - "grizz-it/codec": "^1.0", - "grizz-it/configuration": "^1.1", - "grizz-it/enum": "^1.0", - "grizz-it/http": "^1.0", - "grizz-it/translator": "^1.1", - "ulrack/services": "^3.0" + "php": "^8.0", + "grizz-it/codec": "^1.1", + "grizz-it/configuration": "^1.3", + "grizz-it/enum": "^1.1", + "grizz-it/http": "^1.1", + "grizz-it/services": "^1.0", + "grizz-it/translator": "^1.2" }, "authors": [ { @@ -55,7 +55,7 @@ ] }, "require-dev": { - "phpunit/phpunit": "^9.3", + "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3.5" } } diff --git a/docs/usage/error.md b/docs/usage/error.md index 0c310f1..1c6bf99 100644 --- a/docs/usage/error.md +++ b/docs/usage/error.md @@ -13,11 +13,13 @@ services. These are A definition for an error looks like the following: ```json { - "web.errors.default.api.400": { - "class": "\\Ulrack\\Web\\Component\\Error\\ConfigurableApiError", - "parameters": { - "errorStatusCode": 400, - "errorMessage": "Bad Request" + "services": { + "web.errors.default.api.400": { + "class": "\\Ulrack\\Web\\Component\\Error\\ConfigurableApiError", + "parameters": { + "errorStatusCode": 400, + "errorMessage": "Bad Request" + } } } } diff --git a/src/Common/Endpoint/InputInterface.php b/src/Common/Endpoint/InputInterface.php index bf1ec34..dbbff8b 100644 --- a/src/Common/Endpoint/InputInterface.php +++ b/src/Common/Endpoint/InputInterface.php @@ -34,7 +34,7 @@ public function hasParameter(string $key): bool; * * @return mixed */ - public function getParameter(string $key); + public function getParameter(string $key): mixed; /** * Retrieves all parameters. @@ -51,7 +51,7 @@ public function getParameters(): array; * * @return void */ - public function setParameter(string $key, $value): void; + public function setParameter(string $key, mixed $value): void; /** * Retrieves a list of keys of available parameters. diff --git a/src/Common/Endpoint/OutputInterface.php b/src/Common/Endpoint/OutputInterface.php index 22e481b..5570806 100644 --- a/src/Common/Endpoint/OutputInterface.php +++ b/src/Common/Endpoint/OutputInterface.php @@ -14,7 +14,7 @@ interface OutputInterface * * @return mixed */ - public function getOutput(); + public function getOutput(): mixed; /** * Sets the value of the output. @@ -23,7 +23,7 @@ public function getOutput(); * * @return void */ - public function setOutput($output): void; + public function setOutput(mixed $output): void; /** * Sets the serving protocol. diff --git a/src/Component/Endpoint/Input.php b/src/Component/Endpoint/Input.php index d965af9..00b20ae 100644 --- a/src/Component/Endpoint/Input.php +++ b/src/Component/Endpoint/Input.php @@ -17,14 +17,14 @@ class Input implements InputInterface * * @var RequestInterface */ - private $request; + private RequestInterface $request; /** * Contains the parameters for the input. * * @var array */ - private $parameters = []; + private array $parameters = []; /** * Constructor. @@ -65,7 +65,7 @@ public function hasParameter(string $key): bool * * @return mixed */ - public function getParameter(string $key) + public function getParameter(string $key): mixed { return $this->parameters[$key]; } @@ -88,7 +88,7 @@ public function getParameters(): array * * @return void */ - public function setParameter(string $key, $value): void + public function setParameter(string $key, mixed $value): void { $this->parameters[$key] = $value; } diff --git a/src/Component/Endpoint/Output.php b/src/Component/Endpoint/Output.php index 55c482f..aa9eedf 100644 --- a/src/Component/Endpoint/Output.php +++ b/src/Component/Endpoint/Output.php @@ -16,49 +16,49 @@ class Output implements OutputInterface * * @var string */ - private $protocol; + private string $protocol; /** * Contains the status code for the response. * * @var int */ - private $statusCode = 200; + private int $statusCode = 200; /** * Contains the headers for the response. * * @var string[] */ - private $headers = []; + private array $headers = []; /** * Contains the parameters. * * @var array */ - private $parameters = []; + private array $parameters = []; /** * Contains the chosen content type. * * @var string */ - private $contentType = ''; + private string $contentType = ''; /** * Contains the output of the response. * * @var mixed */ - private $output; + private mixed $output; /** * Contains the accepted content types. * * @var string[] */ - private $acceptedContentTypes; + private array $acceptedContentTypes; /** * Constructor. @@ -78,7 +78,7 @@ public function __construct(string ...$acceptedContentTypes) * * @return mixed */ - public function getOutput() + public function getOutput(): mixed { return $this->output; } @@ -90,7 +90,7 @@ public function getOutput() * * @return void */ - public function setOutput($output): void + public function setOutput(mixed $output): void { $this->output = $output; } @@ -237,7 +237,7 @@ public function hasParameter(string $key): bool * * @return mixed */ - public function getParameter(string $key) + public function getParameter(string $key): mixed { return $this->parameters[$key]; } @@ -250,7 +250,7 @@ public function getParameter(string $key) * * @return void */ - public function setParameter(string $key, $value): void + public function setParameter(string $key, mixed $value): void { $this->parameters[$key] = $value; } diff --git a/src/Component/Error/ConfigurableApiError.php b/src/Component/Error/ConfigurableApiError.php index ec1fa40..67775df 100644 --- a/src/Component/Error/ConfigurableApiError.php +++ b/src/Component/Error/ConfigurableApiError.php @@ -19,35 +19,35 @@ class ConfigurableApiError implements ErrorInterface * * @var int */ - private $errorStatusCode; + private int $errorStatusCode; /** * Contains the error code. * - * @var int + * @var int|null */ - private $errorCode; + private ?int $errorCode; /** * Contains the error message. * - * @var string + * @var string|null */ - private $errorMessage; + private ?string $errorMessage; /** * Contains the default content type. * * @var string */ - private $defaultContentType; + private string $defaultContentType; /** * Constructor. * * @param int $errorStatusCode - * @param int $errorCode - * @param string $errorMessage + * @param int|null $errorCode + * @param string|null $errorMessage * @param string $defaultContentType */ public function __construct( diff --git a/src/Component/Error/ConfigurablePlainError.php b/src/Component/Error/ConfigurablePlainError.php index b3d1c4a..778076c 100644 --- a/src/Component/Error/ConfigurablePlainError.php +++ b/src/Component/Error/ConfigurablePlainError.php @@ -19,29 +19,28 @@ class ConfigurablePlainError implements ErrorInterface * * @var int */ - private $errorStatusCode; + private int $errorStatusCode; /** * Contains the error code. * - * @var int + * @var int|null */ - private $errorCode; + private ?int $errorCode; /** * Contains the error message. * - * @var string + * @var string|null */ - private $errorMessage; + private ?string $errorMessage; /** * Constructor. * * @param int $errorStatusCode - * @param int $errorCode - * @param string $errorMessage - * @param string $defaultContentType + * @param int|null $errorCode + * @param string|null $errorMessage */ public function __construct( int $errorStatusCode, diff --git a/src/Component/Error/ErrorHandler.php b/src/Component/Error/ErrorHandler.php index 647fc38..9101ead 100644 --- a/src/Component/Error/ErrorHandler.php +++ b/src/Component/Error/ErrorHandler.php @@ -22,28 +22,28 @@ class ErrorHandler implements ErrorHandlerInterface * * @var InputInterface */ - private $input; + private InputInterface $input; /** * Contains a reference to the output. * * @var OutputInterface */ - private $output; + private OutputInterface $output; /** * Contains the output handler. * * @var OutputHandlerInterface */ - private $outputHandler; + private OutputHandlerInterface $outputHandler; /** * Contains the error registry. * * @var ErrorRegistryInterface */ - private $errorRegistry; + private ErrorRegistryInterface $errorRegistry; /** * Constructor. diff --git a/src/Component/Error/ErrorRegistry.php b/src/Component/Error/ErrorRegistry.php index 0773c04..42e6238 100644 --- a/src/Component/Error/ErrorRegistry.php +++ b/src/Component/Error/ErrorRegistry.php @@ -17,7 +17,7 @@ class ErrorRegistry implements ErrorRegistryInterface * * @var ErrorInterface[] */ - private $errors; + private array $errors; /** * Constructor. diff --git a/src/Component/Middleware/HostMatchingMiddleware.php b/src/Component/Middleware/HostMatchingMiddleware.php index dfdc856..93b7324 100644 --- a/src/Component/Middleware/HostMatchingMiddleware.php +++ b/src/Component/Middleware/HostMatchingMiddleware.php @@ -18,7 +18,7 @@ class HostMatchingMiddleware implements MiddlewareInterface * * @var string[] */ - private $hosts; + private array $hosts; /** * Constructor. diff --git a/src/Component/Middleware/MethodMatchingMiddleware.php b/src/Component/Middleware/MethodMatchingMiddleware.php index 1a26b15..e655302 100644 --- a/src/Component/Middleware/MethodMatchingMiddleware.php +++ b/src/Component/Middleware/MethodMatchingMiddleware.php @@ -18,7 +18,7 @@ class MethodMatchingMiddleware implements MiddlewareInterface * * @var string[] */ - private $methods; + private array $methods; /** * Constructor. diff --git a/src/Component/Middleware/MiddlewareAggregate.php b/src/Component/Middleware/MiddlewareAggregate.php index eb87dd0..990a7cf 100644 --- a/src/Component/Middleware/MiddlewareAggregate.php +++ b/src/Component/Middleware/MiddlewareAggregate.php @@ -18,14 +18,14 @@ class MiddlewareAggregate implements MiddlewareInterface * * @var MiddlewareInterface[] */ - private $middlewares; + private array $middlewares; /** * Contains the last error code. * * @var int */ - private $lastErrorCode = 500; + private int $lastErrorCode = 500; /** * Constructor. diff --git a/src/Component/Middleware/PathMatchingMiddleware.php b/src/Component/Middleware/PathMatchingMiddleware.php index cc28c38..672a32e 100644 --- a/src/Component/Middleware/PathMatchingMiddleware.php +++ b/src/Component/Middleware/PathMatchingMiddleware.php @@ -18,7 +18,7 @@ class PathMatchingMiddleware implements MiddlewareInterface * * @var string */ - private $route; + private string $route; /** * Constructor. diff --git a/src/Component/Middleware/PortMatchingMiddleware.php b/src/Component/Middleware/PortMatchingMiddleware.php index 6faf57f..1123b78 100644 --- a/src/Component/Middleware/PortMatchingMiddleware.php +++ b/src/Component/Middleware/PortMatchingMiddleware.php @@ -18,7 +18,7 @@ class PortMatchingMiddleware implements MiddlewareInterface * * @var int[] */ - private $ports; + private array $ports; /** * Constructor. diff --git a/src/Component/Output/CodecOutputConverter.php b/src/Component/Output/CodecOutputConverter.php index ce99e7b..64db40a 100644 --- a/src/Component/Output/CodecOutputConverter.php +++ b/src/Component/Output/CodecOutputConverter.php @@ -20,14 +20,14 @@ class CodecOutputConverter implements OutputConverterInterface * * @var TranslatorInterface */ - private $mimeToCodec; + private TranslatorInterface $mimeToCodec; /** * Contains the codec registry. * * @var CodecRegistryInterface */ - private $codecRegistry; + private CodecRegistryInterface $codecRegistry; /** * Constructor. diff --git a/src/Component/Output/OutputHandler.php b/src/Component/Output/OutputHandler.php index e038ff1..7252e8c 100644 --- a/src/Component/Output/OutputHandler.php +++ b/src/Component/Output/OutputHandler.php @@ -21,14 +21,14 @@ class OutputHandler implements OutputHandlerInterface * * @var OutputConverterInterface[] */ - private $outputConverters; + private array $outputConverters; /** * Contains the header handler. * * @var HeaderHandlerInterface */ - private $headerHandler; + private HeaderHandlerInterface $headerHandler; /** * Constructor. diff --git a/src/Component/Output/PlainOutputConverter.php b/src/Component/Output/PlainOutputConverter.php index 4514056..de61535 100644 --- a/src/Component/Output/PlainOutputConverter.php +++ b/src/Component/Output/PlainOutputConverter.php @@ -17,7 +17,7 @@ class PlainOutputConverter implements OutputConverterInterface * * @var string[] */ - private $contentTypes; + private array $contentTypes; /** * Constructor. diff --git a/src/Component/Router/BaseRouter.php b/src/Component/Router/BaseRouter.php index d434d21..85501c3 100644 --- a/src/Component/Router/BaseRouter.php +++ b/src/Component/Router/BaseRouter.php @@ -13,8 +13,8 @@ use Ulrack\Web\Common\Endpoint\OutputInterface; use Ulrack\Web\Common\Endpoint\EndpointInterface; use Ulrack\Web\Common\Error\ErrorHandlerInterface; -use Ulrack\Services\Common\ServiceFactoryInterface; use Ulrack\Web\Common\Output\OutputHandlerInterface; +use GrizzIt\Services\Common\Factory\ServiceFactoryInterface; class BaseRouter implements RouterInterface { @@ -23,35 +23,35 @@ class BaseRouter implements RouterInterface * * @var RouterInterface */ - private $router; + private RouterInterface $router; /** * Determines whether a router has been found. * * @var bool */ - private $found = false; + private bool $found = false; /** * Contains the output handler. * * @var OutputHandlerInterface */ - private $outputHandler; + private OutputHandlerInterface $outputHandler; /** * Contains the error handler. * * @var ErrorHandlerInterface */ - private $errorHandler; + private ErrorHandlerInterface $errorHandler; /** * Contains the service factory. * * @var ServiceFactoryInterface */ - private $serviceFactory; + private ServiceFactoryInterface $serviceFactory; /** * Constructor. diff --git a/src/Component/Router/MiddlewareRouter.php b/src/Component/Router/MiddlewareRouter.php index 4f2b68c..89159df 100644 --- a/src/Component/Router/MiddlewareRouter.php +++ b/src/Component/Router/MiddlewareRouter.php @@ -20,21 +20,21 @@ class MiddlewareRouter implements RouterInterface * * @var RouterInterface */ - private $router; + private RouterInterface $router; /** * Contains the middleware that takes care of the accepts method. * * @var MiddlewareInterface|null */ - private $middlewareAccept; + private ?MiddlewareInterface $middlewareAccept; /** * Contains the middleware that takes care of the invoke method. * * @var MiddlewareInterface|null */ - private $middlewareInvoke; + private ?MiddlewareInterface $middlewareInvoke; /** * Constructor. diff --git a/src/Component/Router/RouterAggregate.php b/src/Component/Router/RouterAggregate.php index 7f69c72..955e52a 100644 --- a/src/Component/Router/RouterAggregate.php +++ b/src/Component/Router/RouterAggregate.php @@ -19,14 +19,14 @@ class RouterAggregate implements RouterInterface * * @var RouterInterface[] */ - private $routers; + private array $routers; /** * Contains the last accepted router. * * @var RouterInterface|null */ - private $lastAccepted; + private ?RouterInterface $lastAccepted = null; /** * Constructor. diff --git a/src/Exception/HttpException.php b/src/Exception/HttpException.php index 09d2c93..b775ec5 100644 --- a/src/Exception/HttpException.php +++ b/src/Exception/HttpException.php @@ -17,7 +17,7 @@ class HttpException extends Exception * * @var int */ - private $errorCode; + private int $errorCode; /** * Constructor. diff --git a/src/Factory/InputFactory.php b/src/Factory/InputFactory.php index 5b216b9..2233e51 100644 --- a/src/Factory/InputFactory.php +++ b/src/Factory/InputFactory.php @@ -26,28 +26,28 @@ class InputFactory * * @var TranslatorInterface */ - private $mimeToCodec; + private TranslatorInterface $mimeToCodec; /** * Contains the codec registry. * * @var CodecRegistryInterface */ - private $codecRegistry; + private CodecRegistryInterface $codecRegistry; /** * Contains the URI factory. * * @var UriFactory */ - private $uriFactory; + private UriFactory $uriFactory; /** * Contains the identifier of the input stream. * * @var string */ - private $inputStream; + private string $inputStream; /** * Constructor. diff --git a/tests/Component/Router/BaseRouterTest.php b/tests/Component/Router/BaseRouterTest.php index 7c2cdad..864f8e8 100644 --- a/tests/Component/Router/BaseRouterTest.php +++ b/tests/Component/Router/BaseRouterTest.php @@ -9,14 +9,14 @@ use PHPUnit\Framework\TestCase; use Ulrack\Web\Component\Router\BaseRouter; -use Ulrack\Web\Exception\UnauthorizedException; use Ulrack\Web\Common\Router\RouterInterface; use Ulrack\Web\Common\Endpoint\InputInterface; use Ulrack\Web\Common\Endpoint\OutputInterface; +use Ulrack\Web\Exception\UnauthorizedException; use Ulrack\Web\Common\Endpoint\EndpointInterface; use Ulrack\Web\Common\Error\ErrorHandlerInterface; -use Ulrack\Services\Common\ServiceFactoryInterface; use Ulrack\Web\Common\Output\OutputHandlerInterface; +use GrizzIt\Services\Common\Factory\ServiceFactoryInterface; /** * @coversDefaultClass \Ulrack\Web\Component\Router\BaseRouter diff --git a/tests/Factory/OutputFactoryTest.php b/tests/Factory/OutputFactoryTest.php index 3022d7a..5a136a9 100644 --- a/tests/Factory/OutputFactoryTest.php +++ b/tests/Factory/OutputFactoryTest.php @@ -47,4 +47,29 @@ public function testCreate(): void $this->assertInstanceOf(OutputInterface::class, $subject->create($input)); } + + /** + * @covers ::create + * @covers ::parseAcceptHeader + * + * @return void + */ + public function testCreateNoAccept(): void + { + $subject = new OutputFactory(); + + $input = $this->createMock(InputInterface::class); + $request = $this->createMock(RequestInterface::class); + + $input->expects(static::once()) + ->method('getRequest') + ->willReturn($request); + + $request->expects(static::once()) + ->method('hasHeader') + ->with('Accept') + ->willReturn(false); + + $this->assertInstanceOf(OutputInterface::class, $subject->create($input)); + } }