Skip to content

fix: Update event function code samples when using CloudEventInterface #2082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions functions/helloworld_pubsub/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@
// This enables omitting the `FUNCTIONS_SIGNATURE_TYPE=cloudevent` environment
// variable when deploying. The `FUNCTION_TARGET` environment variable should
// match the first parameter.
FunctionsFramework::cloudEvent('helloworldPubsub', 'helloworldPubsub');

function helloworldPubsub(CloudEventInterface $event): void
{
FunctionsFramework::cloudEvent('helloworldPubsub', function (CloudEventInterface $event) {
$log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb');

$cloudEventData = $event->getData();
$pubSubData = base64_decode($cloudEventData['message']['data']);

$name = $pubSubData ? htmlspecialchars($pubSubData) : 'World';
fwrite($log, "Hello, $name!" . PHP_EOL);
}
});
// [END functions_helloworld_pubsub]
// [END functions_cloudevent_pubsub]
7 changes: 2 additions & 5 deletions functions/helloworld_storage/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
// This enables omitting the `FUNCTIONS_SIGNATURE_TYPE=cloudevent` environment
// variable when deploying. The `FUNCTION_TARGET` environment variable should
// match the first parameter.
FunctionsFramework::cloudEvent('helloGCS', 'helloGCS');

function helloGCS(CloudEventInterface $cloudevent)
{
FunctionsFramework::cloudEvent('helloGCS', function (CloudEventInterface $cloudevent) {
// This function supports all Cloud Storage event types.
$log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb');
$data = $cloudevent->getData();
Expand All @@ -40,7 +37,7 @@ function helloGCS(CloudEventInterface $cloudevent)
fwrite($log, 'Metageneration: ' . $data['metageneration'] . PHP_EOL);
fwrite($log, 'Created: ' . $data['timeCreated'] . PHP_EOL);
fwrite($log, 'Updated: ' . $data['updated'] . PHP_EOL);
}
});

// [END functions_cloudevent_storage]
// [END functions_helloworld_storage]