spiral / roadrunner-bridge

🌉 RoadRunner bridge to Spiral Framework
https://spiral.dev/docs/packages-roadrunner-bridge
MIT License
12 stars 6 forks source link

Add Message Object Access in Interceptors for gRPC Component #92

Closed butschster closed 8 months ago

butschster commented 9 months ago

Overview

This pull request introduces a significant enhancement to the gRPC component. Previously, interceptors could only access incoming requests as binary strings. This limitation restricted the ability to analyze and manipulate request data effectively.

<?php

declare(strict_types=1);

namespace ...\gRPC\Interceptor\Incoming;

use Spiral\Core\CoreInterceptorInterface;
use Spiral\Core\CoreInterface;
use Spiral\RoadRunner\GRPC\ContextInterface;
use Spiral\RoadRunner\GRPC\ServiceInterface;

final class SomeInterceptor implements CoreInterceptorInterface
{
    /**
     * @param array{service: ServiceInterface, ctx: ContextInterface, input: string} $parameters
     */
    public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed
    {
        dump($parameters['input']);

        return $core->callAction($controller, $action, $parameters);
    }
}

Key Changes

<?php

declare(strict_types=1);

namespace ...\gRPC\Interceptor\Incoming;

use Spiral\Core\CoreInterceptorInterface;
use Spiral\Core\CoreInterface;
use Spiral\RoadRunner\GRPC\ContextInterface;
use Spiral\RoadRunner\GRPC\ServiceInterface;
use Google\Protobuf\Internal\Message;

final class SomeInterceptor implements CoreInterceptorInterface
{
    /**
     * @param array{
     *     service: ServiceInterface, 
     *     ctx: ContextInterface, 
     *     input: string, 
     *     message: Message
     * } $parameters
     */
    public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed
    {
        dump($parameters['message']);

        return $core->callAction($controller, $action, $parameters);
    }
}

Impact

This improvement allows developers to create more robust and secure applications using the Spiral Framework. By enabling detailed inspection and validation of incoming requests, we enhance both the flexibility and security of the gRPC component.

Q A
Bugfix?
Breaks BC?
New feature? ✔️
Issues #90

I welcome feedback and further suggestions on this enhancement.

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (2cf49a9) 92.87% compared to head (20438d7) 92.95%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## 3.x #92 +/- ## ============================================ + Coverage 92.87% 92.95% +0.08% - Complexity 316 321 +5 ============================================ Files 62 62 Lines 1010 1022 +12 ============================================ + Hits 938 950 +12 Misses 72 72 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.