Skip to content
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

chore: introduce functions samples #5361

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_CallFunction_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$formattedName = $cloudFunctionsServiceClient->cloudFunctionName('[PROJECT]', '[LOCATION]', '[FUNCTION]');
$data = 'data';
$response = $cloudFunctionsServiceClient->callFunction($formattedName, $data);
} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_CallFunction_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_CreateFunction_sync]
use Google\Cloud\Functions\V1\CloudFunction;
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$formattedLocation = $cloudFunctionsServiceClient->locationName('[PROJECT]', '[LOCATION]');
$function = new CloudFunction();
$operationResponse = $cloudFunctionsServiceClient->createFunction($formattedLocation, $function);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}

// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $cloudFunctionsServiceClient->createFunction($formattedLocation, $function);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $cloudFunctionsServiceClient->resumeOperation($operationName, 'createFunction');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}

if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}

} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_CreateFunction_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_DeleteFunction_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$formattedName = $cloudFunctionsServiceClient->cloudFunctionName('[PROJECT]', '[LOCATION]', '[FUNCTION]');
$operationResponse = $cloudFunctionsServiceClient->deleteFunction($formattedName);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// operation succeeded and returns no value
} else {
$error = $operationResponse->getError();
// handleError($error)
}

// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $cloudFunctionsServiceClient->deleteFunction($formattedName);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $cloudFunctionsServiceClient->resumeOperation($operationName, 'deleteFunction');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}

if ($newOperationResponse->operationSucceeded()) {
// operation succeeded and returns no value
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}

} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_DeleteFunction_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_GenerateDownloadUrl_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$response = $cloudFunctionsServiceClient->generateDownloadUrl();
} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_GenerateDownloadUrl_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_GenerateUploadUrl_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$response = $cloudFunctionsServiceClient->generateUploadUrl();
} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_GenerateUploadUrl_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_GetFunction_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$formattedName = $cloudFunctionsServiceClient->cloudFunctionName('[PROJECT]', '[LOCATION]', '[FUNCTION]');
$response = $cloudFunctionsServiceClient->getFunction($formattedName);
} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_GetFunction_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_GetIamPolicy_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$resource = 'resource';
$response = $cloudFunctionsServiceClient->getIamPolicy($resource);
} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_GetIamPolicy_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_ListFunctions_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
// Iterate over pages of elements
$pagedResponse = $cloudFunctionsServiceClient->listFunctions();
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}

}

// Alternatively:
// Iterate through all elements
$pagedResponse = $cloudFunctionsServiceClient->listFunctions();
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}

} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_ListFunctions_sync]
Loading