diff --git a/.editorconfig b/.editorconfig index 837f0ef..9d16cf5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,7 +4,7 @@ end_of_line = lf indent_size = 4 indent_style = space insert_final_newline = false -max_line_length = 150 +max_line_length = 120 tab_width = 4 ij_continuation_indent_size = 8 ij_formatter_off_tag = @formatter:off diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6b62727..5aa264c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,7 +27,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ "8.1", "8.2" ] + php-version: [ "8.2" ] operating-system: [ "ubuntu-latest" ] steps: @@ -77,7 +77,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ "8.1", "8.2" ] + php-version: [ "8.2" ] operating-system: [ "ubuntu-latest" ] steps: @@ -128,7 +128,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ "8.1", "8.2" ] + php-version: [ "8.2" ] operating-system: [ "ubuntu-latest" ] steps: @@ -318,7 +318,7 @@ jobs: strategy: matrix: - php-version: [ "8.1", "8.2" ] + php-version: [ "8.2" ] operating-system: [ "ubuntu-latest" ] fail-fast: false diff --git a/composer.json b/composer.json index a5d853b..c211dee 100644 --- a/composer.json +++ b/composer.json @@ -36,9 +36,9 @@ "source": "https://github.com/FastyBird/web-server-plugin" }, "require": { - "php": ">=8.1.0", + "php": ">=8.2.0", "cweagans/composer-patches": "^1.7", - "fastybird/bootstrap-library": "dev-main", + "fastybird/application-library": "dev-main", "fastybird/metadata-library": "dev-main", "fig/http-message-util": "^1.1", "ipub/slim-router": "^0.2", @@ -108,12 +108,6 @@ } } }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/mathsolver/mathsolver.git" - } - ], "minimum-stability": "dev", "prefer-stable": true } diff --git a/docs/index.md b/docs/index.md index e0c9589..50511dd 100644 --- a/docs/index.md +++ b/docs/index.md @@ -230,7 +230,7 @@ You can copy & paste it to your project, for example to `/www/index.ph require __DIR__ . '/../vendor/autoload.php'; -exit(Your\CoolApp\Bootstrap::boot() +exit(Your\CoolApp\Application::boot() ->createContainer() ->getByType(FastyBird\Plugin\WebServer\Application\Application::class) ->run()); diff --git a/src/Commands/HttpServer.php b/src/Commands/HttpServer.php index 3909c34..1796b9f 100644 --- a/src/Commands/HttpServer.php +++ b/src/Commands/HttpServer.php @@ -15,7 +15,7 @@ namespace FastyBird\Plugin\WebServer\Commands; -use FastyBird\Library\Bootstrap\Helpers as BootstrapHelpers; +use FastyBird\Library\Application\Helpers as ApplicationHelpers; use FastyBird\Library\Metadata\Types as MetadataTypes; use FastyBird\Plugin\WebServer\Events; use FastyBird\Plugin\WebServer\Exceptions; @@ -79,9 +79,9 @@ protected function execute( ): int { $this->logger->info( - 'Launching HTTP Server', + 'Starting HTTP Server', [ - 'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER, + 'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value, 'type' => 'server-command', ], ); @@ -117,28 +117,14 @@ protected function execute( $this->eventLoop->run(); - } catch (Exceptions\Terminate $ex) { - // Log error action reason - $this->logger->error( - 'HTTP server was forced to close', - [ - 'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER, - 'type' => 'server-command', - 'exception' => BootstrapHelpers\Logger::buildException($ex), - 'cmd' => $this->getName(), - ], - ); - - $this->eventLoop->stop(); - } catch (Throwable $ex) { // Log error action reason $this->logger->error( 'An unhandled error occurred. Stopping HTTP server', [ - 'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER, + 'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value, 'type' => 'server-command', - 'exception' => BootstrapHelpers\Logger::buildException($ex), + 'exception' => ApplicationHelpers\Logger::buildException($ex), 'cmd' => $this->getName(), ], ); diff --git a/src/DI/WebServerExtension.php b/src/DI/WebServerExtension.php index 77b055f..3ee5289 100644 --- a/src/DI/WebServerExtension.php +++ b/src/DI/WebServerExtension.php @@ -15,7 +15,7 @@ namespace FastyBird\Plugin\WebServer\DI; -use FastyBird\Library\Bootstrap\Boot as BootstrapBoot; +use FastyBird\Library\Application\Boot as ApplicationBoot; use FastyBird\Plugin\WebServer\Application; use FastyBird\Plugin\WebServer\Commands; use FastyBird\Plugin\WebServer\Http; @@ -43,12 +43,12 @@ class WebServerExtension extends DI\CompilerExtension public const NAME = 'fbWebServerPlugin'; public static function register( - BootstrapBoot\Configurator $config, + ApplicationBoot\Configurator $config, string $extensionName = self::NAME, ): void { $config->onCompile[] = static function ( - BootstrapBoot\Configurator $config, + ApplicationBoot\Configurator $config, DI\Compiler $compiler, ) use ( $extensionName, @@ -61,7 +61,7 @@ public function getConfigSchema(): Schema\Schema { return Schema\Expect::structure([ 'static' => Schema\Expect::structure([ - 'publicRoot' => Schema\Expect::string(null)->nullable(), + 'publicRoot' => Schema\Expect::string()->nullable(), 'enabled' => Schema\Expect::bool(false), ]), 'server' => Schema\Expect::structure([ diff --git a/src/Exceptions/Terminate.php b/src/Exceptions/Terminate.php deleted file mode 100644 index f878b95..0000000 --- a/src/Exceptions/Terminate.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @package FastyBird:WebServerPlugin! - * @subpackage Exceptions - * @since 1.0.0 - * - * @date 05.12.20 - */ - -namespace FastyBird\Plugin\WebServer\Exceptions; - -use Exception; -use Throwable; - -class Terminate extends Exception implements Throwable -{ - -} diff --git a/src/Http/Entity.php b/src/Http/Entity.php index ea91754..881e538 100644 --- a/src/Http/Entity.php +++ b/src/Http/Entity.php @@ -1,7 +1,7 @@ */ -final class Cors +final readonly class Cors { /** @@ -37,11 +37,11 @@ final class Cors * @param array $allowHeaders */ public function __construct( - private readonly bool $enabled, - private readonly string $allowOrigin, - private readonly array $allowMethods, - private readonly bool $allowCredentials, - private readonly array $allowHeaders, + private bool $enabled, + private string $allowOrigin, + private array $allowMethods, + private bool $allowCredentials, + private array $allowHeaders, ) { } diff --git a/src/Middleware/Router.php b/src/Middleware/Router.php index 8d5a0f3..a59cdf5 100644 --- a/src/Middleware/Router.php +++ b/src/Middleware/Router.php @@ -29,12 +29,12 @@ * * @author Adam Kadlec */ -final class Router +final readonly class Router { public function __construct( - private readonly Routing\IRouter $router, - private readonly EventDispatcher\EventDispatcherInterface|null $dispatcher = null, + private Routing\IRouter $router, + private EventDispatcher\EventDispatcherInterface|null $dispatcher = null, ) { } diff --git a/src/Server/Factory.php b/src/Server/Factory.php index 108e680..e5b9dfa 100644 --- a/src/Server/Factory.php +++ b/src/Server/Factory.php @@ -15,7 +15,7 @@ namespace FastyBird\Plugin\WebServer\Server; -use FastyBird\Library\Bootstrap\Helpers as BootstrapHelpers; +use FastyBird\Library\Application\Helpers as ApplicationHelpers; use FastyBird\Library\Metadata\Types as MetadataTypes; use FastyBird\Plugin\WebServer\Middleware; use Psr\Log; @@ -34,15 +34,15 @@ * * @author Adam Kadlec */ -final class Factory +final readonly class Factory { public function __construct( - private readonly Middleware\Cors $corsMiddleware, - private readonly Middleware\StaticFiles $staticFilesMiddleware, - private readonly Middleware\Router $routerMiddleware, - private readonly EventLoop\LoopInterface $eventLoop, - private readonly Log\LoggerInterface $logger = new Log\NullLogger(), + private Middleware\Cors $corsMiddleware, + private Middleware\StaticFiles $staticFilesMiddleware, + private Middleware\Router $routerMiddleware, + private EventLoop\LoopInterface $eventLoop, + private Log\LoggerInterface $logger = new Log\NullLogger(), ) { } @@ -61,9 +61,9 @@ public function create(Socket\ServerInterface $server): void $this->logger->error( 'An error occurred during handling request. Stopping HTTP server', [ - 'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER, + 'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value, 'type' => 'factory', - 'exception' => BootstrapHelpers\Logger::buildException($ex), + 'exception' => ApplicationHelpers\Logger::buildException($ex), ], ); @@ -77,7 +77,7 @@ public function create(Socket\ServerInterface $server): void $this->logger->info( sprintf('Listening on "%s"', str_replace('tls:', 'https:', $server->getAddress())), [ - 'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER, + 'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value, 'type' => 'factory', ], ); @@ -86,7 +86,7 @@ public function create(Socket\ServerInterface $server): void $this->logger->info( sprintf('Listening on "%s"', str_replace('tcp:', 'http:', $server->getAddress())), [ - 'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER, + 'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value, 'type' => 'factory', ], ); diff --git a/src/Subscribers/Server.php b/src/Subscribers/Server.php index c0eb65c..cf86169 100644 --- a/src/Subscribers/Server.php +++ b/src/Subscribers/Server.php @@ -16,8 +16,8 @@ namespace FastyBird\Plugin\WebServer\Subscribers; use Doctrine\DBAL; -use FastyBird\Library\Bootstrap\Exceptions as BootstrapExceptions; -use FastyBird\Library\Bootstrap\Helpers as BootstrapHelpers; +use FastyBird\Library\Application\Exceptions as ApplicationExceptions; +use FastyBird\Library\Application\Helpers as ApplicationHelpers; use FastyBird\Plugin\WebServer\Events; use FastyBird\Plugin\WebServer\Exceptions; use Symfony\Component\EventDispatcher; @@ -30,10 +30,10 @@ * * @author Adam Kadlec */ -class Server implements EventDispatcher\EventSubscriberInterface +readonly class Server implements EventDispatcher\EventSubscriberInterface { - public function __construct(private readonly BootstrapHelpers\Database $database) + public function __construct(private ApplicationHelpers\Database $database) { } @@ -47,7 +47,7 @@ public static function getSubscribedEvents(): array } /** - * @throws BootstrapExceptions\InvalidState + * @throws ApplicationExceptions\InvalidState * @throws DBAL\Exception * @throws Exceptions\InvalidState */ @@ -66,7 +66,7 @@ public function check(): void } /** - * @throws BootstrapExceptions\InvalidState + * @throws ApplicationExceptions\InvalidState * @throws DBAL\Exception */ public function request(): void @@ -78,7 +78,7 @@ public function request(): void } /** - * @throws BootstrapExceptions\InvalidState + * @throws ApplicationExceptions\InvalidState */ public function response(): void { diff --git a/tests/cases/unit/BaseTestCase.php b/tests/cases/unit/BaseTestCase.php index 274baa2..da720db 100644 --- a/tests/cases/unit/BaseTestCase.php +++ b/tests/cases/unit/BaseTestCase.php @@ -3,8 +3,8 @@ namespace FastyBird\Plugin\WebServer\Tests\Cases\Unit; use Error; -use FastyBird\Library\Bootstrap\Boot as BootstrapBoot; -use FastyBird\Library\Bootstrap\Exceptions as BootstrapExceptions; +use FastyBird\Library\Application\Boot as ApplicationBoot; +use FastyBird\Library\Application\Exceptions as ApplicationExceptions; use FastyBird\Plugin\WebServer; use Nette; use Nette\DI; @@ -14,7 +14,6 @@ use function file_exists; use function getmypid; use function md5; -use function strval; use function time; abstract class BaseTestCase extends TestCase @@ -23,7 +22,7 @@ abstract class BaseTestCase extends TestCase protected DI\Container $container; /** - * @throws BootstrapExceptions\InvalidArgument + * @throws ApplicationExceptions\InvalidArgument * @throws Error */ protected function setUp(): void @@ -34,7 +33,7 @@ protected function setUp(): void } /** - * @throws BootstrapExceptions\InvalidArgument + * @throws ApplicationExceptions\InvalidArgument * @throws Error */ protected function createContainer(string|null $additionalConfig = null): Nette\DI\Container @@ -42,12 +41,12 @@ protected function createContainer(string|null $additionalConfig = null): Nette\ $rootDir = __DIR__ . '/../..'; $vendorDir = defined('FB_VENDOR_DIR') ? constant('FB_VENDOR_DIR') : $rootDir . '/../vendor'; - $config = BootstrapBoot\Bootstrap::boot(); + $config = ApplicationBoot\Bootstrap::boot(); $config->setForceReloadContainer(); $config->setTempDirectory(FB_TEMP_DIR); $config->addStaticParameters( - ['container' => ['class' => 'SystemContainer_' . strval(getmypid()) . md5((string) time())]], + ['container' => ['class' => 'SystemContainer_' . getmypid() . md5((string) time())]], ); $config->addStaticParameters(['appDir' => $rootDir, 'wwwDir' => $rootDir, 'vendorDir' => $vendorDir]); diff --git a/tests/cases/unit/Commands/HttpServerCommandTest.php b/tests/cases/unit/Commands/HttpServerCommandTest.php index 554bb40..1778535 100644 --- a/tests/cases/unit/Commands/HttpServerCommandTest.php +++ b/tests/cases/unit/Commands/HttpServerCommandTest.php @@ -38,7 +38,7 @@ public function testExecute(): void self::callback(static function (...$args): bool { $valid = [ [ - 'Launching HTTP Server', + 'Starting HTTP Server', ], [ 'Listening on "http://127.0.0.1:8001"', @@ -51,13 +51,13 @@ public function testExecute(): void $valid = [ [ [ - 'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER, + 'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value, 'type' => 'server-command', ], ], [ [ - 'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER, + 'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value, 'type' => 'factory', ], ], diff --git a/tests/cases/unit/DI/WebServerExtensionTest.php b/tests/cases/unit/DI/WebServerExtensionTest.php index d19887d..e371fc2 100644 --- a/tests/cases/unit/DI/WebServerExtensionTest.php +++ b/tests/cases/unit/DI/WebServerExtensionTest.php @@ -8,11 +8,11 @@ use FastyBird\Plugin\WebServer\Middleware; use FastyBird\Plugin\WebServer\Server; use FastyBird\Plugin\WebServer\Subscribers; -use FastyBird\Plugin\WebServer\Tests\Cases\Unit\BaseTestCase; +use FastyBird\Plugin\WebServer\Tests; use Nette; use React\EventLoop; -final class WebServerExtensionTest extends BaseTestCase +final class WebServerExtensionTest extends Tests\Cases\Unit\BaseTestCase { /** diff --git a/tools/phpcs.xml b/tools/phpcs.xml index b07411b..1ce9154 100644 --- a/tools/phpcs.xml +++ b/tools/phpcs.xml @@ -6,7 +6,7 @@ - + diff --git a/tools/phpstan.base.neon b/tools/phpstan.base.neon index 55d4cfb..797ec8c 100644 --- a/tools/phpstan.base.neon +++ b/tools/phpstan.base.neon @@ -1,5 +1,4 @@ parameters: - phpVersion: 80100 tmpDir: ../var/tools/PHPStan exceptions: