From 472836b23df80630eae1869822c168d6ed2df2cd Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Thu, 28 Sep 2023 10:19:01 +0300 Subject: [PATCH] Registration of dumper middleware, add http module (#135) --- composer.json | 2 +- .../Common/resources/functions.php | 0 installer/Application/ComposerPackages.php | 9 +++--- installer/Application/Web/Application.php | 4 ++- .../Application/Web/Generator/Bootloaders.php | 18 ++++-------- .../Module/Dumper/Generator/Middlewares.php | 28 +++++++++++++++++++ installer/Module/Dumper/Package.php | 2 ++ .../Module/Http/Generator/Bootloaders.php | 25 +++++++++++++++++ installer/Module/Http/Package.php | 22 +++++++++++++++ .../resources/config/queue.php | 2 +- .../PlainPHP/resources/views/home.php | 2 +- .../Stempler/resources/views/home.dark.php | 2 +- .../Twig/resources/views/home.twig | 2 +- .../Tests/Feature/Application/WebTest.php | 4 +++ installer/Tests/Fixtures/composer.json | 2 +- installer/Tests/Module/Dumper.php | 15 ++++++++++ installer/Tests/Module/Http.php | 24 ++++++++++++++++ .../Internal/Installer/ComposerFileTest.php | 2 +- installer/composer.json | 2 +- 19 files changed, 142 insertions(+), 25 deletions(-) rename functions.php => installer/Application/Common/resources/functions.php (100%) create mode 100644 installer/Module/Dumper/Generator/Middlewares.php create mode 100644 installer/Module/Http/Generator/Bootloaders.php create mode 100644 installer/Module/Http/Package.php create mode 100644 installer/Tests/Module/Http.php diff --git a/composer.json b/composer.json index 15bc36c..d686285 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ }, "require": { "php": ">=8.1", - "spiral/framework": "^3.7", + "spiral/framework": "^3.8", "spiral/roadrunner-cli": "^2.5" }, "require-dev": { diff --git a/functions.php b/installer/Application/Common/resources/functions.php similarity index 100% rename from functions.php rename to installer/Application/Common/resources/functions.php diff --git a/installer/Application/ComposerPackages.php b/installer/Application/ComposerPackages.php index e9d8d05..ded4684 100644 --- a/installer/Application/ComposerPackages.php +++ b/installer/Application/ComposerPackages.php @@ -11,7 +11,7 @@ enum ComposerPackages: string case ExtGRPC = 'ext-grpc:*'; case ExtSockets = 'ext-sockets:*'; case GRPC = 'grpc/grpc:^1.42'; - case Dumper = 'dev:spiral/dumper:^3.2'; + case Dumper = 'dev:spiral/dumper:^3.2.1'; case RoadRunnerBridge = 'spiral/roadrunner-bridge:^3.0'; case RoadRunnerCli = 'spiral/roadrunner-cli:^2.5'; case NyholmBridge = 'spiral/nyholm-bridge:^1.3'; @@ -27,12 +27,13 @@ enum ComposerPackages: string case Scheduler = 'spiral-packages/scheduler:^2.1'; case TemporalBridge = 'spiral/temporal-bridge:^2.2'; case SentryBridge = 'spiral/sentry-bridge:^2.1'; - case StemplerBridge = 'spiral/stempler-bridge:^3.7'; + case StemplerBridge = 'spiral/stempler-bridge:^3.8'; case TwigBridge = 'spiral/twig-bridge:^2.0.1'; case LeagueEvent = 'spiral-packages/league-event:^1.0.1'; case SymfonySerializer = 'spiral-packages/symfony-serializer:^2.0.1'; case LaravelSerializableClosure = 'spiral-packages/serializable-closure:^1.0'; case DataGridBridge = 'spiral/data-grid-bridge:^3.0.1'; - case Translator = 'spiral/translator:^3.7'; - case Views = 'spiral/views:^3.7'; + case Translator = 'spiral/translator:^3.8'; + case Views = 'spiral/views:^3.8'; + case Http = 'spiral/http:^3.8'; } diff --git a/installer/Application/Web/Application.php b/installer/Application/Web/Application.php index 5eb0ad7..eeb19a9 100644 --- a/installer/Application/Web/Application.php +++ b/installer/Application/Web/Application.php @@ -5,7 +5,6 @@ namespace Installer\Application\Web; use Composer\Package\PackageInterface; -use Installer\Application\Package; use Installer\Application\Web\Generator\Bootloaders; use Installer\Application\Web\Generator\Env; use Installer\Application\Web\Generator\Interceptors; @@ -13,6 +12,7 @@ use Installer\Application\Web\Generator\ViewRenderer; use Installer\Internal\Application\AbstractApplication; use Installer\Internal\Generator\GeneratorInterface; +use Installer\Internal\Package; use Installer\Internal\Question\QuestionInterface; use Installer\Internal\Readme\Block\FileBlock; use Installer\Internal\Readme\Section; @@ -21,6 +21,7 @@ use Installer\Module\ErrorHandler\Yii\Package as YiiErrorHandlerPackage; use Installer\Module\Exception\Generator\Skeleton as ExceptionSkeleton; use Installer\Module\ExtMbString\Package as ExtMbStringPackage; +use Installer\Module\Http\Package as HttpPackage; use Installer\Module\Psr7Implementation\Nyholm\Package as NyholmPsr7Implementation; use Installer\Module\RoadRunnerBridge\Common\Package as RoadRunnerBridgePackage; @@ -40,6 +41,7 @@ final class Application extends AbstractApplication public function __construct( string $name = 'Web', array $packages = [ + new HttpPackage(), new ExtMbStringPackage(), new NyholmPsr7Implementation(), new RoadRunnerBridgePackage(), diff --git a/installer/Application/Web/Generator/Bootloaders.php b/installer/Application/Web/Generator/Bootloaders.php index 8b9b09d..88a7554 100644 --- a/installer/Application/Web/Generator/Bootloaders.php +++ b/installer/Application/Web/Generator/Bootloaders.php @@ -25,18 +25,12 @@ public function process(Context $context): void priority: 5 ); - $context->kernel->load->addGroup( - bootloaders: [ - Http\RouterBootloader::class, - Http\JsonPayloadsBootloader::class, - Http\CookiesBootloader::class, - Http\SessionBootloader::class, - Http\CsrfBootloader::class, - Http\PaginationBootloader::class, - ], - comment: 'HTTP extensions', - priority: 6 - ); + $context->kernel->load->append(Http\RouterBootloader::class, Http\HttpBootloader::class); + $context->kernel->load->append(Http\JsonPayloadsBootloader::class, Http\RouterBootloader::class); + $context->kernel->load->append(Http\CookiesBootloader::class, Http\JsonPayloadsBootloader::class); + $context->kernel->load->append(Http\SessionBootloader::class, Http\CookiesBootloader::class); + $context->kernel->load->append(Http\CsrfBootloader::class, Http\SessionBootloader::class); + $context->kernel->load->append(Http\PaginationBootloader::class, Http\CsrfBootloader::class); $context->kernel->load->addGroup( bootloaders: [ diff --git a/installer/Module/Dumper/Generator/Middlewares.php b/installer/Module/Dumper/Generator/Middlewares.php new file mode 100644 index 0000000..9ab48fc --- /dev/null +++ b/installer/Module/Dumper/Generator/Middlewares.php @@ -0,0 +1,28 @@ +application->isPackageInstalled(new Package())) { + return; + } + + $context->routesBootloader?->addUse(DumperMiddleware::class); + + $context->routesBootloader?->addGlobalMiddleware( + middleware: [DumperMiddleware::class], + afterMiddleware: ErrorHandlerMiddleware::class + ); + } +} diff --git a/installer/Module/Dumper/Package.php b/installer/Module/Dumper/Package.php index 5bdfed1..769be8d 100644 --- a/installer/Module/Dumper/Package.php +++ b/installer/Module/Dumper/Package.php @@ -7,12 +7,14 @@ use Installer\Application\ComposerPackages; use Installer\Internal\Package as BasePackage; use Installer\Module\Dumper\Generator\Bootloaders; +use Installer\Module\Dumper\Generator\Middlewares; final class Package extends BasePackage { public function __construct( array $generators = [ new Bootloaders(), + new Middlewares(), ], ) { parent::__construct(ComposerPackages::Dumper, generators: $generators); diff --git a/installer/Module/Http/Generator/Bootloaders.php b/installer/Module/Http/Generator/Bootloaders.php new file mode 100644 index 0000000..8e5b12d --- /dev/null +++ b/installer/Module/Http/Generator/Bootloaders.php @@ -0,0 +1,25 @@ +kernel->addUse(HttpBootloader::class); + + $context->kernel->load->addGroup( + bootloaders: [ + HttpBootloader::class, + ], + comment: 'HTTP extensions', + priority: 6 + ); + } +} diff --git a/installer/Module/Http/Package.php b/installer/Module/Http/Package.php new file mode 100644 index 0000000..99ed773 --- /dev/null +++ b/installer/Module/Http/Package.php @@ -0,0 +1,22 @@ + [ 'sync' => [ diff --git a/installer/Module/TemplateEngines/PlainPHP/resources/views/home.php b/installer/Module/TemplateEngines/PlainPHP/resources/views/home.php index c632366..a4f4cc5 100644 --- a/installer/Module/TemplateEngines/PlainPHP/resources/views/home.php +++ b/installer/Module/TemplateEngines/PlainPHP/resources/views/home.php @@ -279,7 +279,7 @@ -
Spiral Framework v3.7 PHP
+
Spiral Framework v3.8 PHP
-
Spiral Framework v3.7 PHP @php echo PHP_VERSION; @endphp
+
Spiral Framework v3.8 PHP @php echo PHP_VERSION; @endphp
-
Spiral Framework v3.7 PHP {{ constant('PHP_VERSION') }}
+
Spiral Framework v3.8 PHP {{ constant('PHP_VERSION') }}