Skip to content

Commit

Permalink
Registration of dumper middleware, add http module
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Sep 5, 2023
1 parent 55ba0b4 commit 4b14329
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 25 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"require": {
"php": ">=8.1",
"spiral/framework": "^3.7",
"spiral/framework": "^3.8",
"spiral/roadrunner-cli": "^2.5"
},
"require-dev": {
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions installer/Application/ComposerPackages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
}
4 changes: 3 additions & 1 deletion installer/Application/Web/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
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;
use Installer\Application\Web\Generator\Skeleton;
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;
Expand All @@ -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;

Expand All @@ -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(),
Expand Down
18 changes: 6 additions & 12 deletions installer/Application/Web/Generator/Bootloaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
28 changes: 28 additions & 0 deletions installer/Module/Dumper/Generator/Middlewares.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Installer\Module\Dumper\Generator;

use Installer\Internal\Generator\Context;
use Installer\Internal\Generator\GeneratorInterface;
use Installer\Module\Http\Package;
use Spiral\Debug\Middleware\DumperMiddleware;
use Spiral\Http\Middleware\ErrorHandlerMiddleware;

final class Middlewares implements GeneratorInterface
{
public function process(Context $context): void
{
if (!$context->application->isPackageInstalled(new Package())) {
return;
}

$context->routesBootloader?->addUse(DumperMiddleware::class);

$context->routesBootloader?->addGlobalMiddleware(
middleware: [DumperMiddleware::class],
afterMiddleware: ErrorHandlerMiddleware::class
);
}
}
2 changes: 2 additions & 0 deletions installer/Module/Dumper/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions installer/Module/Http/Generator/Bootloaders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Installer\Module\Http\Generator;

use Installer\Internal\Generator\Context;
use Installer\Internal\Generator\GeneratorInterface;
use Spiral\Bootloader\Http\HttpBootloader;

final class Bootloaders implements GeneratorInterface
{
public function process(Context $context): void
{
$context->kernel->addUse(HttpBootloader::class);

$context->kernel->load->addGroup(
bootloaders: [
HttpBootloader::class,
],
comment: 'HTTP extensions',
priority: 6
);
}
}
22 changes: 22 additions & 0 deletions installer/Module/Http/Package.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Installer\Module\Http;

use Installer\Application\ComposerPackages;
use Installer\Internal\Package as BasePackage;
use Installer\Module\Http\Generator\Bootloaders;

final class Package extends BasePackage
{
public function __construct()
{
parent::__construct(
package: ComposerPackages::Http,
generators: [
new Bootloaders(),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Queue connections
* Drivers: "sync", "roadrunner"
*
* @link https://spiral.dev/docs/queue-configuration/#3.7/en
* @link https://spiral.dev/docs/queue-configuration
*/
'connections' => [
'sync' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
</a>
</nav>
</div>
<div class="version"><span>Spiral Framework v3.7</span> <span>PHP <?=PHP_VERSION?></span></div>
<div class="version"><span>Spiral Framework v3.8</span> <span>PHP <?=PHP_VERSION?></span></div>

<div class="logo">
<a href="https://spiral.dev/">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</a>
</nav>
</div>
<div class="version"><span>Spiral Framework v3.7</span> <span>PHP @php echo PHP_VERSION; @endphp</span></div>
<div class="version"><span>Spiral Framework v3.8</span> <span>PHP @php echo PHP_VERSION; @endphp</span></div>
<div class="logo">
<a href="https://spiral.dev/">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</a>
</nav>
</div>
<div class="version"><span>Spiral Framework v3.7</span> <span>PHP {{ constant('PHP_VERSION') }}</span></div>
<div class="version"><span>Spiral Framework v3.8</span> <span>PHP {{ constant('PHP_VERSION') }}</span></div>

<div class="logo">
<a href="https://spiral.dev/">
Expand Down
4 changes: 4 additions & 0 deletions installer/Tests/Feature/Application/WebTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function testDefaultInstall(): void
->addModule(new TestModule\TemplateEngines\Stempler())
->addModule(new TestModule\Translator())
->addModule(new TestModule\Validators\Spiral())
->addModule(new TestModule\Http())
->run();

$result->storeLog();
Expand Down Expand Up @@ -117,6 +118,7 @@ public function testStemplerTemplateEngine(): void
->addModule(new TestModule\ExtMbString())
->addModule(new TestModule\Exception())
->addModule(new TestModule\TemplateEngines\Stempler())
->addModule(new TestModule\Http())
->run();

$result->storeLog();
Expand All @@ -137,6 +139,7 @@ public function testTwigTemplateEngine(): void
->addModule(new TestModule\ExtMbString())
->addModule(new TestModule\Exception())
->addModule(new TestModule\TemplateEngines\Twig())
->addModule(new TestModule\Http())
->run();

$result->storeLog();
Expand All @@ -157,6 +160,7 @@ public function testPlainPHPTemplateEngine(): void
->addModule(new TestModule\ExtMbString())
->addModule(new TestModule\Exception())
->addModule(new TestModule\TemplateEngines\PlainPHP())
->addModule(new TestModule\Http())
->run();

$result->storeLog();
Expand Down
2 changes: 1 addition & 1 deletion installer/Tests/Fixtures/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"require": {
"php": ">=8.1",
"spiral/framework": "^3.7",
"spiral/framework": "^3.8",
"spiral/roadrunner-cli": "^2.5"
},
"require-dev": {
Expand Down
15 changes: 15 additions & 0 deletions installer/Tests/Module/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Installer\Internal\Application\ApplicationInterface;
use Installer\Module\Dumper\Package;
use Installer\Module\Http\Package as HttpPackage;
use Spiral\Debug\Bootloader\DumperBootloader;
use Spiral\Debug\Middleware\DumperMiddleware;

final class Dumper extends AbstractModule
{
Expand All @@ -21,4 +23,17 @@ public function getBootloaders(ApplicationInterface $application): array
DumperBootloader::class,
];
}

public function getMiddleware(ApplicationInterface $application): array
{
if (!$application->isPackageInstalled(new HttpPackage())) {
return [];
}

return [
'global' => [
DumperMiddleware::class
]
];
}
}
24 changes: 24 additions & 0 deletions installer/Tests/Module/Http.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Tests\Module;

use Installer\Internal\Application\ApplicationInterface;
use Installer\Module\Http\Package;
use Spiral\Bootloader\Http\HttpBootloader;

final class Http extends AbstractModule
{
public function __construct()
{
parent::__construct(new Package());
}

public function getBootloaders(ApplicationInterface $application): array
{
return [
HttpBootloader::class,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testAddsPackage(): void
->withArgs(static function (array $json): bool {
return
$json['require']['ext-grpc'] === '*'
&& $json['require-dev']['spiral/dumper'] === '^3.2'
&& $json['require-dev']['spiral/dumper'] === '^3.2.1'
&& \in_array('ext-grpc', $json['extra']['spiral']['packages'])
&& \in_array('spiral/dumper', $json['extra']['spiral']['packages']);
});
Expand Down
2 changes: 1 addition & 1 deletion installer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Spiral Application installer",
"require-dev": {
"nette/php-generator": "^4.0",
"spiral/framework": "^3.7",
"spiral/framework": "^3.8",
"spiral/nyholm-bridge": "^1.0",
"composer/composer": "^2.4",
"phpunit/phpunit": "^10.1",
Expand Down

0 comments on commit 4b14329

Please sign in to comment.