Skip to content

Commit 37252bb

Browse files
authored
Merge pull request #3 from Micro-PHP/1.6.1
v1.6.1 implements list of allowed SAPI modes
2 parents 5fa9ec6 + 1b6c512 commit 37252bb

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/Listener/ApplicationStartedListener.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
*/
2626
class ApplicationStartedListener implements EventListenerInterface
2727
{
28+
public const ALLOWED_MODES = [
29+
'apache2handler',
30+
'apache',
31+
'cgi-fcgi',
32+
'fpm-fcgi',
33+
'litespeed',
34+
'cli-server',
35+
];
36+
2837
public function __construct(
2938
private readonly HttpFacadeInterface $httpFacade
3039
) {
@@ -38,12 +47,11 @@ public function __construct(
3847
public function on(EventInterface $event): void
3948
{
4049
$sysenv = $event->systemEnvironment();
41-
if ('cli' === $sysenv) {
50+
if (!\in_array($sysenv, self::ALLOWED_MODES)) {
4251
return;
4352
}
4453

4554
$request = Request::createFromGlobals();
46-
4755
$this->httpFacade->execute($request);
4856
}
4957

tests/Unit/Listener/ApplicationStartedListenerTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ protected function setUp(): void
3131
$this->applicationStartedListener = new ApplicationStartedListener($this->httpFacade);
3232
}
3333

34-
protected function createEvent(bool $isHttp)
34+
protected function createEvent(string $env)
3535
{
3636
$evt = $this->createMock(ApplicationReadyEventInterface::class);
37-
$evt->method('systemEnvironment')->willReturn($isHttp ? 'http' : 'cli');
37+
$evt->method('systemEnvironment')->willReturn($env);
3838

3939
return $evt;
4040
}
4141

4242
/**
4343
* @dataProvider dataProvider
4444
*/
45-
public function testOn(bool $isHttp): void
45+
public function testOn(string $extension, bool $isHttp): void
4646
{
47-
$event = $this->createEvent($isHttp);
47+
$event = $this->createEvent($extension);
4848

4949
if (!$isHttp) {
5050
$this->httpFacade
@@ -64,17 +64,21 @@ public function testOn(bool $isHttp): void
6464

6565
public function dataProvider(): array
6666
{
67-
return [
68-
[true],
69-
[false],
70-
];
67+
$allowed = ApplicationStartedListener::ALLOWED_MODES;
68+
$data = [];
69+
70+
foreach ($allowed as $val) {
71+
$data[] = [$val, true];
72+
}
73+
74+
return $data;
7175
}
7276

7377
public function testSupports()
7478
{
7579
$httpFacade = $this->createMock(HttpFacadeInterface::class);
7680
$listener = new ApplicationStartedListener($httpFacade);
7781

78-
$this->assertTrue($listener->supports($this->createEvent(true)));
82+
$this->assertTrue($listener->supports($this->createEvent(ApplicationStartedListener::ALLOWED_MODES[0])));
7983
}
8084
}

0 commit comments

Comments
 (0)