GoogleCloudPlatform / GoogleCloudPlatform/functions-framework-php

Issues with FunctionsFramework::cloudEvent()

Offen
#159 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug P2
Vorherrschende Sprache
PHP
Sterne
213
Forks
37
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Having issues with FunctionsFramework::cloudEvent() when running in Cloud Functions (but not locally) as documented at https://cloud.google.com/functions/docs/tutorials/pubsub#preparing_the_application.

I'm calling the following:

```php
FunctionsFramework::cloudEvent('eventarc-event-name', 'myFunctionName');

function myFunctionName(\CloudEvents\V1\CloudEventInterface $event)
```

This runs locally, but when I run it on Cloud Run the it tells me I have to hint Google\CloudFunctions\CloudEvent, but if I do that it wants CloudEventInterface instead. Putting either results in the other being required.

```
PHP message: PHP Fatal error: Uncaught LogicException: Your function must have "Google\CloudFunctions\CloudEvent" as the typehint for the first argument in /workspace/vendor/google/cloud-functions-framework/src/CloudEventFunctionWrapper.php:65
```

I can't repeat this locally. FunctionsFramework calls the following, which locally always forces CloudEventInterface, and I can debug this right through to the Reflection check on line 71 of CloudEventFunctionWrapper

```php
public static function cloudEvent(string $name, callable $fn)
{
Invoker::registerFunction($name, new CloudEventFunctionWrapper($fn, true));
}
```

If I do both (which seems probably unintended and wrong anyway), I get the following error:

```
PHP message: PHP Fatal error: Uncaught Error: Call to undefined method ReflectionUnionType::getName() in /workspace/vendor/google/cloud-functions-framework/src/CloudEventFunctionWrapper.php:75 Stack trace: #0 /workspace/vendor/google/cloud-functions-framework/src/FunctionValidationTrait.php(43): Google\CloudFunctions\CloudEventFunctionWrapper->validateFirstParameter(Object(ReflectionParameter)) #1 /workspace/vendor/google/cloud-functions-framework/src/CloudEventFunctionWrapper.php(58): Google\CloudFunctions\CloudEventFunctionWrapper->validateFunctionSignature(Object(ReflectionFunction)) #2 /workspace/vendor/google/cloud-functions-framework/src/FunctionsFramework.php(35): Google\CloudFunctions\CloudEventFunctionWrapper->__construct('dicomwebImport', true) #3 /workspace/index.php(11): Google\CloudFunctions\FunctionsFramework::cloudEvent('transport-reque...', 'dicomwebImport') #4 /workspace/vendor/google/cloud-functions-framework/router.php(37): require_once('/workspace/inde...')
```

I'm not even sure how to proceed here, as this is the officially documented approach, but doesn't appear in the readme for this project at all.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit CloudEventFunctionWrapper.php bei den Validierungsprüfungen um die Zeilen 65–75 und FunctionsFramework::cloudEvent(), und vergleiche anschließend die dokumentierte Signatur mit dem hier beschriebenen Verhalten von Cloud Run und der lokalen Umgebung. Reproduziere die Type-Hint-Validierung und den ReflectionUnionType-Fehler; abgeschlossen ist die Aufgabe, wenn die dokumentierte CloudEvent-Funktionssignatur in beiden Umgebungen konsistent behandelt wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
google-cloud, php
Bereich
backend, cloud
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.