GoogleCloudPlatform / GoogleCloudPlatform/functions-framework-php

Issues with FunctionsFramework::cloudEvent()

Aperta
#159 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
bug P2
Lingua principale
PHP
Stelle
213
Fork
37
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con CloudEventFunctionWrapper.php, nei controlli di validazione intorno alle righe 65-75, e con FunctionsFramework::cloudEvent(), quindi confronta la firma documentata con il comportamento di Cloud Run e locale descritto qui. Riproduci la validazione del type-hint e il fallimento di ReflectionUnionType; il lavoro è completato quando la firma documentata della funzione CloudEvent viene gestita in modo coerente in entrambi gli ambienti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
google-cloud, php
Ambito
backend, cloud
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.