Skip to content

Commit 768c6fb

Browse files
authored
fix(router): use correct input stream (#1005)
1 parent cb9dfc7 commit 768c6fb

File tree

23 files changed

+219
-82
lines changed

23 files changed

+219
-82
lines changed

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
run: php ./tempest discovery:status
101101

102102
- name: Execute tests
103-
run: vendor/bin/phpunit --coverage-clover build/reports/clover.xml
103+
run: php -d"error_reporting = E_ALL & ~E_DEPRECATED" vendor/bin/phpunit --coverage-clover build/reports/clover.xml
104104

105105
# Only upload coverage once.
106106
- if: matrix.php == '8.3' && matrix.database == 'sqlite' && matrix.os == 'ubuntu-latest' && matrix.stability == 'prefer-stable'

phpunit.xml.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
<env name="BASE_URI" value="" />
3434
<env name="CACHE" value="null" />
3535
<env name="DISCOVERY_CACHE" value="true" />
36-
<env name="DEBUG_LOG_PATH" value="log/debug.test.log" />
37-
<env name="SERVER_LOG_PATH" value="log/server.test.log" />
3836
<ini name="memory_limit" value="256M" />
3937
</php>
4038
</phpunit>

src/Tempest/Console/src/ConsoleApplication.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ public static function boot(
4040
$consoleConfig = $container->get(ConsoleConfig::class);
4141
$consoleConfig->name = $name;
4242

43-
$logConfig = $container->get(LogConfig::class);
44-
45-
if ($logConfig->debugLogPath === null && $logConfig->channels === []) {
46-
$logConfig->debugLogPath = path($container->get(Kernel::class)->root, '/log/debug.log')->toString();
47-
$logConfig->channels[] = new AppendLogChannel(path($container->get(Kernel::class)->root, '/log/tempest.log')->toString());
48-
}
49-
5043
return $application;
5144
}
5245

src/Tempest/Log/src/LogConfig.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Tempest\Log;
66

7+
use Tempest\Log\Channels\AppendLogChannel;
8+
9+
use function Tempest\root_path;
10+
711
final class LogConfig
812
{
913
public function __construct(
@@ -13,5 +17,10 @@ public function __construct(
1317
public ?string $debugLogPath = null,
1418
public ?string $serverLogPath = null,
1519
) {
20+
$this->debugLogPath ??= root_path('/log/debug.log');
21+
22+
if ($this->channels === []) {
23+
$this->channels[] = new AppendLogChannel(root_path('/log/tempest.log'));
24+
}
1625
}
1726
}

src/Tempest/Router/src/GenericRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function dispatch(Request|PsrRequest $request): Response
7777
} catch (NotFoundException) {
7878
return new NotFound();
7979
} catch (ValidationException $validationException) {
80-
return new Invalid($request, $validationException->failingRules);
80+
return new Invalid($validationException->object, $validationException->failingRules);
8181
}
8282
} else {
8383
$request = $this->resolveRequest($request, $matchedRoute);

src/Tempest/Router/src/Input/PostInputStream.php renamed to src/Tempest/Router/src/Input/InputStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Tempest\Router\Input;
44

5-
interface PostInputStream
5+
interface InputStream
66
{
77
public function parse(): array;
88
}

src/Tempest/Router/src/Input/PostInputStreamInitializer.php renamed to src/Tempest/Router/src/Input/InputStreamInitializer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
use Tempest\Container\Initializer;
77
use Tempest\Container\Singleton;
88

9-
final class PostInputStreamInitializer implements Initializer
9+
final class InputStreamInitializer implements Initializer
1010
{
1111
#[Singleton]
12-
public function initialize(Container $container): PostInputStream
12+
public function initialize(Container $container): InputStream
1313
{
14-
return new StdinPostInputStream();
14+
return new StdinInputStream();
1515
}
1616
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Tempest\Router\Input;
4+
5+
use function Tempest\Support\str;
6+
7+
final class StdinInputStream implements InputStream
8+
{
9+
public function parse(): array
10+
{
11+
$input = file_get_contents('php://input');
12+
13+
if (json_validate($input)) {
14+
return json_decode($input, true);
15+
}
16+
17+
$inputStreamData = str($input)
18+
->explode('&')
19+
->mapWithKeys(function (string $item) {
20+
$parts = explode('=', $item, 2);
21+
22+
$key = $parts[0];
23+
24+
$value = $_POST[str_replace('.', '_', $key)] ?? $parts[1] ?? '';
25+
26+
yield $key => $value;
27+
})
28+
->toArray();
29+
30+
return $_POST + $inputStreamData;
31+
}
32+
}

src/Tempest/Router/src/Input/StdinPostInputStream.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Tempest/Router/src/Mappers/RequestToObjectMapper.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
use Tempest\Mapper\Mapper;
88
use Tempest\Mapper\Mappers\ArrayToObjectMapper;
99
use Tempest\Router\Request;
10-
use Tempest\Validation\Exceptions\PropertyValidationException;
1110
use Tempest\Validation\Exceptions\ValidationException;
1211
use Tempest\Validation\Validator;
1312

1413
use function Tempest\map;
15-
use function Tempest\reflect;
1614

1715
final readonly class RequestToObjectMapper implements Mapper
1816
{

0 commit comments

Comments
 (0)