Skip to content

Commit 6cde81b

Browse files
authored
Merge branch 'main' into main
2 parents aacab07 + a37a177 commit 6cde81b

File tree

6 files changed

+150
-45
lines changed

6 files changed

+150
-45
lines changed

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]

storage/src/move_object_atomic.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Google Inc.
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/storage/README.md
22+
*/
23+
24+
namespace Google\Cloud\Samples\Storage;
25+
26+
# [START storage_move_object]
27+
use Google\Cloud\Storage\StorageClient;
28+
29+
/**
30+
* Move an object to a new name within HNS-enabled bucket.
31+
*
32+
* @param string $bucketName The name of your Cloud Storage bucket.
33+
* (e.g. 'my-bucket')
34+
* @param string $objectName The name of your Cloud Storage object.
35+
* (e.g. 'my-object')
36+
* @param string $newObjectName the destination object name.
37+
* (e.g. 'my-other-object')
38+
*/
39+
function move_object_atomic(string $bucketName, string $objectName, string $newObjectName): void
40+
{
41+
$storage = new StorageClient();
42+
$bucket = $storage->bucket($bucketName);
43+
$object = $bucket->object($objectName);
44+
$object->move($newObjectName);
45+
printf('Moved gs://%s/%s to gs://%s/%s' . PHP_EOL,
46+
$bucketName,
47+
$objectName,
48+
$bucketName,
49+
$newObjectName);
50+
}
51+
# [END storage_move_object]
52+
53+
// The following 2 lines are only needed to run the samples
54+
require_once __DIR__ . '/../../testing/sample_helpers.php';
55+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

storage/test/ObjectsTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,44 @@ public function testManageObject()
151151
$this->assertEquals($output, $outputString);
152152
}
153153

154+
public function testMoveObjectAtomic()
155+
{
156+
$bucketName = self::$bucketName . '-hns';
157+
$objectName = 'test-object-' . time();
158+
$newObjectName = $objectName . '-moved';
159+
$bucket = self::$storage->createBucket($bucketName, [
160+
'hierarchicalNamespace' => ['enabled' => true],
161+
'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => true]]
162+
]);
163+
164+
$object = $bucket->upload('test', ['name' => $objectName]);
165+
$this->assertTrue($object->exists());
166+
167+
$output = self::runFunctionSnippet('move_object_atomic', [
168+
$bucketName,
169+
$objectName,
170+
$newObjectName
171+
]);
172+
173+
$this->assertEquals(
174+
sprintf(
175+
'Moved gs://%s/%s to gs://%s/%s' . PHP_EOL,
176+
$bucketName,
177+
$objectName,
178+
$bucketName,
179+
$newObjectName
180+
),
181+
$output
182+
);
183+
184+
$this->assertFalse($object->exists());
185+
$movedObject = $bucket->object($newObjectName);
186+
$this->assertTrue($movedObject->exists());
187+
188+
$bucket->object($newObjectName)->delete();
189+
$bucket->delete();
190+
}
191+
154192
public function testCompose()
155193
{
156194
$bucket = self::$storage->bucket(self::$bucketName);

translate/src/v3_translate_text.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
namespace Google\Cloud\Samples\Translate;
1919

2020
// [START translate_v3_translate_text]
21+
// [START translate_v3_import_client_library]
2122
use Google\Cloud\Translate\V3\Client\TranslationServiceClient;
23+
// [END translate_v3_import_client_library]
2224
use Google\Cloud\Translate\V3\TranslateTextRequest;
2325

2426
/**
@@ -42,6 +44,7 @@ function v3_translate_text(
4244
->setTargetLanguageCode($targetLanguage)
4345
->setParent($formattedParent);
4446
$response = $translationServiceClient->translateText($request);
47+
4548
// Display the translation for each input text provided
4649
foreach ($response->getTranslations() as $translation) {
4750
printf('Translated text: %s' . PHP_EOL, $translation->getTranslatedText());

0 commit comments

Comments
 (0)