Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

anniefu
Copy link
Contributor

@anniefu anniefu commented Nov 5, 2021

Allow expressing the function signature type configuration through code
instead of through FUNCTION_SIGNATURE_TYPE env var. This means
the FUNCTION_SIGNATURE_TYPE var can be omitted when deploying
a function with a declarative function signature.

The new signature also changes to using the official CloudEventInterface from the CloudEvents SDK instead of the Function Framework's custom class.

The primary difference is $cloudevent->getTime() returns a DateTime instead of a string. This can be converted back to a string as follows:

$cloudevent->getTime()->format(DateTimeInterface::RFC3339_EXTENDED);

Define your Function

index.php

<?php

require 'vendor/autoload.php';

use Psr\Http\Message\ServerRequestInterface;
use Google\CloudFunctions\FunctionsFramework;
use CloudEvents\V1\CloudEventInterface;
 
FunctionsFramework::http("helloHttp", func(ServerRequestInterface $request)
{
   return "Hello World from a PHP HTTP function!" . PHP_EOL;
});
 
FunctionsFramework::cloudEvent("helloCloudEvents", func(CloudEventInterface $cloudevent)
{
   // Print the whole CloudEvent
   $stdout = fopen('php://stdout', 'wb');
   fwrite($stdout, $cloudevent);
});

Run your function

php -S localhost:8080 vendor/bin/router.php

@anniefu anniefu requested a review from bshaffer November 5, 2021 18:53
Allow expressing the function signature type configuration through code
instead of through `FUNCTION_SIGNATURE_TYPE` env var.
@anniefu anniefu requested a review from bshaffer November 8, 2021 22:59
@anniefu anniefu requested a review from bshaffer November 9, 2021 01:13
Copy link
Collaborator

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two super-nits and then this is approved!

@bshaffer bshaffer merged commit 7e84ad4 into GoogleCloudPlatform:master Nov 9, 2021
anniefu added a commit to anniefu/php-docs-samples that referenced this pull request Nov 18, 2021
Update to the new [declarative function
signature](GoogleCloudPlatform/functions-framework-php#116)  style that was
introduced in Functions Framework v1.1.0
anniefu added a commit to anniefu/php-docs-samples that referenced this pull request Nov 18, 2021
Update to the new [declarative function
signature](GoogleCloudPlatform/functions-framework-php#116)  style that was
introduced in Functions Framework v1.1.0
anniefu added a commit to anniefu/php-docs-samples that referenced this pull request Nov 18, 2021
Update to the new [declarative function
signature](GoogleCloudPlatform/functions-framework-php#116)  style that was
introduced in Functions Framework v1.1.0
anniefu added a commit to anniefu/php-docs-samples that referenced this pull request Nov 18, 2021
helloworld_storage

Update to the new [declarative function signature](GoogleCloudPlatform/functions-framework-php#116)  style that was introduced in Functions Framework v1.1.0
anniefu added a commit to anniefu/php-docs-samples that referenced this pull request Nov 18, 2021
helloworld_pubsub

Update to the new [declarative function signature](GoogleCloudPlatform/functions-framework-php#116)  style that was introduced in Functions Framework v1.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants