Skip to content

Commit 9ddb6f6

Browse files
committed
AutoExit configuration
1 parent 85a96d4 commit 9ddb6f6

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

src/Cli/AutoExit.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace WonderNetwork\SlimKernel\Cli;
5+
6+
use DI\Definition\Definition;
7+
use function DI\value;
8+
9+
final class AutoExit {
10+
private bool $value;
11+
12+
public static function yes(): Definition {
13+
return value(new self(true));
14+
}
15+
16+
public static function no(): Definition {
17+
return value(new self(false));
18+
}
19+
20+
private function __construct(bool $value) {
21+
$this->value = $value;
22+
}
23+
24+
public function value(): bool {
25+
return $this->value;
26+
}
27+
}

src/ServiceFactory/SymfonyConsoleServiceFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use DI\Definition\Helper\CreateDefinitionHelper;
77
use Symfony\Component\Console;
8+
use WonderNetwork\SlimKernel\Cli\AutoExit;
89
use WonderNetwork\SlimKernel\ServiceFactory;
910
use WonderNetwork\SlimKernel\ServicesBuilder;
1011
use function DI\autowire;
@@ -22,14 +23,15 @@ public function __construct(string $path = '/src/Cli/**/*Command.php', string $n
2223

2324
public function __invoke(ServicesBuilder $builder): iterable {
2425
yield from $commands = $builder->autowire()->glob($this->path);
26+
yield AutoExit::class => AutoExit::no();
2527

2628
yield Console\Application::class => collection($commands)
2729
->keys()
2830
->reduce(
2931
static fn(CreateDefinitionHelper $def, string $command) => $def->method('add', get($command)),
3032
autowire()
3133
->constructor($this->name)
32-
->method('setAutoExit', false),
34+
->method('setAutoExit', static fn (AutoExit $autoExit) => $autoExit->value()),
3335
);
3436
}
3537
}

tests/ServiceFactory/SymfonyConsoleServiceFactoryTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function test(): void {
2222
$commands = $actual
2323
->keys()
2424
->reverse()
25-
->drop(1)
25+
->drop(count(['Application', 'AutoExit']))
2626
->reverse()
2727
->toArray();
2828

tests/StartupHook/ErrorHandlingHookTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
use Acme\ErrorHandlingSpy;
77
use PHPUnit\Framework\TestCase;
8+
use Psr\Container\ContainerInterface;
89
use Slim\App;
910
use Slim\Psr7\Factory\ServerRequestFactory;
1011
use Throwable;
1112
use WonderNetwork\SlimKernel\KernelBuilder;
1213

1314
class ErrorHandlingHookTest extends TestCase {
14-
public function testCustomMiddlewaresTakePrecedence() {
15+
public function testCustomMiddlewaresTakePrecedence(): void {
1516
$container = KernelBuilder::start(__DIR__.'/../Resources/ErrorMiddleware')
1617
->glob('app/services/*.php')
1718
->onStartup(
@@ -20,7 +21,7 @@ public function testCustomMiddlewaresTakePrecedence() {
2021
)
2122
->build();
2223

23-
/** @var App $app */
24+
/** @var App<ContainerInterface> $app */
2425
$app = $container->get(App::class);
2526
/** @var ErrorHandlingSpy $spy */
2627
$spy = $container->get(ErrorHandlingSpy::class);

tests/StartupHook/RoutesStartupHookTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
namespace WonderNetwork\SlimKernel\StartupHook;
55

66
use PHPUnit\Framework\TestCase;
7+
use Psr\Container\ContainerInterface;
78
use Slim\App;
89
use Slim\Psr7\Factory\ServerRequestFactory;
910
use WonderNetwork\SlimKernel\KernelBuilder;
1011

1112
class RoutesStartupHookTest extends TestCase {
1213
public function test(): void {
13-
/** @var App $app */
14+
/** @var App<ContainerInterface> $app */
1415
$app = KernelBuilder::start(__DIR__.'/../Resources/App')
1516
->glob('app/services/*.php')
1617
->onStartup(

0 commit comments

Comments
 (0)