Skip to content

Commit f3fd31e

Browse files
Merge branch 'main' into jackwotherspoon-patch-1
2 parents 8d9e19a + 6962dba commit f3fd31e

File tree

54 files changed

+3618
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3618
-72
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
php-version: '8.2'
2929
- name: Get changed files
3030
id: changedFiles
31-
uses: tj-actions/changed-files@v44
31+
uses: tj-actions/changed-files@v46
3232
- uses: jwalton/gh-find-current-pr@v1
3333
id: findPr
3434
with:

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
->setFinder(
3737
PhpCsFixer\Finder::create()
3838
->in(__DIR__)
39+
->exclude(['generated'])
3940
)
4041
;
4142

CODEOWNERS

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/cloud_sql/**/*.php @GoogleCloudPlatform/cloud-sql-connectors @GoogleCloudPlatform/php-samples-reviewers
2323
/datastore/**/*.php @GoogleCloudPlatform/cloud-native-db-dpes @GoogleCloudPlatform/php-samples-reviewers
2424
/firestore/**/*.php @GoogleCloudPlatform/cloud-native-db-dpes @GoogleCloudPlatform/php-samples-reviewers
25-
/storage/ @GoogleCloudPlatform/cloud-storage-dpe @GoogleCloudPlatform/php-samples-reviewers
25+
/storage/ @GoogleCloudPlatform/gcs-sdk-team @GoogleCloudPlatform/php-samples-reviewers
2626
/spanner/ @GoogleCloudPlatform/api-spanner @GoogleCloudPlatform/php-samples-reviewers
2727
/secretmanager/ @GoogleCloudPlatform/php-samples-reviewers @GoogleCloudPlatform/cloud-secrets-team
2828

@@ -33,10 +33,6 @@
3333
/run/ @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/php-samples-reviewers
3434
/eventarc/ @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/php-samples-reviewers
3535

36-
# Functions samples owned by the Firebase team
37-
38-
/functions/firebase_analytics @schandel
39-
4036
# DLP samples owned by DLP team
4137

4238
/dlp/ @GoogleCloudPlatform/googleapis-dlp

documentai/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"google/cloud-document-ai": "^1.0.1"
3+
"google/cloud-document-ai": "^2.1.3"
44
}
55
}

documentai/phpunit.xml.dist

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
-->
17-
<phpunit bootstrap="../testing/bootstrap.php">
18-
<testsuites>
19-
<testsuite name="PHP documentai test">
20-
<directory>test</directory>
21-
</testsuite>
22-
</testsuites>
23-
<logging>
24-
<log type="coverage-clover" target="build/logs/clover.xml"/>
25-
</logging>
26-
<filter>
27-
<whitelist>
28-
<directory suffix=".php">./src</directory>
29-
<file>quickstart.php</file>
30-
<exclude>
31-
<directory>./vendor</directory>
32-
</exclude>
33-
</whitelist>
34-
</filter>
35-
<php>
36-
<env name="PHPUNIT_TESTS" value="1"/>
37-
</php>
17+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="../testing/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
18+
<coverage>
19+
<include>
20+
<directory suffix=".php">./src</directory>
21+
<file>quickstart.php</file>
22+
</include>
23+
<exclude>
24+
<directory>./vendor</directory>
25+
</exclude>
26+
<report>
27+
<clover outputFile="build/logs/clover.xml"/>
28+
</report>
29+
</coverage>
30+
<testsuites>
31+
<testsuite name="PHP documentai test">
32+
<directory>test</directory>
33+
</testsuite>
34+
</testsuites>
35+
<logging/>
36+
<php>
37+
<env name="PHPUNIT_TESTS" value="1"/>
38+
</php>
3839
</phpunit>

documentai/quickstart.php

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,51 @@
1616
*/
1717

1818
# [START documentai_quickstart]
19-
# Includes the autoloader for libraries installed with composer
19+
# Include the autoloader for libraries installed with Composer.
2020
require __DIR__ . '/vendor/autoload.php';
2121

22-
# Imports the Google Cloud client library
23-
use Google\Cloud\DocumentAI\V1\DocumentProcessorServiceClient;
22+
# Import the Google Cloud client library.
23+
use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient;
2424
use Google\Cloud\DocumentAI\V1\RawDocument;
25+
use Google\Cloud\DocumentAI\V1\ProcessRequest;
2526

26-
$projectId = 'YOUR_PROJECT_ID'; # Your Google Cloud Platform project ID
27-
$location = 'us'; # Your Processor Location
28-
$processor = 'YOUR_PROCESSOR_ID'; # Your Processor ID
27+
# TODO(developer): Update the following lines before running the sample.
28+
# Your Google Cloud Platform project ID.
29+
$projectId = 'YOUR_PROJECT_ID';
2930

30-
# Create Client
31-
$client = new DocumentProcessorServiceClient();
31+
# Your Processor Location.
32+
$location = 'us';
33+
34+
# Your Processor ID as hexadecimal characters.
35+
# Not to be confused with the Processor Display Name.
36+
$processorId = 'YOUR_PROCESSOR_ID';
3237

33-
# Local File Path
38+
# Path for the file to read.
3439
$documentPath = 'resources/invoice.pdf';
3540

36-
# Read in File Contents
41+
# Create Client.
42+
$client = new DocumentProcessorServiceClient();
43+
44+
# Read in file.
3745
$handle = fopen($documentPath, 'rb');
3846
$contents = fread($handle, filesize($documentPath));
3947
fclose($handle);
4048

41-
# Load File Contents into RawDocument
42-
$rawDocument = new RawDocument([
43-
'content' => $contents,
44-
'mime_type' => 'application/pdf'
45-
]);
49+
# Load file contents into a RawDocument.
50+
$rawDocument = (new RawDocument())
51+
->setContent($contents)
52+
->SetMimeType('application/pdf');
4653

47-
# Fully-qualified Processor Name
48-
$name = $client->processorName($projectId, $location, $processor);
54+
# Get the Fully-qualified Processor Name.
55+
$fullProcessorName = $client->processorName($projectId, $location, $processorId);
4956

50-
# Make Processing Request
51-
$response = $client->processDocument($name, [
52-
'rawDocument' => $rawDocument
53-
]);
57+
# Send a ProcessRequest and get a ProcessResponse.
58+
$request = (new ProcessRequest())
59+
->setName($fullProcessorName)
60+
->setRawDocument($rawDocument);
5461

55-
# Print Document Text
56-
printf('Document Text: %s', $response->getDocument()->getText());
62+
$response = $client->processDocument($request);
5763

64+
# Show the text found in the document.
65+
printf('Document Text: %s', $response->getDocument()->getText());
5866
# [END documentai_quickstart]

secretmanager/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"google/cloud-secret-manager": "^1.13"
3+
"google/cloud-secret-manager": "^1.15.2"
44
}
55
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/*
3+
* Copyright 2024 Google LLC.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* For instructions on how to run the full sample:
20+
*
21+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
22+
*/
23+
24+
declare(strict_types=1);
25+
26+
namespace Google\Cloud\Samples\SecretManager;
27+
28+
// [START secretmanager_access_regional_secret_version]
29+
// Import the Secret Manager client library.
30+
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
31+
use Google\Cloud\SecretManager\V1\AccessSecretVersionRequest;
32+
33+
/**
34+
* @param string $projectId Your Google Cloud Project ID (e.g. 'my-project')
35+
* @param string $locationId Your secret Location (e.g. "us-central1")
36+
* @param string $secretId Your secret ID (e.g. 'my-secret')
37+
* @param string $versionId Your version ID (e.g. 'latest' or '5');
38+
*/
39+
function access_regional_secret_version(
40+
string $projectId,
41+
string $locationId,
42+
string $secretId,
43+
string $versionId
44+
): void {
45+
// Specify regional endpoint.
46+
$options = ['apiEndpoint' => "secretmanager.$locationId.rep.googleapis.com"];
47+
48+
// Create the Secret Manager client.
49+
$client = new SecretManagerServiceClient($options);
50+
51+
// Build the resource name of the secret version.
52+
$name = $client->projectLocationSecretSecretVersionName($projectId, $locationId, $secretId, $versionId);
53+
54+
// Build the request.
55+
$request = AccessSecretVersionRequest::build($name);
56+
57+
// Access the secret version.
58+
$response = $client->accessSecretVersion($request);
59+
60+
// Print the secret payload.
61+
//
62+
// WARNING: Do not print the secret in a production environment - this
63+
// snippet is showing how to access the secret material.
64+
$payload = $response->getPayload()->getData();
65+
printf('Plaintext: %s', $payload);
66+
}
67+
// [END secretmanager_access_regional_secret_version]
68+
69+
// The following 2 lines are only needed to execute the samples on the CLI
70+
require_once __DIR__ . '/../../testing/sample_helpers.php';
71+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/*
3+
* Copyright 2024 Google LLC.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* For instructions on how to run the full sample:
20+
*
21+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
22+
*/
23+
24+
declare(strict_types=1);
25+
26+
namespace Google\Cloud\Samples\SecretManager;
27+
28+
// [START secretmanager_add_regional_secret_version]
29+
// Import the Secret Manager client library.
30+
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
31+
use Google\Cloud\SecretManager\V1\AddSecretVersionRequest;
32+
use Google\Cloud\SecretManager\V1\SecretPayload;
33+
34+
/**
35+
* @param string $projectId Your Google Cloud Project ID (e.g. 'my-project')
36+
* @param string $locationId Your secret Location (e.g. "us-central1")
37+
* @param string $secretId Your secret ID (e.g. 'my-secret')
38+
*/
39+
function add_regional_secret_version(string $projectId, string $locationId, string $secretId): void
40+
{
41+
// Specify regional endpoint.
42+
$options = ['apiEndpoint' => "secretmanager.$locationId.rep.googleapis.com"];
43+
44+
// Create the Secret Manager client.
45+
$client = new SecretManagerServiceClient($options);
46+
47+
// Build the resource name of the parent secret and the payload.
48+
$parent = $client->projectLocationSecretName($projectId, $locationId, $secretId);
49+
$secretPayload = new SecretPayload([
50+
'data' => 'my super secret data',
51+
]);
52+
53+
// Build the request.
54+
$request = AddSecretVersionRequest::build($parent, $secretPayload);
55+
56+
// Access the secret version.
57+
$response = $client->addSecretVersion($request);
58+
59+
// Print the new secret version name.
60+
printf('Added secret version: %s', $response->getName());
61+
}
62+
// [END secretmanager_add_regional_secret_version]
63+
64+
// The following 2 lines are only needed to execute the samples on the CLI
65+
require_once __DIR__ . '/../../testing/sample_helpers.php';
66+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/*
3+
* Copyright 2024 Google LLC.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* For instructions on how to run the full sample:
20+
*
21+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
22+
*/
23+
24+
declare(strict_types=1);
25+
26+
namespace Google\Cloud\Samples\SecretManager;
27+
28+
// [START secretmanager_create_regional_secret]
29+
// Import the Secret Manager client library.
30+
use Google\Cloud\SecretManager\V1\CreateSecretRequest;
31+
use Google\Cloud\SecretManager\V1\Secret;
32+
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
33+
34+
/**
35+
* @param string $projectId Your Google Cloud Project ID (e.g. 'my-project')
36+
* @param string $locationId Your secret Location (e.g. "us-central1")
37+
* @param string $secretId Your secret ID (e.g. 'my-secret')
38+
*/
39+
function create_regional_secret(string $projectId, string $locationId, string $secretId): void
40+
{
41+
// Specify regional endpoint.
42+
$options = ['apiEndpoint' => "secretmanager.$locationId.rep.googleapis.com"];
43+
44+
// Create the Secret Manager client.
45+
$client = new SecretManagerServiceClient($options);
46+
47+
// Build the resource name of the parent project.
48+
$parent = $client->locationName($projectId, $locationId);
49+
50+
$secret = new Secret();
51+
52+
// Build the request.
53+
$request = CreateSecretRequest::build($parent, $secretId, $secret);
54+
55+
// Create the secret.
56+
$newSecret = $client->createSecret($request);
57+
58+
// Print the new secret name.
59+
printf('Created secret: %s', $newSecret->getName());
60+
}
61+
// [END secretmanager_create_regional_secret]
62+
63+
// The following 2 lines are only needed to execute the samples on the CLI
64+
require_once __DIR__ . '/../../testing/sample_helpers.php';
65+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)