Skip to content

Commit

Permalink
Allow spiral/roadrunner-tcp 4.0 (#102)
Browse files Browse the repository at this point in the history
* Allow spiral/roadrunner-tcp 4.0

* Fix test
  • Loading branch information
msmakouz committed Apr 12, 2024
1 parent 15013b3 commit 191042e
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 16 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ on:
pull_request: null
push:
branches:
- master
- '*.*'

name: phpunit
Expand All @@ -14,7 +13,5 @@ jobs:
install_protoc: true
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2']
stability: >-
['prefer-stable']
3 changes: 0 additions & 3 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ on:
pull_request: null
push:
branches:
- master
- '*.*'

name: static analysis
Expand All @@ -13,5 +12,3 @@ jobs:
with:
os: >-
['ubuntu-latest']
php: >-
['8.1']
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Spiral Scout
Copyright (c) 2024 Spiral Scout

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"spiral/roadrunner-grpc": "^3.2",
"spiral/roadrunner-jobs": "^4.0",
"spiral/roadrunner-kv": "^4.0",
"spiral/roadrunner-tcp": "^3.0",
"spiral/roadrunner-tcp": "^3.1 || ^4.0",
"spiral/roadrunner-metrics": "^3.0",
"roadrunner-php/app-logger": "^1.0",
"roadrunner-php/centrifugo": "^2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function push(
*/
private function initQueue(?string $pipeline): RRQueueInterface
{
if (!$pipeline) {
if ($pipeline === null || $pipeline === '') {
throw new InvalidArgumentException('You must define RoadRunner queue pipeline.');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Tcp/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function serve(WorkerInterface $worker = null, callable $finalize = null)

while ($request = $tcpWorker->waitRequest()) {
try {
$core = $this->createHandler($request->server);
$core = $this->createHandler($request->getServer());
/** @var ResponseInterface $response */
$response = $core->callAction($request->server, 'handle', ['request' => $request]);
$response = $core->callAction($request->getServer(), 'handle', ['request' => $request]);
} catch (\Throwable $e) {
$worker->error($this->config->isDebugMode() ? (string)$e : $e->getMessage());
$response = new CloseConnection();
Expand Down
4 changes: 4 additions & 0 deletions src/Tcp/Service/ServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
namespace Spiral\RoadRunnerBridge\Tcp\Service;

use Spiral\RoadRunner\Tcp\Request;
use Spiral\RoadRunner\Tcp\RequestInterface;
use Spiral\RoadRunnerBridge\Tcp\Response\ResponseInterface;

interface ServiceInterface
{
/**
* @param Request $request. Will be changed to {@see RequestInterface} in the v4.0.
*/
public function handle(Request $request): ResponseInterface;
}
11 changes: 9 additions & 2 deletions tests/app/Tcp/TestInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Spiral\Core\CoreInterceptorInterface;
use Spiral\Core\CoreInterface;
use Spiral\RoadRunner\Tcp\Request;
use Spiral\RoadRunnerBridge\Tcp\Response\ContinueRead;

class TestInterceptor implements CoreInterceptorInterface
Expand All @@ -15,11 +16,17 @@ class TestInterceptor implements CoreInterceptorInterface
public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed
{
if (\count($this->data) < 5) {
$this->data[] = $parameters['request']->body;
$this->data[] = $parameters['request']->getBody();
}

if (\count($this->data) === 5) {
$parameters['request']->body = \json_encode($this->data, JSON_THROW_ON_ERROR);
$parameters['request'] = new Request(
remoteAddr: $parameters['request']->getRemoteAddress(),
event: $parameters['request']->getEvent(),
body: \json_encode($this->data, JSON_THROW_ON_ERROR),
connectionUuid: $parameters['request']->getConnectionUuid(),
server: $parameters['request']->getServer(),
);

return $core->callAction($controller, $action, $parameters);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/app/Tcp/TestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class TestService implements ServiceInterface
{
public function handle(Request $request): ResponseInterface
{
return new RespondMessage($request->body, true);
return new RespondMessage($request->getBody(), true);
}
}
4 changes: 2 additions & 2 deletions tests/src/Bootloader/RoadRunnerBootloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function testFailbackDispatcherShouldBeLast(): void
{
$kernel = $this->getContainer()->get(KernelInterface::class);
$dispatchers = (new \ReflectionProperty($kernel, 'dispatchers'))->getValue($kernel);
$dispatchers = \array_filter($dispatchers, static fn (mixed $disp): bool => !$disp instanceof ConsoleDispatcher);
$dispatchers = \array_filter($dispatchers, static fn (string $disp): bool => $disp !== ConsoleDispatcher::class);

$this->assertInstanceOf(FallbackDispatcher::class, $dispatchers[\array_key_last($dispatchers)]);
$this->assertSame(FallbackDispatcher::class, $dispatchers[\array_key_last($dispatchers)]);
}
}

0 comments on commit 191042e

Please sign in to comment.