diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index fb9234187d..8cf828e51b 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -105,14 +105,14 @@ Install that by running
composer global require friendsofphp/php-cs-fixer
```
-Then to fix your directory or file run
+Then to fix your directory or file run
```
php-cs-fixer fix . --config .php-cs-fixer.dist.php
php-cs-fixer fix path/to/file --config .php-cs-fixer.dist.php
```
-The [DLP snippets](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp) are an example of snippets following the latest style guidelines.
+The [DLP snippets](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp) are an example of snippets following the latest style guidelines.
[psr2]: http://www.php-fig.org/psr/psr-2/
[psr4]: http://www.php-fig.org/psr/psr-4/
diff --git a/analyticsdata/composer.json b/analyticsdata/composer.json
index d4d507afb9..dcbb91fa17 100644
--- a/analyticsdata/composer.json
+++ b/analyticsdata/composer.json
@@ -1,5 +1,5 @@
{
"require": {
- "google/analytics-data": "^0.8.0"
+ "google/analytics-data": "^0.9.0"
}
}
diff --git a/analyticsdata/quickstart_oauth2/composer.json b/analyticsdata/quickstart_oauth2/composer.json
index 000ec4b750..fa31a3c25d 100644
--- a/analyticsdata/quickstart_oauth2/composer.json
+++ b/analyticsdata/quickstart_oauth2/composer.json
@@ -1,6 +1,6 @@
{
"require": {
- "google/analytics-data": "^0.8.0",
+ "google/analytics-data": "^0.9.0",
"ext-bcmath": "*"
}
}
diff --git a/appengine/flexible/tasks/src/create_task.php b/appengine/flexible/tasks/src/create_task.php
index f06bc6d33f..fdd2abb6e9 100644
--- a/appengine/flexible/tasks/src/create_task.php
+++ b/appengine/flexible/tasks/src/create_task.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/appengine/flexible/tasks/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/appengine/flexible/tasks/README.md
*/
namespace Google\Cloud\Samples\Tasks;
diff --git a/appengine/standard/auth/src/auth_api.php b/appengine/standard/auth/src/auth_api.php
index 09578f2c74..e3f0a5dbf1 100644
--- a/appengine/standard/auth/src/auth_api.php
+++ b/appengine/standard/auth/src/auth_api.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/auth/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md
*/
# [START gae_auth_api_implicit]
diff --git a/appengine/standard/auth/src/auth_cloud.php b/appengine/standard/auth/src/auth_cloud.php
index 1ca0f8eb03..2ce4ff41b2 100644
--- a/appengine/standard/auth/src/auth_cloud.php
+++ b/appengine/standard/auth/src/auth_cloud.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/auth/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md
*/
# [START gae_auth_cloud_implicit]
diff --git a/appengine/standard/errorreporting/README.md b/appengine/standard/errorreporting/README.md
index 02bde344dc..2952836525 100644
--- a/appengine/standard/errorreporting/README.md
+++ b/appengine/standard/errorreporting/README.md
@@ -20,7 +20,7 @@ these two steps:
The [`prepend.php`][prepend] file will be executed prior to each request, which
registers the client library's error handler.
-[prepend]: https://github.com/GoogleCloudPlatform/google-cloud-php-errorreporting/blob/master/src/prepend.php
+[prepend]: https://github.com/GoogleCloudPlatform/google-cloud-php-errorreporting/blob/main/src/prepend.php
If you cannot modify your `php.ini`, the `prepend.php` file can be manually
included to register the error handler:
diff --git a/appengine/standard/laravel-framework/app/Exceptions/Handler.php b/appengine/standard/laravel-framework/app/Exceptions/Handler.php
index 0b3602d0e9..8e7d582876 100644
--- a/appengine/standard/laravel-framework/app/Exceptions/Handler.php
+++ b/appengine/standard/laravel-framework/app/Exceptions/Handler.php
@@ -31,7 +31,7 @@ class Handler extends ExceptionHandler
* Report or log an exception to Google Cloud Stackdriver Error Reporting
*
* For a full tutorial on deploying Laravel to Google Cloud,
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/appengine/standard/laravel-framework/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/appengine/standard/laravel-framework/README.md
*
* @param \Exception $exception
* @return void
diff --git a/appengine/standard/tasks/snippets/src/create_task.php b/appengine/standard/tasks/snippets/src/create_task.php
index ede334cf9a..e4bf9feca9 100644
--- a/appengine/standard/tasks/snippets/src/create_task.php
+++ b/appengine/standard/tasks/snippets/src/create_task.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/appengine/standard/tasks/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/appengine/standard/tasks/README.md
*/
// Include Google Cloud dependendencies using Composer
diff --git a/appengine/standard/wordpress/composer.json b/appengine/standard/wordpress/composer.json
index 437f4edad1..6f814f0c31 100644
--- a/appengine/standard/wordpress/composer.json
+++ b/appengine/standard/wordpress/composer.json
@@ -3,6 +3,6 @@
"ext-phar": "*",
"ext-zip": "*",
"paragonie/random_compat": "^9.0.0",
- "google/cloud-tools": "dev-master"
+ "google/cloud-tools": "dev-main"
}
}
diff --git a/auth/src/auth_api_explicit.php b/auth/src/auth_api_explicit.php
index 646a902295..c85a887c9c 100644
--- a/auth/src/auth_api_explicit.php
+++ b/auth/src/auth_api_explicit.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/auth/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md
*/
# [START auth_api_explicit]
diff --git a/auth/src/auth_api_explicit_compute.php b/auth/src/auth_api_explicit_compute.php
index 6f30441859..cd8320dbb9 100644
--- a/auth/src/auth_api_explicit_compute.php
+++ b/auth/src/auth_api_explicit_compute.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/auth/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md
*/
# [START auth_api_explicit_compute]
diff --git a/auth/src/auth_api_implicit.php b/auth/src/auth_api_implicit.php
index f99f9917e0..6327508c53 100644
--- a/auth/src/auth_api_implicit.php
+++ b/auth/src/auth_api_implicit.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/auth/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md
*/
# [START auth_api_implicit]
diff --git a/auth/src/auth_cloud_explicit.php b/auth/src/auth_cloud_explicit.php
index 58289501cf..a3fbefbdf5 100644
--- a/auth/src/auth_cloud_explicit.php
+++ b/auth/src/auth_cloud_explicit.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/auth/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md
*/
# [START auth_cloud_explicit]
diff --git a/auth/src/auth_cloud_explicit_compute.php b/auth/src/auth_cloud_explicit_compute.php
index 4b5454f19c..32dc1d9bb8 100644
--- a/auth/src/auth_cloud_explicit_compute.php
+++ b/auth/src/auth_cloud_explicit_compute.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/auth/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md
*/
# [START auth_cloud_explicit_compute]
diff --git a/auth/src/auth_cloud_implicit.php b/auth/src/auth_cloud_implicit.php
index af9331e249..90331a2297 100644
--- a/auth/src/auth_cloud_implicit.php
+++ b/auth/src/auth_cloud_implicit.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/auth/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md
*/
namespace Google\Cloud\Samples\Auth;
diff --git a/auth/src/auth_http_explicit.php b/auth/src/auth_http_explicit.php
index 962891c7f9..e3b3667097 100644
--- a/auth/src/auth_http_explicit.php
+++ b/auth/src/auth_http_explicit.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/auth/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md
*/
# [START auth_http_explicit]
diff --git a/auth/src/auth_http_implicit.php b/auth/src/auth_http_implicit.php
index 8b16f4aa54..749f3ab510 100644
--- a/auth/src/auth_http_implicit.php
+++ b/auth/src/auth_http_implicit.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/auth/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/auth/README.md
*/
# [START auth_http_implicit]
diff --git a/bigquery/api/src/add_column_load_append.php b/bigquery/api/src/add_column_load_append.php
new file mode 100644
index 0000000000..3150ef75e1
--- /dev/null
+++ b/bigquery/api/src/add_column_load_append.php
@@ -0,0 +1,79 @@
+ $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
+ // In this example, the existing table contains only the 'Name' and 'Title'.
+ // A new column 'Description' gets added after load job.
+
+ $schema = [
+ 'fields' => [
+ ['name' => 'name', 'type' => 'string', 'mode' => 'nullable'],
+ ['name' => 'title', 'type' => 'string', 'mode' => 'nullable'],
+ ['name' => 'description', 'type' => 'string', 'mode' => 'nullable']
+ ]
+ ];
+
+ $source = __DIR__ . '/../test/data/test_data_extra_column.csv';
+
+ // Set job configs
+ $loadConfig = $table->load(fopen($source, 'r'));
+ $loadConfig->destinationTable($table);
+ $loadConfig->schema($schema);
+ $loadConfig->schemaUpdateOptions(['ALLOW_FIELD_ADDITION']);
+ $loadConfig->sourceFormat('CSV');
+ $loadConfig->writeDisposition('WRITE_APPEND');
+
+ // Run the job with load config
+ $job = $bigQuery->runJob($loadConfig);
+
+ // Print all the columns
+ $columns = $table->info()['schema']['fields'];
+ printf('The columns in the table are ');
+ foreach ($columns as $column) {
+ printf('%s ', $column['name']);
+ }
+}
+# [END bigquery_add_column_load_append]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/add_column_query_append.php b/bigquery/api/src/add_column_query_append.php
new file mode 100644
index 0000000000..6eeeb7cf51
--- /dev/null
+++ b/bigquery/api/src/add_column_query_append.php
@@ -0,0 +1,71 @@
+ $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
+
+ // In this example, the existing table contains only the 'Name' and 'Title'.
+ // A new column 'Description' gets added after the query job.
+
+ // Define query
+ $query = sprintf('SELECT "John" as name, "Unknown" as title, "Dummy person" as description;');
+
+ // Set job configs
+ $queryJobConfig = $bigQuery->query($query);
+ $queryJobConfig->destinationTable($table);
+ $queryJobConfig->schemaUpdateOptions(['ALLOW_FIELD_ADDITION']);
+ $queryJobConfig->writeDisposition('WRITE_APPEND');
+
+ // Run query with query job configuration
+ $bigQuery->runQuery($queryJobConfig);
+
+ // Print all the columns
+ $columns = $table->info()['schema']['fields'];
+ printf('The columns in the table are ');
+ foreach ($columns as $column) {
+ printf('%s ', $column['name']);
+ }
+}
+# [END bigquery_add_column_query_append]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/bigquery_client.php b/bigquery/api/src/bigquery_client.php
index 9d63dec148..e616a1aa49 100644
--- a/bigquery/api/src/bigquery_client.php
+++ b/bigquery/api/src/bigquery_client.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
if (isset($argv)) {
diff --git a/bigquery/api/src/browse_table.php b/bigquery/api/src/browse_table.php
index 1b9ae3a03a..5ed5d1f014 100644
--- a/bigquery/api/src/browse_table.php
+++ b/bigquery/api/src/browse_table.php
@@ -18,45 +18,49 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 4 || count($argv) > 5) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID [START_INDEX]\n", __FILE__);
-}
-list($_, $projectId, $datasetId, $tableId) = $argv;
-$startIndex = isset($argv[4]) ? $argv[4] : 0;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_browse_table]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'The BigQuery table ID';
-// $startIndex = 0;
-
-$maxResults = 10;
+/**
+ * Browses the given table for data
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ * @param int $startIndex Zero-based index of the starting row.
+ */
+function browse_table(
+ string $projectId,
+ string $datasetId,
+ string $tableId,
+ int $startIndex = 0
+): void {
+ // Query options
+ $maxResults = 10;
+ $options = [
+ 'maxResults' => $maxResults,
+ 'startIndex' => $startIndex
+ ];
-$options = [
- 'maxResults' => $maxResults,
- 'startIndex' => $startIndex
-];
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
-$numRows = 0;
-foreach ($table->rows($options) as $row) {
- print('---');
- foreach ($row as $column => $value) {
- printf('%s: %s' . PHP_EOL, $column, $value);
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
+ $numRows = 0;
+ foreach ($table->rows($options) as $row) {
+ print('---');
+ foreach ($row as $column => $value) {
+ printf('%s: %s' . PHP_EOL, $column, $value);
+ }
+ $numRows++;
}
- $numRows++;
}
# [END bigquery_browse_table]
-return $numRows;
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/copy_table.php b/bigquery/api/src/copy_table.php
index 6157633f4e..e29a71b60c 100644
--- a/bigquery/api/src/copy_table.php
+++ b/bigquery/api/src/copy_table.php
@@ -18,50 +18,50 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 5) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID SOURCE_TABLE_ID DESTINATION_TABLE_ID\n", __FILE__);
-}
-list($_, $projectId, $datasetId, $sourceTableId, $destinationTableId) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_copy_table]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $sourceTableId = 'The BigQuery table ID to copy from';
-// $destinationTableId = 'The BigQuery table ID to copy to';
-
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$sourceTable = $dataset->table($sourceTableId);
-$destinationTable = $dataset->table($destinationTableId);
-$copyConfig = $sourceTable->copy($destinationTable);
-$job = $sourceTable->runJob($copyConfig);
+/**
+ * Copy the contents of table from source table to destination table.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $sourceTableId Source tableId in dataset.
+ * @param string $destinationTableId Destination tableId in dataset.
+ */
+function copy_table(
+ string $projectId,
+ string $datasetId,
+ string $sourceTableId,
+ string $destinationTableId
+): void {
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $sourceTable = $dataset->table($sourceTableId);
+ $destinationTable = $dataset->table($destinationTableId);
+ $copyConfig = $sourceTable->copy($destinationTable);
+ $job = $sourceTable->runJob($copyConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Table copied successfully' . PHP_EOL);
}
-});
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Table copied successfully' . PHP_EOL);
}
# [END bigquery_copy_table]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/create_dataset.php b/bigquery/api/src/create_dataset.php
index 46f07eeb59..e0c727feb0 100644
--- a/bigquery/api/src/create_dataset.php
+++ b/bigquery/api/src/create_dataset.php
@@ -18,28 +18,28 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 3) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID\n", __FILE__);
-}
-list($_, $projectId, $datasetId) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_create_dataset]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->createDataset($datasetId);
-printf('Created dataset %s' . PHP_EOL, $datasetId);
+/**
+ * Creates a dataset with the given dataset ID.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ */
+function create_dataset(string $projectId, string $datasetId): void
+{
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->createDataset($datasetId);
+ printf('Created dataset %s' . PHP_EOL, $datasetId);
+}
# [END bigquery_create_dataset]
-return $dataset;
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/create_table.php b/bigquery/api/src/create_table.php
index 0c8e69e672..9da5afa8b8 100644
--- a/bigquery/api/src/create_table.php
+++ b/bigquery/api/src/create_table.php
@@ -18,43 +18,49 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 4 || count($argv) > 5) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID [FIELDS]\n", __FILE__);
-}
-list($_, $projectId, $datasetId, $tableId) = $argv;
-$fields = isset($argv[4]) ? json_decode($argv[4]) : [['name' => 'field1', 'type' => 'string']];
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_create_table]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'The BigQuery table ID';
-// $fields = [
-// [
-// 'name' => 'field1',
-// 'type' => 'string',
-// 'mode' => 'required'
-// ],
-// [
-// 'name' => 'field2',
-// 'type' => 'integer'
-// ],
-//];
+/**
+ * Creates a table with the given ID and Schema
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ * @param string $fields Json Encoded string of schema of the table. For eg,
+ * $fields = json_encode([
+ * [
+ * 'name' => 'field1',
+ * 'type' => 'string',
+ * 'mode' => 'required'
+ * ],
+ * [
+ * 'name' => 'field2',
+ * 'type' => 'integer'
+ * ],
+ * ]);
+ */
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$schema = ['fields' => $fields];
-$table = $dataset->createTable($tableId, ['schema' => $schema]);
-printf('Created table %s' . PHP_EOL, $tableId);
+function create_table(
+ string $projectId,
+ string $datasetId,
+ string $tableId,
+ string $fields
+): void {
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $fields = json_decode($fields);
+ $schema = ['fields' => $fields];
+ $table = $dataset->createTable($tableId, ['schema' => $schema]);
+ printf('Created table %s' . PHP_EOL, $tableId);
+}
# [END bigquery_create_table]
-return $table;
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/delete_dataset.php b/bigquery/api/src/delete_dataset.php
index 54fb0e1e99..91a572db8b 100644
--- a/bigquery/api/src/delete_dataset.php
+++ b/bigquery/api/src/delete_dataset.php
@@ -18,28 +18,29 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) > 3) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID\n", __FILE__);
-}
-list($_, $projectId, $datasetId) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_delete_dataset]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->delete();
-printf('Deleted dataset %s' . PHP_EOL, $datasetId);
+/**
+ * Deletes the given dataset
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ */
+function delete_dataset(string $projectId, string $datasetId): void
+{
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->delete();
+ printf('Deleted dataset %s' . PHP_EOL, $datasetId);
+}
# [END bigquery_delete_dataset]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/delete_table.php b/bigquery/api/src/delete_table.php
index f3ab2ac773..b552c9c7f3 100644
--- a/bigquery/api/src/delete_table.php
+++ b/bigquery/api/src/delete_table.php
@@ -18,30 +18,31 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID\n", __FILE__);
-}
-list($_, $projectId, $datasetId, $tableId) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_delete_table]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'The BigQuery table ID';
-
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
-$table->delete();
-printf('Deleted table %s.%s' . PHP_EOL, $datasetId, $tableId);
+/**
+ * Deletes the given table
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function delete_table(string $projectId, string $datasetId, string $tableId): void
+{
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
+ $table->delete();
+ printf('Deleted table %s.%s' . PHP_EOL, $datasetId, $tableId);
+}
# [END bigquery_delete_table]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/dry_run_query.php b/bigquery/api/src/dry_run_query.php
index 5b98237dab..fe681b2ef5 100644
--- a/bigquery/api/src/dry_run_query.php
+++ b/bigquery/api/src/dry_run_query.php
@@ -18,37 +18,38 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 3) {
- return printf("Usage: php %s PROJECT_ID SQL_QUERY\n", __FILE__);
-}
-list($_, $projectId, $query) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_query_dry_run]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $query = 'SELECT id, view_count FROM `bigquery-public-data.stackoverflow.posts_questions`';
-
-// Construct a BigQuery client object.
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-
-// Set job configs
-$jobConfig = $bigQuery->query($query);
-$jobConfig->useQueryCache(false);
-$jobConfig->dryRun(true);
-
-// Extract query results
-$queryJob = $bigQuery->startJob($jobConfig);
-$info = $queryJob->info();
-
-printf('This query will process %s bytes' . PHP_EOL, $info['statistics']['totalBytesProcessed']);
+/**
+ * Dry runs the given query
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $query The query to be run. For eg: $query = 'SELECT id, view_count FROM `bigquery-public-data.stackoverflow.posts_questions`'
+ */
+function dry_run_query(string $projectId, string $query): void
+{
+ // Construct a BigQuery client object.
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+
+ // Set job configs
+ $jobConfig = $bigQuery->query($query);
+ $jobConfig->useQueryCache(false);
+ $jobConfig->dryRun(true);
+
+ // Extract query results
+ $queryJob = $bigQuery->startJob($jobConfig);
+ $info = $queryJob->info();
+
+ printf('This query will process %s bytes' . PHP_EOL, $info['statistics']['totalBytesProcessed']);
+}
# [END bigquery_query_dry_run]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/extract_table.php b/bigquery/api/src/extract_table.php
index 92ecca763b..2feec0f967 100644
--- a/bigquery/api/src/extract_table.php
+++ b/bigquery/api/src/extract_table.php
@@ -18,38 +18,42 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 5) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID BUCKET_NAME\n", __FILE__);
-}
-
-list($_, $projectId, $datasetId, $tableId, $bucketName) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_extract_table]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'The BigQuery table ID';
-// $bucketName = 'The Cloud Storage bucket Name';
-
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
-$destinationUri = "gs://{$bucketName}/{$tableId}.json";
-// Define the format to use. If the format is not specified, 'CSV' will be used.
-$format = 'NEWLINE_DELIMITED_JSON';
-// Create the extract job
-$extractConfig = $table->extract($destinationUri)->destinationFormat($format);
-// Run the job
-$job = $table->runJob($extractConfig); // Waits for the job to complete
-printf('Exported %s to %s' . PHP_EOL, $table->id(), $destinationUri);
+/**
+ * Extracts the given table as json to given GCS bucket.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ * @param string $bucketName Bucket name in Google Cloud Storage
+ */
+function extract_table(
+ string $projectId,
+ string $datasetId,
+ string $tableId,
+ string $bucketName
+): void {
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
+ $destinationUri = "gs://{$bucketName}/{$tableId}.json";
+ // Define the format to use. If the format is not specified, 'CSV' will be used.
+ $format = 'NEWLINE_DELIMITED_JSON';
+ // Create the extract job
+ $extractConfig = $table->extract($destinationUri)->destinationFormat($format);
+ // Run the job
+ $job = $table->runJob($extractConfig); // Waits for the job to complete
+ printf('Exported %s to %s' . PHP_EOL, $table->id(), $destinationUri);
+}
# [END bigquery_extract_table]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/get_table.php b/bigquery/api/src/get_table.php
index e648ad0f4f..e836d2647c 100644
--- a/bigquery/api/src/get_table.php
+++ b/bigquery/api/src/get_table.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
if (isset($argv)) {
diff --git a/bigquery/api/src/import_from_local_csv.php b/bigquery/api/src/import_from_local_csv.php
index d12e117652..c7a5ed0623 100644
--- a/bigquery/api/src/import_from_local_csv.php
+++ b/bigquery/api/src/import_from_local_csv.php
@@ -18,52 +18,52 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 5) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID SOURCE\n", __FILE__);
-}
-
-list($_, $projectId, $datasetId, $tableId, $source) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_load_from_file]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'The BigQuery table ID';
-// $source = 'The path to the CSV source file to import';
+/**
+ * Imports data to the given table from given csv
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ * @param string $source The path to the CSV source file to import.
+ */
+function import_from_local_csv(
+ string $projectId,
+ string $datasetId,
+ string $tableId,
+ string $source
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
+ // create the import job
+ $loadConfig = $table->load(fopen($source, 'r'))->sourceFormat('CSV');
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
-// create the import job
-$loadConfig = $table->load(fopen($source, 'r'))->sourceFormat('CSV');
+ $job = $table->runJob($loadConfig);
-$job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- printf('Waiting for job to complete' . PHP_EOL);
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
}
-});
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_from_file]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/import_from_storage_csv.php b/bigquery/api/src/import_from_storage_csv.php
index b57bfb34b2..1f6341e23f 100644
--- a/bigquery/api/src/import_from_storage_csv.php
+++ b/bigquery/api/src/import_from_storage_csv.php
@@ -18,57 +18,57 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-if (count($argv) < 3 || count($argv) > 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID [TABLE_ID]\n", __FILE__);
-}
+namespace Google\Cloud\Samples\BigQuery;
-list($_, $projectId, $datasetId) = $argv;
-$tableId = isset($argv[3]) ? $argv[3] : 'us_states';
# [START bigquery_load_table_gcs_csv]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'us_states';
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
+/**
+ * Import data from storage csv.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function import_from_storage_csv(
+ string $projectId,
+ string $datasetId,
+ string $tableId = 'us_states'
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
-// create the import job
-$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.csv';
-$schema = [
- 'fields' => [
+ // create the import job
+ $gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.csv';
+ $schema = [
+ 'fields' => [
['name' => 'name', 'type' => 'string'],
['name' => 'post_abbr', 'type' => 'string']
- ]
-];
-$loadConfig = $table->loadFromStorage($gcsUri)->schema($schema)->skipLeadingRows(1);
-$job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ ]
+ ];
+ $loadConfig = $table->loadFromStorage($gcsUri)->schema($schema)->skipLeadingRows(1);
+ $job = $table->runJob($loadConfig);
+
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
}
-});
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_csv]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/import_from_storage_csv_autodetect.php b/bigquery/api/src/import_from_storage_csv_autodetect.php
index b189bfb677..6c6a16c4b5 100644
--- a/bigquery/api/src/import_from_storage_csv_autodetect.php
+++ b/bigquery/api/src/import_from_storage_csv_autodetect.php
@@ -18,51 +18,52 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-if (count($argv) < 3 || count($argv) > 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID [TABLE_ID]\n", __FILE__);
-}
+namespace Google\Cloud\Samples\BigQuery;
-list($_, $projectId, $datasetId) = $argv;
-$tableId = isset($argv[3]) ? $argv[3] : 'us_states';
# [START bigquery_load_table_gcs_csv_autodetect]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'us_states';
+/**
+ * Imports data to the given table from csv file present in GCS by auto
+ * detecting options and schema.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function import_from_storage_csv_autodetect(
+ string $projectId,
+ string $datasetId,
+ string $tableId = 'us_states'
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
+ // create the import job
+ $gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.csv';
+ $loadConfig = $table->loadFromStorage($gcsUri)->autodetect(true)->skipLeadingRows(1);
+ $job = $table->runJob($loadConfig);
-// create the import job
-$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.csv';
-$loadConfig = $table->loadFromStorage($gcsUri)->autodetect(true)->skipLeadingRows(1);
-$job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
}
-});
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_csv_autodetect]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/import_from_storage_csv_truncate.php b/bigquery/api/src/import_from_storage_csv_truncate.php
index 35b8498756..cd842d1c71 100644
--- a/bigquery/api/src/import_from_storage_csv_truncate.php
+++ b/bigquery/api/src/import_from_storage_csv_truncate.php
@@ -18,51 +18,50 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-if (count($argv) != 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID\n", __FILE__);
-}
+namespace Google\Cloud\Samples\BigQuery;
-list($_, $projectId, $datasetId, $tableId) = $argv;
# [START bigquery_load_table_gcs_csv_truncate]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'The BigQuery table ID';
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$table = $bigQuery->dataset($datasetId)->table($tableId);
+/**
+ * Import data from storage csv with write truncate option.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function import_from_storage_csv_truncate(
+ string $projectId,
+ string $datasetId,
+ string $tableId = 'us_states'
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $table = $bigQuery->dataset($datasetId)->table($tableId);
-// create the import job
-$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.csv';
-$loadConfig = $table->loadFromStorage($gcsUri)->skipLeadingRows(1)->writeDisposition('WRITE_TRUNCATE');
-$job = $table->runJob($loadConfig);
+ // create the import job
+ $gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.csv';
+ $loadConfig = $table->loadFromStorage($gcsUri)->skipLeadingRows(1)->writeDisposition('WRITE_TRUNCATE');
+ $job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
}
-});
-
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_csv_truncate]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/import_from_storage_json.php b/bigquery/api/src/import_from_storage_json.php
index 94a4c3e221..709ad13597 100644
--- a/bigquery/api/src/import_from_storage_json.php
+++ b/bigquery/api/src/import_from_storage_json.php
@@ -18,57 +18,57 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-if (count($argv) < 3 || count($argv) > 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID [TABLE_ID]\n", __FILE__);
-}
+namespace Google\Cloud\Samples\BigQuery;
-list($_, $projectId, $datasetId) = $argv;
-$tableId = isset($argv[3]) ? $argv[3] : 'us_states';
# [START bigquery_load_table_gcs_json]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'us_states';
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
+/**
+ * Import data from storage json.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function import_from_storage_json(
+ string $projectId,
+ string $datasetId,
+ string $tableId = 'us_states'
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
-// create the import job
-$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.json';
-$schema = [
- 'fields' => [
+ // create the import job
+ $gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.json';
+ $schema = [
+ 'fields' => [
['name' => 'name', 'type' => 'string'],
['name' => 'post_abbr', 'type' => 'string']
- ]
-];
-$loadConfig = $table->loadFromStorage($gcsUri)->schema($schema)->sourceFormat('NEWLINE_DELIMITED_JSON');
-$job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ ]
+ ];
+ $loadConfig = $table->loadFromStorage($gcsUri)->schema($schema)->sourceFormat('NEWLINE_DELIMITED_JSON');
+ $job = $table->runJob($loadConfig);
+
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
}
-});
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_json]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/import_from_storage_json_autodetect.php b/bigquery/api/src/import_from_storage_json_autodetect.php
index a6cad520e2..61d243ee41 100644
--- a/bigquery/api/src/import_from_storage_json_autodetect.php
+++ b/bigquery/api/src/import_from_storage_json_autodetect.php
@@ -18,51 +18,52 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-if (count($argv) < 3 || count($argv) > 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID [TABLE_ID]\n", __FILE__);
-}
+namespace Google\Cloud\Samples\BigQuery;
-list($_, $projectId, $datasetId) = $argv;
-$tableId = isset($argv[3]) ? $argv[3] : 'us_states';
# [START bigquery_load_table_gcs_json_autodetect]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'us_states';
+/**
+ * Imports data to the given table from json file present in GCS by auto
+ * detecting options and schema.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function import_from_storage_json_autodetect(
+ string $projectId,
+ string $datasetId,
+ string $tableId = 'us_states'
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
+ // create the import job
+ $gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.json';
+ $loadConfig = $table->loadFromStorage($gcsUri)->autodetect(true)->sourceFormat('NEWLINE_DELIMITED_JSON');
+ $job = $table->runJob($loadConfig);
-// create the import job
-$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.json';
-$loadConfig = $table->loadFromStorage($gcsUri)->autodetect(true)->sourceFormat('NEWLINE_DELIMITED_JSON');
-$job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
}
-});
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_json_autodetect]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/import_from_storage_json_truncate.php b/bigquery/api/src/import_from_storage_json_truncate.php
index 6c9ed684e0..9d1aa825c8 100644
--- a/bigquery/api/src/import_from_storage_json_truncate.php
+++ b/bigquery/api/src/import_from_storage_json_truncate.php
@@ -18,51 +18,50 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-if (count($argv) != 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID\n", __FILE__);
-}
+namespace Google\Cloud\Samples\BigQuery;
-list($_, $projectId, $datasetId, $tableId) = $argv;
# [START bigquery_load_table_gcs_json_truncate]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableID = 'The BigQuery table ID';
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$table = $bigQuery->dataset($datasetId)->table($tableId);
+/**
+ * Import data from storage json with write truncate option.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function import_from_storage_json_truncate(
+ string $projectId,
+ string $datasetId,
+ string $tableId = 'us_states'
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $table = $bigQuery->dataset($datasetId)->table($tableId);
-// create the import job
-$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.json';
-$loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('NEWLINE_DELIMITED_JSON')->writeDisposition('WRITE_TRUNCATE');
-$job = $table->runJob($loadConfig);
+ // create the import job
+ $gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.json';
+ $loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('NEWLINE_DELIMITED_JSON')->writeDisposition('WRITE_TRUNCATE');
+ $job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
}
-});
-
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_json_truncate]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/import_from_storage_orc.php b/bigquery/api/src/import_from_storage_orc.php
index 5d93fce8cb..0bb242d25d 100644
--- a/bigquery/api/src/import_from_storage_orc.php
+++ b/bigquery/api/src/import_from_storage_orc.php
@@ -18,51 +18,51 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-if (count($argv) < 3 || count($argv) > 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID [TABLE_ID]\n", __FILE__);
-}
+namespace Google\Cloud\Samples\BigQuery;
-list($_, $projectId, $datasetId) = $argv;
-$tableId = isset($argv[3]) ? $argv[3] : 'us_states';
# [START bigquery_load_table_gcs_orc]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'us_states';
+/**
+ * Import data from storage orc.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function import_from_storage_orc(
+ string $projectId,
+ string $datasetId,
+ string $tableId = 'us_states'
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
+ // create the import job
+ $gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.orc';
+ $loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('ORC');
+ $job = $table->runJob($loadConfig);
-// create the import job
-$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.orc';
-$loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('ORC');
-$job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
}
-});
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_orc]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/import_from_storage_orc_truncate.php b/bigquery/api/src/import_from_storage_orc_truncate.php
index 839839eefd..3cd75760eb 100644
--- a/bigquery/api/src/import_from_storage_orc_truncate.php
+++ b/bigquery/api/src/import_from_storage_orc_truncate.php
@@ -18,51 +18,51 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-if (count($argv) != 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID\n", __FILE__);
-}
+namespace Google\Cloud\Samples\BigQuery;
-list($_, $projectId, $datasetId, $tableId) = $argv;
# [START bigquery_load_table_gcs_orc_truncate]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableID = 'The BigQuery table ID';
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$table = $bigQuery->dataset($datasetId)->table($tableId);
+/**
+ * Import data from storage orc with write truncate option.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function import_from_storage_orc_truncate(
+ string $projectId,
+ string $datasetId,
+ string $tableId = 'us_states'
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $table = $bigQuery->dataset($datasetId)->table($tableId);
-// create the import job
-$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.orc';
-$loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('ORC')->writeDisposition('WRITE_TRUNCATE');
-$job = $table->runJob($loadConfig);
+ // create the import job
+ $gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.orc';
+ $loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('ORC')->writeDisposition('WRITE_TRUNCATE');
+ $job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
}
-});
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
+ }
}
# [END bigquery_load_table_gcs_orc_truncate]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/import_from_storage_parquet.php b/bigquery/api/src/import_from_storage_parquet.php
index d7ac9cef82..bcbb488988 100644
--- a/bigquery/api/src/import_from_storage_parquet.php
+++ b/bigquery/api/src/import_from_storage_parquet.php
@@ -18,51 +18,51 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-if (count($argv) < 3 || count($argv) > 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID [TABLE_ID]\n", __FILE__);
-}
+namespace Google\Cloud\Samples\BigQuery;
-list($_, $projectId, $datasetId) = $argv;
-$tableId = isset($argv[3]) ? $argv[3] : 'us_states';
# [START bigquery_load_table_gcs_parquet]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'us_states';
+/**
+ * Import data from storage parquet.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function import_from_storage_parquet(
+ string $projectId,
+ string $datasetId,
+ string $tableId = 'us_states'
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
+ // create the import job
+ $gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.parquet';
+ $loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('PARQUET');
+ $job = $table->runJob($loadConfig);
-// create the import job
-$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.parquet';
-$loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('PARQUET');
-$job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
}
-});
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_parquet]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/import_from_storage_parquet_truncate.php b/bigquery/api/src/import_from_storage_parquet_truncate.php
index 89ed4c1138..0fb10d2212 100644
--- a/bigquery/api/src/import_from_storage_parquet_truncate.php
+++ b/bigquery/api/src/import_from_storage_parquet_truncate.php
@@ -18,51 +18,50 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-if (count($argv) != 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID\n", __FILE__);
-}
+namespace Google\Cloud\Samples\BigQuery;
-list($_, $projectId, $datasetId, $tableId) = $argv;
# [START bigquery_load_table_gcs_parquet_truncate]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableID = 'The BigQuery table ID';
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$table = $bigQuery->dataset($datasetId)->table($tableId);
+/**
+ * Import data from storage parquet with write truncate option.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ */
+function import_from_storage_parquet_truncate(
+ string $projectId,
+ string $datasetId,
+ string $tableId
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $table = $bigQuery->dataset($datasetId)->table($tableId);
-// create the import job
-$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.parquet';
-$loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('PARQUET')->writeDisposition('WRITE_TRUNCATE');
-$job = $table->runJob($loadConfig);
+ // create the import job
+ $gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.parquet';
+ $loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('PARQUET')->writeDisposition('WRITE_TRUNCATE');
+ $job = $table->runJob($loadConfig);
-// poll the job until it is complete
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
+ }
+ // check if the job has errors
+ if (isset($job->info()['status']['errorResult'])) {
+ $error = $job->info()['status']['errorResult']['message'];
+ printf('Error running job: %s' . PHP_EOL, $error);
+ } else {
+ print('Data imported successfully' . PHP_EOL);
}
-});
-
-// check if the job has errors
-if (isset($job->info()['status']['errorResult'])) {
- $error = $job->info()['status']['errorResult']['message'];
- printf('Error running job: %s' . PHP_EOL, $error);
-} else {
- print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_parquet_truncate]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/insert_sql.php b/bigquery/api/src/insert_sql.php
index b9501a8e42..76c0bdbc47 100644
--- a/bigquery/api/src/insert_sql.php
+++ b/bigquery/api/src/insert_sql.php
@@ -18,37 +18,40 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 4) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID SOURCE\n", __FILE__);
-}
-
-list($_, $projectId, $datasetId, $source) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $source = 'The path to the source file to import';
-
-// instantiate the bigquery client
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-// run a sync query for each line of the import
-$file = fopen($source, 'r');
-while ($line = fgets($file)) {
- if (0 !== strpos(trim($line), 'INSERT')) {
- continue;
+/**
+ * Import data using INSERT sql statements from a file
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $source The path to the source file to import.
+ */
+function insert_sql(
+ string $projectId,
+ string $datasetId,
+ string $source
+): void {
+ // instantiate the bigquery client
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ // run a sync query for each line of the import
+ $file = fopen($source, 'r');
+ while ($line = fgets($file)) {
+ if (0 !== strpos(trim($line), 'INSERT')) {
+ continue;
+ }
+ $queryConfig = $bigQuery->query($line)->defaultDataset($dataset);
+ $bigQuery->runQuery($queryConfig);
}
- $queryConfig = $bigQuery->query($line)->defaultDataset($dataset);
- $bigQuery->runQuery($queryConfig);
+ print('Data imported successfully' . PHP_EOL);
}
-print('Data imported successfully' . PHP_EOL);
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/list_datasets.php b/bigquery/api/src/list_datasets.php
index 6063226d27..f897d2d61d 100644
--- a/bigquery/api/src/list_datasets.php
+++ b/bigquery/api/src/list_datasets.php
@@ -18,29 +18,29 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return printf("Usage: php %s PROJECT_ID\n", __FILE__);
-}
-
-list($_, $projectId) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_list_datasets]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$datasets = $bigQuery->datasets();
-foreach ($datasets as $dataset) {
- print($dataset->id() . PHP_EOL);
+/**
+ * List all datasets in the given project
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ */
+function list_datasets(string $projectId): void
+{
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $datasets = $bigQuery->datasets();
+ foreach ($datasets as $dataset) {
+ print($dataset->id() . PHP_EOL);
+ }
}
# [END bigquery_list_datasets]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/list_tables.php b/bigquery/api/src/list_tables.php
index 695356d285..40c56bf3b8 100644
--- a/bigquery/api/src/list_tables.php
+++ b/bigquery/api/src/list_tables.php
@@ -18,31 +18,31 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 3) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID\n", __FILE__);
-}
-
-list($_, $projectId, $datasetId) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_list_tables]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$tables = $dataset->tables();
-foreach ($tables as $table) {
- print($table->id() . PHP_EOL);
+/**
+ * List all the tables in the given dataset.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ */
+function list_tables(string $projectId, string $datasetId): void
+{
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $tables = $dataset->tables();
+ foreach ($tables as $table) {
+ print($table->id() . PHP_EOL);
+ }
}
# [END bigquery_list_tables]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/query_legacy.php b/bigquery/api/src/query_legacy.php
index cc65375ffa..c82e6a2766 100644
--- a/bigquery/api/src/query_legacy.php
+++ b/bigquery/api/src/query_legacy.php
@@ -18,35 +18,39 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return printf("Usage: php %s PROJECT_ID\n", __FILE__);
-}
-list($_, $projectId) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
// [START bigquery_query_legacy]
use Google\Cloud\BigQuery\BigQueryClient;
-$query = 'SELECT corpus FROM [bigquery-public-data:samples.shakespeare] GROUP BY corpus';
-
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$jobConfig = $bigQuery->query($query)->useLegacySql(true);
-
-$queryResults = $bigQuery->runQuery($jobConfig);
-
-$i = 0;
-foreach ($queryResults as $row) {
- printf('--- Row %s ---' . PHP_EOL, ++$i);
- foreach ($row as $column => $value) {
- printf('%s: %s' . PHP_EOL, $column, json_encode($value));
+/**
+ * Query using legacy sql
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ */
+function query_legacy(string $projectId): void
+{
+ $query = 'SELECT corpus FROM [bigquery-public-data:samples.shakespeare] GROUP BY corpus';
+
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $jobConfig = $bigQuery->query($query)->useLegacySql(true);
+
+ $queryResults = $bigQuery->runQuery($jobConfig);
+
+ $i = 0;
+ foreach ($queryResults as $row) {
+ printf('--- Row %s ---' . PHP_EOL, ++$i);
+ foreach ($row as $column => $value) {
+ printf('%s: %s' . PHP_EOL, $column, json_encode($value));
+ }
}
+ printf('Found %s row(s)' . PHP_EOL, $i);
}
-printf('Found %s row(s)' . PHP_EOL, $i);
// [END bigquery_query_legacy]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/query_no_cache.php b/bigquery/api/src/query_no_cache.php
index 16569f838f..a5a8d6eb99 100644
--- a/bigquery/api/src/query_no_cache.php
+++ b/bigquery/api/src/query_no_cache.php
@@ -18,42 +18,44 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 3) {
- return printf("Usage: php %s PROJECT_ID SQL_QUERY\n", __FILE__);
-}
-list($_, $projectId, $query) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_query_no_cache]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $query = 'SELECT id, view_count FROM `bigquery-public-data.stackoverflow.posts_questions`';
-
-// Construct a BigQuery client object.
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-
-// Set job configs
-$jobConfig = $bigQuery->query($query);
-$jobConfig->useQueryCache(false);
-
-// Extract query results
-$queryResults = $bigQuery->runQuery($jobConfig);
-
-$i = 0;
-foreach ($queryResults as $row) {
- printf('--- Row %s ---' . PHP_EOL, ++$i);
- foreach ($row as $column => $value) {
- printf('%s: %s' . PHP_EOL, $column, json_encode($value));
+/**
+ * Query with query catch option enabled.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $query Eg: 'SELECT id, view_count FROM
+ * `bigquery-public-data.stackoverflow.posts_questions`';
+ */
+function query_no_cache(string $projectId, string $query): void
+{
+ // Construct a BigQuery client object.
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+
+ // Set job configs
+ $jobConfig = $bigQuery->query($query);
+ $jobConfig->useQueryCache(false);
+
+ // Extract query results
+ $queryResults = $bigQuery->runQuery($jobConfig);
+
+ $i = 0;
+ foreach ($queryResults as $row) {
+ printf('--- Row %s ---' . PHP_EOL, ++$i);
+ foreach ($row as $column => $value) {
+ printf('%s: %s' . PHP_EOL, $column, json_encode($value));
+ }
}
+ printf('Found %s row(s)' . PHP_EOL, $i);
}
-printf('Found %s row(s)' . PHP_EOL, $i);
# [END bigquery_query_no_cache]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/run_query.php b/bigquery/api/src/run_query.php
index 6ac4d9a04d..1c45f6301a 100644
--- a/bigquery/api/src/run_query.php
+++ b/bigquery/api/src/run_query.php
@@ -18,34 +18,36 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 3) {
- return printf("Usage: php %s PROJECT_ID SQL_QUERY\n", __FILE__);
-}
-list($_, $projectId, $query) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $query = 'SELECT id, view_count FROM `bigquery-public-data.stackoverflow.posts_questions`';
-
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$jobConfig = $bigQuery->query($query);
-$queryResults = $bigQuery->runQuery($jobConfig);
+/**
+ * Run query.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $query Eg: 'SELECT id, view_count FROM
+ * `bigquery-public-data.stackoverflow.posts_questions`';
+ */
+function run_query(string $projectId, string $query): void
+{
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $jobConfig = $bigQuery->query($query);
+ $queryResults = $bigQuery->runQuery($jobConfig);
-$i = 0;
-foreach ($queryResults as $row) {
- printf('--- Row %s ---' . PHP_EOL, ++$i);
- foreach ($row as $column => $value) {
- printf('%s: %s' . PHP_EOL, $column, json_encode($value));
+ $i = 0;
+ foreach ($queryResults as $row) {
+ printf('--- Row %s ---' . PHP_EOL, ++$i);
+ foreach ($row as $column => $value) {
+ printf('%s: %s' . PHP_EOL, $column, json_encode($value));
+ }
}
+ printf('Found %s row(s)' . PHP_EOL, $i);
}
-printf('Found %s row(s)' . PHP_EOL, $i);
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/run_query_as_job.php b/bigquery/api/src/run_query_as_job.php
index c803e20073..1daad75b2c 100644
--- a/bigquery/api/src/run_query_as_job.php
+++ b/bigquery/api/src/run_query_as_job.php
@@ -18,47 +18,45 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 3) {
- return printf("Usage: php %s PROJECT_ID SQL_QUERY\n", __FILE__);
-}
-list($_, $projectId, $query) = $argv;
+namespace Google\Cloud\Samples\BigQuery;
# [START bigquery_query]
use Google\Cloud\BigQuery\BigQueryClient;
-use Google\Cloud\Core\ExponentialBackoff;
-
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $query = 'SELECT id, view_count FROM `bigquery-public-data.stackoverflow.posts_questions`';
-
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$jobConfig = $bigQuery->query($query);
-$job = $bigQuery->startQuery($jobConfig);
-$backoff = new ExponentialBackoff(10);
-$backoff->execute(function () use ($job) {
- print('Waiting for job to complete' . PHP_EOL);
+/**
+ * Run query as job.
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $query Eg: 'SELECT id, view_count FROM
+ * `bigquery-public-data.stackoverflow.posts_questions`';
+ */
+function run_query_as_job(string $projectId, string $query): void
+{
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $jobConfig = $bigQuery->query($query);
+ $job = $bigQuery->startQuery($jobConfig);
+
+ // check if the job is complete
$job->reload();
if (!$job->isComplete()) {
- throw new Exception('Job has not yet completed', 500);
+ throw new \Exception('Job has not yet completed', 500);
}
-});
-$queryResults = $job->queryResults();
-
-$i = 0;
-foreach ($queryResults as $row) {
- printf('--- Row %s ---' . PHP_EOL, ++$i);
- foreach ($row as $column => $value) {
- printf('%s: %s' . PHP_EOL, $column, json_encode($value));
+ $queryResults = $job->queryResults();
+
+ $i = 0;
+ foreach ($queryResults as $row) {
+ printf('--- Row %s ---' . PHP_EOL, ++$i);
+ foreach ($row as $column => $value) {
+ printf('%s: %s' . PHP_EOL, $column, json_encode($value));
+ }
}
+ printf('Found %s row(s)' . PHP_EOL, $i);
}
-printf('Found %s row(s)' . PHP_EOL, $i);
# [END bigquery_query]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/stream_row.php b/bigquery/api/src/stream_row.php
index 96ca09ce39..fa320c9135 100644
--- a/bigquery/api/src/stream_row.php
+++ b/bigquery/api/src/stream_row.php
@@ -18,50 +18,54 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
namespace Google\Cloud\Samples\BigQuery;
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 4 || count($argv) > 5) {
- return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID [DATA]\n", __FILE__);
-}
-list($_, $projectId, $datasetId, $tableId) = $argv;
-$data = isset($argv[4]) ? json_decode($argv[4], true) : ['field1' => 'value1'];
-
# [START bigquery_table_insert_rows]
use Google\Cloud\BigQuery\BigQueryClient;
-/** Uncomment and populate these variables in your code */
-// $projectId = 'The Google project ID';
-// $datasetId = 'The BigQuery dataset ID';
-// $tableId = 'The BigQuery table ID';
-// $data = [
-// "field1" => "value1",
-// "field2" => "value2",
-// ];
-
-// instantiate the bigquery table service
-$bigQuery = new BigQueryClient([
- 'projectId' => $projectId,
-]);
-$dataset = $bigQuery->dataset($datasetId);
-$table = $dataset->table($tableId);
+/**
+ * Stream data into bigquery
+ *
+ * @param string $projectId The project Id of your Google Cloud Project.
+ * @param string $datasetId The BigQuery dataset ID.
+ * @param string $tableId The BigQuery table ID.
+ * @param array $data Json encoded data For eg,
+ * $data = json_encode([
+ * "field1" => "value1",
+ * "field2" => "value2",
+ * ]);
+ */
+function stream_row(
+ string $projectId,
+ string $datasetId,
+ string $tableId,
+ string $data
+): void {
+ // instantiate the bigquery table service
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
-$insertResponse = $table->insertRows([
- ['data' => $data],
- // additional rows can go here
-]);
-if ($insertResponse->isSuccessful()) {
- print('Data streamed into BigQuery successfully' . PHP_EOL);
-} else {
- foreach ($insertResponse->failedRows() as $row) {
- foreach ($row['errors'] as $error) {
- printf('%s: %s' . PHP_EOL, $error['reason'], $error['message']);
+ $data = json_decode($data, true);
+ $insertResponse = $table->insertRows([
+ ['data' => $data],
+ // additional rows can go here
+ ]);
+ if ($insertResponse->isSuccessful()) {
+ print('Data streamed into BigQuery successfully' . PHP_EOL);
+ } else {
+ foreach ($insertResponse->failedRows() as $row) {
+ foreach ($row['errors'] as $error) {
+ printf('%s: %s' . PHP_EOL, $error['reason'], $error['message']);
+ }
}
}
}
# [END bigquery_table_insert_rows]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/src/table_insert_rows_explicit_none_insert_ids.php b/bigquery/api/src/table_insert_rows_explicit_none_insert_ids.php
new file mode 100644
index 0000000000..f541b804b2
--- /dev/null
+++ b/bigquery/api/src/table_insert_rows_explicit_none_insert_ids.php
@@ -0,0 +1,80 @@
+ "value1",
+ * "field2" => "value2"
+ * ]);
+ * $rowData2 = json_encode([
+ * "field1" => "value1",
+ * "field2" => "value2"
+ * ]);
+ */
+function table_insert_rows_explicit_none_insert_ids(
+ string $projectId,
+ string $datasetId,
+ string $tableId,
+ string $rowData1,
+ string $rowData2
+): void {
+ $bigQuery = new BigQueryClient([
+ 'projectId' => $projectId,
+ ]);
+ $dataset = $bigQuery->dataset($datasetId);
+ $table = $dataset->table($tableId);
+
+ $rowData1 = json_decode($rowData1, true);
+ $rowData2 = json_decode($rowData2, true);
+ // Omitting insert Id's in following rows.
+ $rows = [
+ ['data' => $rowData1],
+ ['data' => $rowData2]
+ ];
+ $insertResponse = $table->insertRows($rows);
+
+ if ($insertResponse->isSuccessful()) {
+ printf('Rows successfully inserted into table without insert ids' . PHP_EOL);
+ } else {
+ foreach ($insertResponse->failedRows() as $row) {
+ foreach ($row['errors'] as $error) {
+ printf('%s: %s' . PHP_EOL, $error['reason'], $error['message']);
+ }
+ }
+ }
+}
+# [END bigquery_table_insert_rows_explicit_none_insert_ids]
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/bigquery/api/test/bigqueryTest.php b/bigquery/api/test/bigqueryTest.php
index 8aed3397c9..d96258bc43 100644
--- a/bigquery/api/test/bigqueryTest.php
+++ b/bigquery/api/test/bigqueryTest.php
@@ -28,7 +28,9 @@
*/
class FunctionsTest extends TestCase
{
- use TestTrait;
+ use TestTrait {
+ TestTrait::runFunctionSnippet as traitRunFunctionSnippet;
+ }
use EventuallyConsistentTestTrait;
private static $datasetId;
@@ -47,7 +49,7 @@ public static function setUpBeforeClass(): void
public function testBigQueryClient()
{
$projectId = self::$projectId;
- $bigQuery = require __DIR__ . '/../src/bigquery_client.php';
+ $bigQuery = require_once __DIR__ . '/../src/bigquery_client.php';
$this->assertInstanceOf(
\Google\Cloud\BigQuery\BigQueryClient::class,
@@ -58,7 +60,7 @@ public function testBigQueryClient()
public function testBrowseTable()
{
$tableId = $this->createTempTable();
- $output = $this->runSnippet('browse_table', [
+ $output = $this->runFunctionSnippet('browse_table', [
self::$datasetId,
$tableId,
]);
@@ -71,7 +73,7 @@ public function testCopyTable()
$destinationTableId = sprintf('test_copy_table_%s', time());
// run the import
- $output = $this->runSnippet('copy_table', [
+ $output = $this->runFunctionSnippet('copy_table', [
self::$datasetId,
$sourceTableId,
$destinationTableId,
@@ -85,25 +87,30 @@ public function testCopyTable()
public function testCreateAndDeleteDataset()
{
$tempDatasetId = sprintf('test_dataset_%s', time());
- $output = $this->runSnippet('create_dataset', [$tempDatasetId]);
+ $output = $this->runFunctionSnippet('create_dataset', [$tempDatasetId]);
$this->assertStringContainsString('Created dataset', $output);
// delete the dataset
- $output = $this->runSnippet('delete_dataset', [$tempDatasetId]);
+ $output = $this->runFunctionSnippet('delete_dataset', [$tempDatasetId]);
$this->assertStringContainsString('Deleted dataset', $output);
}
public function testCreateAndDeleteTable()
{
$tempTableId = sprintf('test_table_%s', time());
- $output = $this->runSnippet('create_table', [
+ $fields = json_encode([
+ ['name' => 'name', 'type' => 'string', 'mode' => 'nullable'],
+ ['name' => 'title', 'type' => 'string', 'mode' => 'nullable']
+ ]);
+ $output = $this->runFunctionSnippet('create_table', [
self::$datasetId,
- $tempTableId
+ $tempTableId,
+ $fields
]);
$this->assertStringContainsString('Created table', $output);
// delete the table
- $output = $this->runSnippet('delete_table', [
+ $output = $this->runFunctionSnippet('delete_table', [
self::$datasetId,
$tempTableId
]);
@@ -116,7 +123,7 @@ public function testExtractTable()
$tableId = $this->createTempTable();
// run the import
- $output = $this->runSnippet('extract_table', [
+ $output = $this->runFunctionSnippet('extract_table', [
self::$datasetId,
$tableId,
$bucketName
@@ -140,7 +147,7 @@ public function testGetTable()
$projectId = self::$projectId;
$datasetId = self::$datasetId;
$tableId = $this->createTempEmptyTable();
- $table = require __DIR__ . '/../src/get_table.php';
+ $table = require_once __DIR__ . '/../src/get_table.php';
$this->assertInstanceOf(
\Google\Cloud\BigQuery\Table::class,
@@ -156,7 +163,7 @@ public function testImportFromFile()
$tempTableId = $this->createTempEmptyTable();
// run the import
- $output = $this->runSnippet('import_from_local_csv', [
+ $output = $this->runFunctionSnippet('import_from_local_csv', [
self::$datasetId,
$tempTableId,
$source,
@@ -175,7 +182,7 @@ public function testImportFromStorage($snippet, $runTruncateSnippet = false)
$tableId = sprintf('%s_%s', $snippet, rand());
// run the import
- $output = $this->runSnippet($snippet, [
+ $output = $this->runFunctionSnippet($snippet, [
self::$datasetId,
$tableId,
]);
@@ -188,7 +195,7 @@ public function testImportFromStorage($snippet, $runTruncateSnippet = false)
if ($runTruncateSnippet) {
$truncateSnippet = sprintf('%s_truncate', $snippet);
- $output = $this->runSnippet($truncateSnippet, [
+ $output = $this->runFunctionSnippet($truncateSnippet, [
self::$datasetId,
$tableId,
]);
@@ -224,7 +231,7 @@ public function testInsertSql()
);
// run the import
- $output = $this->runSnippet('insert_sql', [
+ $output = $this->runFunctionSnippet('insert_sql', [
self::$datasetId,
$tmpFile,
]);
@@ -236,26 +243,26 @@ public function testInsertSql()
public function testListDatasets()
{
- $output = $this->runSnippet('list_datasets');
+ $output = $this->runFunctionSnippet('list_datasets');
$this->assertStringContainsString(self::$datasetId, $output);
}
public function testListTables()
{
$tempTableId = $this->createTempEmptyTable();
- $output = $this->runSnippet('list_tables', [self::$datasetId]);
+ $output = $this->runFunctionSnippet('list_tables', [self::$datasetId]);
$this->assertStringContainsString($tempTableId, $output);
}
public function testStreamRow()
{
$tempTableId = $this->createTempEmptyTable();
-
+ $data = json_encode(['name' => 'Brent Shaffer', 'title' => 'Developer']);
// run the import
- $output = $this->runSnippet('stream_row', [
+ $output = $this->runFunctionSnippet('stream_row', [
self::$datasetId,
$tempTableId,
- json_encode(['name' => 'Brent Shaffer', 'title' => 'Developer'])
+ $data
]);
$tempTable = self::$dataset->table($tempTableId);
@@ -266,14 +273,34 @@ public function testStreamRow()
public function testRunQuery()
{
$query = 'SELECT corpus, COUNT(*) as unique_words
- FROM `publicdata.samples.shakespeare` GROUP BY corpus LIMIT 10';
+ FROM `publicdata.samples.shakespeare`
+ GROUP BY corpus
+ ORDER BY unique_words DESC
+ LIMIT 10';
- $output = $this->runSnippet('run_query', [$query]);
+ $output = $this->runFunctionSnippet('run_query', [$query]);
$this->assertStringContainsString('hamlet', $output);
$this->assertStringContainsString('kinglear', $output);
$this->assertStringContainsString('Found 10 row(s)', $output);
}
+ public function testTableInsertRowsExplicitNoneInsertIds()
+ {
+ $tempTableId = $this->createTempEmptyTable();
+
+ $output = $this->runFunctionSnippet('table_insert_rows_explicit_none_insert_ids', [
+ self::$datasetId,
+ $tempTableId,
+ json_encode(['name' => 'Yash Sahu', 'title' => 'Noogler dev']),
+ json_encode(['name' => 'Friday', 'title' => 'Are the best'])
+ ]);
+
+ $tempTable = self::$dataset->table($tempTableId);
+ $expectedOutput = sprintf('Rows successfully inserted into table without insert ids');
+ $this->assertStringContainsString($expectedOutput, $output);
+ $this->verifyTable($tempTable, 'Yash Sahu', 2);
+ }
+
public function testRunQueryAsJob()
{
$tableId = $this->createTempTable();
@@ -283,7 +310,7 @@ public function testRunQueryAsJob()
$tableId
);
- $output = $this->runSnippet('run_query_as_job', [$query]);
+ $output = $this->runFunctionSnippet('run_query_as_job', [$query]);
$this->assertStringContainsString('Found 1 row(s)', $output);
}
@@ -296,7 +323,7 @@ public function testDryRunQuery()
$tableId
);
- $output = $this->runSnippet('dry_run_query', [$query]);
+ $output = $this->runFunctionSnippet('dry_run_query', [$query]);
$this->assertStringContainsString('This query will process 126 bytes', $output);
}
@@ -309,36 +336,63 @@ public function testQueryNoCache()
$tableId
);
- $output = $this->runSnippet('query_no_cache', [$query]);
+ $output = $this->runFunctionSnippet('query_no_cache', [$query]);
$this->assertStringContainsString('Found 1 row(s)', $output);
}
public function testQueryLegacy()
{
- $output = $this->runSnippet('query_legacy');
+ $output = $this->runFunctionSnippet('query_legacy');
$this->assertStringContainsString('tempest', $output);
$this->assertStringContainsString('kinghenryviii', $output);
$this->assertStringContainsString('Found 42 row(s)', $output);
}
- private function runSnippet($sampleName, $params = [])
+ public function testAddColumnLoadAppend()
+ {
+ $tableId = $this->createTempTable();
+ $output = $this->runFunctionSnippet('add_column_load_append', [
+ self::$datasetId,
+ $tableId
+ ]);
+
+ $this->assertStringContainsString('name', $output);
+ $this->assertStringContainsString('title', $output);
+ $this->assertStringContainsString('description', $output);
+ }
+
+ public function testAddColumnQueryAppend()
{
- $argv = array_merge([0, self::$projectId], $params);
- ob_start();
- require __DIR__ . "/../src/$sampleName.php";
- return ob_get_clean();
+ $tableId = $this->createTempTable();
+ $output = $this->runFunctionSnippet('add_column_query_append', [
+ self::$datasetId,
+ $tableId
+ ]);
+ $this->assertStringContainsString('name', $output);
+ $this->assertStringContainsString('title', $output);
+ $this->assertStringContainsString('description', $output);
+ }
+
+ private function runFunctionSnippet($sampleName, $params = [])
+ {
+ array_unshift($params, self::$projectId);
+ return $this->traitRunFunctionSnippet(
+ $sampleName,
+ $params
+ );
}
private function createTempEmptyTable()
{
$tempTableId = sprintf('test_table_%s_%s', time(), rand());
- $this->runSnippet('create_table', [
+ $fields = json_encode([
+ ['name' => 'name', 'type' => 'string', 'mode' => 'nullable'],
+ ['name' => 'title', 'type' => 'string', 'mode' => 'nullable']
+ ]);
+ $this->runFunctionSnippet('create_table', [
self::$datasetId,
$tempTableId,
- json_encode([
- ['name' => 'name', 'type' => 'string', 'mode' => 'nullable'],
- ['name' => 'title', 'type' => 'string', 'mode' => 'nullable']
- ])
+ $fields
]);
return $tempTableId;
}
@@ -347,7 +401,7 @@ private function createTempTable()
{
$tempTableId = $this->createTempEmptyTable();
$source = __DIR__ . '/data/test_data.csv';
- $output = $this->runSnippet('import_from_local_csv', [
+ $output = $this->runFunctionSnippet('import_from_local_csv', [
self::$datasetId,
$tempTableId,
$source,
diff --git a/bigquery/api/test/data/test_data_extra_column.csv b/bigquery/api/test/data/test_data_extra_column.csv
new file mode 100644
index 0000000000..6868d98d67
--- /dev/null
+++ b/bigquery/api/test/data/test_data_extra_column.csv
@@ -0,0 +1 @@
+"Yash Sahu","Learner","Sundays are sleep days"
diff --git a/bigquery/stackoverflow/stackoverflow.php b/bigquery/stackoverflow/stackoverflow.php
index 0f6cf56a18..7f070587f5 100644
--- a/bigquery/stackoverflow/stackoverflow.php
+++ b/bigquery/stackoverflow/stackoverflow.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
# [START bigquery_simple_app_all]
diff --git a/bigtable/src/create_app_profile.php b/bigtable/src/create_app_profile.php
index 4e8d5ceffa..44e6416804 100644
--- a/bigtable/src/create_app_profile.php
+++ b/bigtable/src/create_app_profile.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/create_cluster.php b/bigtable/src/create_cluster.php
index 727b6306aa..1836d0ecd2 100644
--- a/bigtable/src/create_cluster.php
+++ b/bigtable/src/create_cluster.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/create_cluster_autoscale_config.php b/bigtable/src/create_cluster_autoscale_config.php
index 280495730e..54a6568dcb 100644
--- a/bigtable/src/create_cluster_autoscale_config.php
+++ b/bigtable/src/create_cluster_autoscale_config.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/create_dev_instance.php b/bigtable/src/create_dev_instance.php
index b051ba49fe..b5ef0229c6 100644
--- a/bigtable/src/create_dev_instance.php
+++ b/bigtable/src/create_dev_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/create_family_gc_intersection.php b/bigtable/src/create_family_gc_intersection.php
index e1214eceed..26139dd58b 100644
--- a/bigtable/src/create_family_gc_intersection.php
+++ b/bigtable/src/create_family_gc_intersection.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/create_family_gc_max_age.php b/bigtable/src/create_family_gc_max_age.php
index 2a69966d24..5a8943997f 100644
--- a/bigtable/src/create_family_gc_max_age.php
+++ b/bigtable/src/create_family_gc_max_age.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/create_family_gc_max_versions.php b/bigtable/src/create_family_gc_max_versions.php
index e7aeadca43..0c69a4fa90 100644
--- a/bigtable/src/create_family_gc_max_versions.php
+++ b/bigtable/src/create_family_gc_max_versions.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/create_family_gc_nested.php b/bigtable/src/create_family_gc_nested.php
index d6ab27e43e..e86a797ccf 100644
--- a/bigtable/src/create_family_gc_nested.php
+++ b/bigtable/src/create_family_gc_nested.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/create_family_gc_union.php b/bigtable/src/create_family_gc_union.php
index a30629decb..2bdabb5510 100644
--- a/bigtable/src/create_family_gc_union.php
+++ b/bigtable/src/create_family_gc_union.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/create_production_instance.php b/bigtable/src/create_production_instance.php
index 2f4967c6f5..ba6ded4579 100644
--- a/bigtable/src/create_production_instance.php
+++ b/bigtable/src/create_production_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/create_table.php b/bigtable/src/create_table.php
index 792bfe1201..6e1afd1b54 100644
--- a/bigtable/src/create_table.php
+++ b/bigtable/src/create_table.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/delete_app_profile.php b/bigtable/src/delete_app_profile.php
index 534e7da894..4525ea0d18 100644
--- a/bigtable/src/delete_app_profile.php
+++ b/bigtable/src/delete_app_profile.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/delete_cluster.php b/bigtable/src/delete_cluster.php
index a7d4af33b3..f5f578ddc3 100644
--- a/bigtable/src/delete_cluster.php
+++ b/bigtable/src/delete_cluster.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/delete_family.php b/bigtable/src/delete_family.php
index ccf7af567c..9d0176fe6e 100644
--- a/bigtable/src/delete_family.php
+++ b/bigtable/src/delete_family.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/delete_instance.php b/bigtable/src/delete_instance.php
index 08a01ac844..3fb9860cd6 100644
--- a/bigtable/src/delete_instance.php
+++ b/bigtable/src/delete_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/delete_table.php b/bigtable/src/delete_table.php
index 83e05c9995..958ca51ef7 100644
--- a/bigtable/src/delete_table.php
+++ b/bigtable/src/delete_table.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/disable_cluster_autoscale_config.php b/bigtable/src/disable_cluster_autoscale_config.php
index ea7cfbda3b..e1ef9bb170 100644
--- a/bigtable/src/disable_cluster_autoscale_config.php
+++ b/bigtable/src/disable_cluster_autoscale_config.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_composing_chain.php b/bigtable/src/filter_composing_chain.php
index 17587dc587..e0c37ad859 100644
--- a/bigtable/src/filter_composing_chain.php
+++ b/bigtable/src/filter_composing_chain.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_composing_condition.php b/bigtable/src/filter_composing_condition.php
index e61aa78101..a16dd68772 100644
--- a/bigtable/src/filter_composing_condition.php
+++ b/bigtable/src/filter_composing_condition.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_composing_interleave.php b/bigtable/src/filter_composing_interleave.php
index 48047371ba..8bbcb807e0 100644
--- a/bigtable/src/filter_composing_interleave.php
+++ b/bigtable/src/filter_composing_interleave.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_block_all.php b/bigtable/src/filter_limit_block_all.php
index 5a7812a774..d6048a8368 100644
--- a/bigtable/src/filter_limit_block_all.php
+++ b/bigtable/src/filter_limit_block_all.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_cells_per_col.php b/bigtable/src/filter_limit_cells_per_col.php
index 4816477e10..6319fcace9 100644
--- a/bigtable/src/filter_limit_cells_per_col.php
+++ b/bigtable/src/filter_limit_cells_per_col.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_cells_per_row.php b/bigtable/src/filter_limit_cells_per_row.php
index e3d5269f1c..460818204d 100644
--- a/bigtable/src/filter_limit_cells_per_row.php
+++ b/bigtable/src/filter_limit_cells_per_row.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_cells_per_row_offset.php b/bigtable/src/filter_limit_cells_per_row_offset.php
index 873bee4e5c..062bcdda5c 100644
--- a/bigtable/src/filter_limit_cells_per_row_offset.php
+++ b/bigtable/src/filter_limit_cells_per_row_offset.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_col_family_regex.php b/bigtable/src/filter_limit_col_family_regex.php
index 087196276e..dcab0ca27c 100644
--- a/bigtable/src/filter_limit_col_family_regex.php
+++ b/bigtable/src/filter_limit_col_family_regex.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_col_qualifier_regex.php b/bigtable/src/filter_limit_col_qualifier_regex.php
index b75faa4f08..f624c059b6 100644
--- a/bigtable/src/filter_limit_col_qualifier_regex.php
+++ b/bigtable/src/filter_limit_col_qualifier_regex.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_col_range.php b/bigtable/src/filter_limit_col_range.php
index 89156ade53..f7f8cc612d 100644
--- a/bigtable/src/filter_limit_col_range.php
+++ b/bigtable/src/filter_limit_col_range.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_pass_all.php b/bigtable/src/filter_limit_pass_all.php
index f54b923f09..fa93437835 100644
--- a/bigtable/src/filter_limit_pass_all.php
+++ b/bigtable/src/filter_limit_pass_all.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_row_regex.php b/bigtable/src/filter_limit_row_regex.php
index edc7f0c0fd..4df7f2ea5f 100644
--- a/bigtable/src/filter_limit_row_regex.php
+++ b/bigtable/src/filter_limit_row_regex.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_row_sample.php b/bigtable/src/filter_limit_row_sample.php
index 53ab0b8e73..b0d25570ea 100644
--- a/bigtable/src/filter_limit_row_sample.php
+++ b/bigtable/src/filter_limit_row_sample.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_timestamp_range.php b/bigtable/src/filter_limit_timestamp_range.php
index bf287e46a2..0d0cf8f4c7 100644
--- a/bigtable/src/filter_limit_timestamp_range.php
+++ b/bigtable/src/filter_limit_timestamp_range.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_value_range.php b/bigtable/src/filter_limit_value_range.php
index 73b5134090..abcbfb3be5 100644
--- a/bigtable/src/filter_limit_value_range.php
+++ b/bigtable/src/filter_limit_value_range.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_limit_value_regex.php b/bigtable/src/filter_limit_value_regex.php
index 4459926d7b..6ba48cf7d4 100644
--- a/bigtable/src/filter_limit_value_regex.php
+++ b/bigtable/src/filter_limit_value_regex.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_modify_apply_label.php b/bigtable/src/filter_modify_apply_label.php
index 3996db6088..02c4f46be8 100644
--- a/bigtable/src/filter_modify_apply_label.php
+++ b/bigtable/src/filter_modify_apply_label.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/filter_modify_strip_value.php b/bigtable/src/filter_modify_strip_value.php
index 9f6c0057e7..5fb521b3ec 100644
--- a/bigtable/src/filter_modify_strip_value.php
+++ b/bigtable/src/filter_modify_strip_value.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/get_app_profile.php b/bigtable/src/get_app_profile.php
index 9e072c19ed..d92d578089 100644
--- a/bigtable/src/get_app_profile.php
+++ b/bigtable/src/get_app_profile.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/get_cluster.php b/bigtable/src/get_cluster.php
index f60e2ca697..91f426a185 100644
--- a/bigtable/src/get_cluster.php
+++ b/bigtable/src/get_cluster.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/get_iam_policy.php b/bigtable/src/get_iam_policy.php
index 9c5f564ff0..4e9d989f04 100644
--- a/bigtable/src/get_iam_policy.php
+++ b/bigtable/src/get_iam_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/get_instance.php b/bigtable/src/get_instance.php
index ba1bcdcdc8..7d5daa9b4a 100644
--- a/bigtable/src/get_instance.php
+++ b/bigtable/src/get_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/hello_world.php b/bigtable/src/hello_world.php
index d990d70736..0b1f02ccd8 100644
--- a/bigtable/src/hello_world.php
+++ b/bigtable/src/hello_world.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
// Include Google Cloud dependencies using Composer
diff --git a/bigtable/src/insert_update_rows.php b/bigtable/src/insert_update_rows.php
index 550259625f..f1d82de874 100644
--- a/bigtable/src/insert_update_rows.php
+++ b/bigtable/src/insert_update_rows.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/list_app_profiles.php b/bigtable/src/list_app_profiles.php
index 674d6b4219..9f6a0387a5 100644
--- a/bigtable/src/list_app_profiles.php
+++ b/bigtable/src/list_app_profiles.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/list_column_families.php b/bigtable/src/list_column_families.php
index 95746195d6..5b7e595671 100644
--- a/bigtable/src/list_column_families.php
+++ b/bigtable/src/list_column_families.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/list_instance.php b/bigtable/src/list_instance.php
index 8cdaaa2163..82c310d5fe 100644
--- a/bigtable/src/list_instance.php
+++ b/bigtable/src/list_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/list_instance_clusters.php b/bigtable/src/list_instance_clusters.php
index 4f5f2a767c..ef6514a8f2 100644
--- a/bigtable/src/list_instance_clusters.php
+++ b/bigtable/src/list_instance_clusters.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/list_tables.php b/bigtable/src/list_tables.php
index e4d648a113..03a8c84369 100644
--- a/bigtable/src/list_tables.php
+++ b/bigtable/src/list_tables.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/quickstart.php b/bigtable/src/quickstart.php
index 835302bc67..6155f55f43 100644
--- a/bigtable/src/quickstart.php
+++ b/bigtable/src/quickstart.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
// Include Google Cloud dependencies using Composer
diff --git a/bigtable/src/read_filter.php b/bigtable/src/read_filter.php
index 03b8204913..1e3e59fe1f 100644
--- a/bigtable/src/read_filter.php
+++ b/bigtable/src/read_filter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/read_prefix.php b/bigtable/src/read_prefix.php
index e279139a17..5434c66d91 100644
--- a/bigtable/src/read_prefix.php
+++ b/bigtable/src/read_prefix.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/read_row.php b/bigtable/src/read_row.php
index 6ffb8f6f85..82f4760d3d 100644
--- a/bigtable/src/read_row.php
+++ b/bigtable/src/read_row.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/read_row_partial.php b/bigtable/src/read_row_partial.php
index 3a7d9e1604..a60406ab08 100644
--- a/bigtable/src/read_row_partial.php
+++ b/bigtable/src/read_row_partial.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/read_row_range.php b/bigtable/src/read_row_range.php
index b1837fabc0..da3f42cef7 100644
--- a/bigtable/src/read_row_range.php
+++ b/bigtable/src/read_row_range.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/read_row_ranges.php b/bigtable/src/read_row_ranges.php
index c838874cb2..c82b82e24b 100644
--- a/bigtable/src/read_row_ranges.php
+++ b/bigtable/src/read_row_ranges.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/read_rows.php b/bigtable/src/read_rows.php
index 6b7e5984ce..12009624fa 100644
--- a/bigtable/src/read_rows.php
+++ b/bigtable/src/read_rows.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/set_iam_policy.php b/bigtable/src/set_iam_policy.php
index dc80cc07c2..825cca10c7 100644
--- a/bigtable/src/set_iam_policy.php
+++ b/bigtable/src/set_iam_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/test_iam_permissions.php b/bigtable/src/test_iam_permissions.php
index 03c9c6ed37..d6dcb5020c 100644
--- a/bigtable/src/test_iam_permissions.php
+++ b/bigtable/src/test_iam_permissions.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/update_app_profile.php b/bigtable/src/update_app_profile.php
index cdebce086c..1f403d35d2 100644
--- a/bigtable/src/update_app_profile.php
+++ b/bigtable/src/update_app_profile.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/update_cluster.php b/bigtable/src/update_cluster.php
index 0029947899..0c8d5dc464 100644
--- a/bigtable/src/update_cluster.php
+++ b/bigtable/src/update_cluster.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/update_cluster_autoscale_config.php b/bigtable/src/update_cluster_autoscale_config.php
index 82410a0281..beea8f4ba2 100644
--- a/bigtable/src/update_cluster_autoscale_config.php
+++ b/bigtable/src/update_cluster_autoscale_config.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/update_gc_rule.php b/bigtable/src/update_gc_rule.php
index e790317fa2..a5e1888398 100644
--- a/bigtable/src/update_gc_rule.php
+++ b/bigtable/src/update_gc_rule.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/update_instance.php b/bigtable/src/update_instance.php
index e4172fdb3f..0647c442fe 100644
--- a/bigtable/src/update_instance.php
+++ b/bigtable/src/update_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/write_batch.php b/bigtable/src/write_batch.php
index a1aa854158..9da801723b 100644
--- a/bigtable/src/write_batch.php
+++ b/bigtable/src/write_batch.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/write_conditionally.php b/bigtable/src/write_conditionally.php
index c0270163de..071c34f733 100644
--- a/bigtable/src/write_conditionally.php
+++ b/bigtable/src/write_conditionally.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/write_increment.php b/bigtable/src/write_increment.php
index 440ffc7392..9b92f317fe 100644
--- a/bigtable/src/write_increment.php
+++ b/bigtable/src/write_increment.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/src/write_simple.php b/bigtable/src/write_simple.php
index 1eb23a94cd..1e9b20c1dd 100644
--- a/bigtable/src/write_simple.php
+++ b/bigtable/src/write_simple.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigtable/README.md
*/
namespace Google\Cloud\Samples\Bigtable;
diff --git a/bigtable/test/bigtableTest.php b/bigtable/test/bigtableTest.php
index 620190ca73..d39f4ceb4d 100644
--- a/bigtable/test/bigtableTest.php
+++ b/bigtable/test/bigtableTest.php
@@ -5,10 +5,16 @@
use Google\ApiCore\ApiException;
use Google\Cloud\Bigtable\Admin\V2\Table\View;
use PHPUnit\Framework\TestCase;
+use PHPUnitRetry\RetryTrait;
+/**
+ * @retryAttempts 3
+ * @retryDelayMethod exponentialBackoff
+ */
final class BigtableTest extends TestCase
{
use BigtableTestTrait;
+ use RetryTrait;
public const CLUSTER_ID_PREFIX = 'php-cluster-';
public const INSTANCE_ID_PREFIX = 'php-instance-';
diff --git a/compute/cloud-client/firewall/src/create_firewall_rule.php b/compute/cloud-client/firewall/src/create_firewall_rule.php
index e01d2f2012..f7135f109a 100644
--- a/compute/cloud-client/firewall/src/create_firewall_rule.php
+++ b/compute/cloud-client/firewall/src/create_firewall_rule.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/firewall/src/delete_firewall_rule.php b/compute/cloud-client/firewall/src/delete_firewall_rule.php
index 1e37961bd2..485ae9d3e8 100644
--- a/compute/cloud-client/firewall/src/delete_firewall_rule.php
+++ b/compute/cloud-client/firewall/src/delete_firewall_rule.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/firewall/src/list_firewall_rules.php b/compute/cloud-client/firewall/src/list_firewall_rules.php
index a69b01ddc0..f888286f66 100644
--- a/compute/cloud-client/firewall/src/list_firewall_rules.php
+++ b/compute/cloud-client/firewall/src/list_firewall_rules.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/firewall/src/patch_firewall_priority.php b/compute/cloud-client/firewall/src/patch_firewall_priority.php
index 9bced91320..d10a730b4a 100644
--- a/compute/cloud-client/firewall/src/patch_firewall_priority.php
+++ b/compute/cloud-client/firewall/src/patch_firewall_priority.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/firewall/src/print_firewall_rule.php b/compute/cloud-client/firewall/src/print_firewall_rule.php
index 7057be93df..25d4cb7f0d 100644
--- a/compute/cloud-client/firewall/src/print_firewall_rule.php
+++ b/compute/cloud-client/firewall/src/print_firewall_rule.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/create_instance.php b/compute/cloud-client/instances/src/create_instance.php
index 535dd756e6..583d106b88 100644
--- a/compute/cloud-client/instances/src/create_instance.php
+++ b/compute/cloud-client/instances/src/create_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/create_instance_with_encryption_key.php b/compute/cloud-client/instances/src/create_instance_with_encryption_key.php
index 45a3def8cf..ce8f9aeee0 100644
--- a/compute/cloud-client/instances/src/create_instance_with_encryption_key.php
+++ b/compute/cloud-client/instances/src/create_instance_with_encryption_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/delete_instance.php b/compute/cloud-client/instances/src/delete_instance.php
index aa1d2f224b..d59ca9991c 100644
--- a/compute/cloud-client/instances/src/delete_instance.php
+++ b/compute/cloud-client/instances/src/delete_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/disable_usage_export_bucket.php b/compute/cloud-client/instances/src/disable_usage_export_bucket.php
index 5366778938..bc4b244b14 100644
--- a/compute/cloud-client/instances/src/disable_usage_export_bucket.php
+++ b/compute/cloud-client/instances/src/disable_usage_export_bucket.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/get_usage_export_bucket.php b/compute/cloud-client/instances/src/get_usage_export_bucket.php
index 7057291790..6097cd6c96 100644
--- a/compute/cloud-client/instances/src/get_usage_export_bucket.php
+++ b/compute/cloud-client/instances/src/get_usage_export_bucket.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/list_all_images.php b/compute/cloud-client/instances/src/list_all_images.php
index 6df5e0536a..e4c4230357 100644
--- a/compute/cloud-client/instances/src/list_all_images.php
+++ b/compute/cloud-client/instances/src/list_all_images.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/list_all_instances.php b/compute/cloud-client/instances/src/list_all_instances.php
index 253a9481f9..194f407dd8 100644
--- a/compute/cloud-client/instances/src/list_all_instances.php
+++ b/compute/cloud-client/instances/src/list_all_instances.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/list_images_by_page.php b/compute/cloud-client/instances/src/list_images_by_page.php
index b4ca554b98..6a1069a91a 100644
--- a/compute/cloud-client/instances/src/list_images_by_page.php
+++ b/compute/cloud-client/instances/src/list_images_by_page.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/list_instances.php b/compute/cloud-client/instances/src/list_instances.php
index 212b7f2074..8fd33393a6 100644
--- a/compute/cloud-client/instances/src/list_instances.php
+++ b/compute/cloud-client/instances/src/list_instances.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/reset_instance.php b/compute/cloud-client/instances/src/reset_instance.php
index 515e3b7320..f52fb85d53 100644
--- a/compute/cloud-client/instances/src/reset_instance.php
+++ b/compute/cloud-client/instances/src/reset_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/resume_instance.php b/compute/cloud-client/instances/src/resume_instance.php
index c349024d8b..ff3f5d79ce 100644
--- a/compute/cloud-client/instances/src/resume_instance.php
+++ b/compute/cloud-client/instances/src/resume_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/set_usage_export_bucket.php b/compute/cloud-client/instances/src/set_usage_export_bucket.php
index f5b9658e51..5e7f29c2bd 100644
--- a/compute/cloud-client/instances/src/set_usage_export_bucket.php
+++ b/compute/cloud-client/instances/src/set_usage_export_bucket.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/start_instance.php b/compute/cloud-client/instances/src/start_instance.php
index 2807de131d..396c167369 100644
--- a/compute/cloud-client/instances/src/start_instance.php
+++ b/compute/cloud-client/instances/src/start_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/start_instance_with_encryption_key.php b/compute/cloud-client/instances/src/start_instance_with_encryption_key.php
index 312a1b1ef1..dc4a66c7a6 100644
--- a/compute/cloud-client/instances/src/start_instance_with_encryption_key.php
+++ b/compute/cloud-client/instances/src/start_instance_with_encryption_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/stop_instance.php b/compute/cloud-client/instances/src/stop_instance.php
index 21c6a0d82f..6e36af9d0c 100644
--- a/compute/cloud-client/instances/src/stop_instance.php
+++ b/compute/cloud-client/instances/src/stop_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/compute/cloud-client/instances/src/suspend_instance.php b/compute/cloud-client/instances/src/suspend_instance.php
index 14fd437305..cbcb5b4a11 100644
--- a/compute/cloud-client/instances/src/suspend_instance.php
+++ b/compute/cloud-client/instances/src/suspend_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/compute/cloud-client/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/compute/cloud-client/README.md
*/
namespace Google\Cloud\Samples\Compute;
diff --git a/dialogflow/README.md b/dialogflow/README.md
index 615a18acf8..04b7ef0158 100644
--- a/dialogflow/README.md
+++ b/dialogflow/README.md
@@ -14,7 +14,7 @@ API from PHP.
1. Follow the first 2 steps of [this quickstart](https://cloud.google.com/dialogflow-enterprise/docs/quickstart-api).
Feel free to stop after you've created an agent.
-2. This sample comes with a [sample agent](https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/dialogflow/resources/RoomReservation.zip) which you can use to try the samples with. Follow the instructions on [this page](https://dialogflow.com/docs/best-practices/import-export-for-versions) to import the agent from the [console](https://console.dialogflow.com/api-client).
+2. This sample comes with a [sample agent](https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/dialogflow/resources/RoomReservation.zip) which you can use to try the samples with. Follow the instructions on [this page](https://dialogflow.com/docs/best-practices/import-export-for-versions) to import the agent from the [console](https://console.dialogflow.com/api-client).
> WARNING: Importing the sample agent will add intents and entities to your Dialogflow agent. You might want to use a different Google Cloud Platform Project, or export your Dialogflow agent before importing the sample agent to save a version of your agent before the sample agent was imported.
3. Clone the repo and cd into this directory
diff --git a/dlp/src/categorical_stats.php b/dlp/src/categorical_stats.php
index 5dc62d5f6c..c95e7c2c14 100644
--- a/dlp/src/categorical_stats.php
+++ b/dlp/src/categorical_stats.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/create_inspect_template.php b/dlp/src/create_inspect_template.php
index 839be01ed1..58225eb666 100644
--- a/dlp/src/create_inspect_template.php
+++ b/dlp/src/create_inspect_template.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/create_trigger.php b/dlp/src/create_trigger.php
index 55ad1f2cc0..a01bc4afd4 100644
--- a/dlp/src/create_trigger.php
+++ b/dlp/src/create_trigger.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/deidentify_dates.php b/dlp/src/deidentify_dates.php
index a802bee8d6..b7c05c2342 100644
--- a/dlp/src/deidentify_dates.php
+++ b/dlp/src/deidentify_dates.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/deidentify_fpe.php b/dlp/src/deidentify_fpe.php
index bfe9027101..740903f012 100644
--- a/dlp/src/deidentify_fpe.php
+++ b/dlp/src/deidentify_fpe.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/deidentify_mask.php b/dlp/src/deidentify_mask.php
index d38cf8d77d..55d5ec3290 100644
--- a/dlp/src/deidentify_mask.php
+++ b/dlp/src/deidentify_mask.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/delete_inspect_template.php b/dlp/src/delete_inspect_template.php
index b3fcaa6d1e..ecf13c5c2e 100644
--- a/dlp/src/delete_inspect_template.php
+++ b/dlp/src/delete_inspect_template.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/delete_job.php b/dlp/src/delete_job.php
index 9503558c00..41ddb240f5 100644
--- a/dlp/src/delete_job.php
+++ b/dlp/src/delete_job.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/delete_trigger.php b/dlp/src/delete_trigger.php
index ad7c643695..b38e42a6e9 100644
--- a/dlp/src/delete_trigger.php
+++ b/dlp/src/delete_trigger.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/inspect_bigquery.php b/dlp/src/inspect_bigquery.php
index 6bd13fd4c3..8381b2bb8c 100644
--- a/dlp/src/inspect_bigquery.php
+++ b/dlp/src/inspect_bigquery.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/inspect_datastore.php b/dlp/src/inspect_datastore.php
index 970ba07df7..599ec11ce4 100644
--- a/dlp/src/inspect_datastore.php
+++ b/dlp/src/inspect_datastore.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/inspect_gcs.php b/dlp/src/inspect_gcs.php
index 82526a2fc3..996199546c 100644
--- a/dlp/src/inspect_gcs.php
+++ b/dlp/src/inspect_gcs.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/inspect_image_file.php b/dlp/src/inspect_image_file.php
index 2bd11910c8..c384e0938e 100644
--- a/dlp/src/inspect_image_file.php
+++ b/dlp/src/inspect_image_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/inspect_string.php b/dlp/src/inspect_string.php
index b7f8e1ac70..b1e0a5035a 100644
--- a/dlp/src/inspect_string.php
+++ b/dlp/src/inspect_string.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/inspect_text_file.php b/dlp/src/inspect_text_file.php
index c6fa091594..5acf13de7c 100644
--- a/dlp/src/inspect_text_file.php
+++ b/dlp/src/inspect_text_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/bigquery/api/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/k_anonymity.php b/dlp/src/k_anonymity.php
index 7068dd321d..1b00f83c52 100644
--- a/dlp/src/k_anonymity.php
+++ b/dlp/src/k_anonymity.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/k_map.php b/dlp/src/k_map.php
index 01889add68..efb37fd654 100644
--- a/dlp/src/k_map.php
+++ b/dlp/src/k_map.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/l_diversity.php b/dlp/src/l_diversity.php
index 26b95a3e32..6bdcf5a176 100644
--- a/dlp/src/l_diversity.php
+++ b/dlp/src/l_diversity.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/list_info_types.php b/dlp/src/list_info_types.php
index e08bd7b143..032f050b81 100644
--- a/dlp/src/list_info_types.php
+++ b/dlp/src/list_info_types.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/list_inspect_templates.php b/dlp/src/list_inspect_templates.php
index b791963bee..2b8f1965b6 100644
--- a/dlp/src/list_inspect_templates.php
+++ b/dlp/src/list_inspect_templates.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/list_jobs.php b/dlp/src/list_jobs.php
index 61ed9a41c9..7f5617434f 100644
--- a/dlp/src/list_jobs.php
+++ b/dlp/src/list_jobs.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/list_triggers.php b/dlp/src/list_triggers.php
index 5c42a731b6..e1861234e4 100644
--- a/dlp/src/list_triggers.php
+++ b/dlp/src/list_triggers.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/numerical_stats.php b/dlp/src/numerical_stats.php
index 7468fce951..2559f9fd64 100644
--- a/dlp/src/numerical_stats.php
+++ b/dlp/src/numerical_stats.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/redact_image.php b/dlp/src/redact_image.php
index 88c80e07bc..e8ea50100f 100644
--- a/dlp/src/redact_image.php
+++ b/dlp/src/redact_image.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/dlp/src/reidentify_fpe.php b/dlp/src/reidentify_fpe.php
index 6791cf1739..0eb96747ee 100644
--- a/dlp/src/reidentify_fpe.php
+++ b/dlp/src/reidentify_fpe.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/dlp/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/dlp/README.md
*/
namespace Google\Cloud\Samples\Dlp;
diff --git a/endpoints/getting-started/app.php b/endpoints/getting-started/app.php
index c854f3f0a9..1570f95712 100644
--- a/endpoints/getting-started/app.php
+++ b/endpoints/getting-started/app.php
@@ -34,7 +34,7 @@
$app->get('/', function (Request $request, Response $response) {
// Simple echo service.
- $url = 'https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/endpoints/getting-started/README.md';
+ $url = 'https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/endpoints/getting-started/README.md';
$response->getBody()->write(sprintf(
'
Welcome to the Endpoints getting started tutorial!
' .
diff --git a/error_reporting/src/report_error.php b/error_reporting/src/report_error.php
index 807567a19c..401c92b0d3 100644
--- a/error_reporting/src/report_error.php
+++ b/error_reporting/src/report_error.php
@@ -18,17 +18,10 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/error_reporting/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/error_reporting/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 3 || count($argv) > 4) {
- return printf("Usage: php %s PROJECT_ID ERROR_MESSAGE [USER]\n", basename(__FILE__));
-}
-list($_, $projectId, $message) = $argv;
-$user = isset($argv[3]) ? $argv[3] : '';
+namespace Google\Cloud\Samples\ErrorReporting;
# [START report_error]
use Google\Cloud\ErrorReporting\V1beta1\ReportErrorsServiceClient;
@@ -41,26 +34,31 @@
* The ReportedErrorEvent object gives you more control over how the error
* appears and the details associated with it.
*
- * Uncomment these line and replace with your project ID, message, and optionally your user.
+ * @param string $projectId Your Google Cloud Project ID.
+ * @param string $message The error message to report.
+ * @param string $user Optional user email address
*/
-// $projectId = 'YOUR_PROJECT_ID';
-// $message = 'This is the error message to report!';
-// $user = 'optional@user.com';
-
-$errors = new ReportErrorsServiceClient();
-$projectName = $errors->projectName($projectId);
+function report_error(string $projectId, string $message, string $user = '')
+{
+ $errors = new ReportErrorsServiceClient();
+ $projectName = $errors->projectName($projectId);
-$location = (new SourceLocation())
- ->setFunctionName('global');
+ $location = (new SourceLocation())
+ ->setFunctionName('global');
-$context = (new ErrorContext())
- ->setReportLocation($location)
- ->setUser($user);
+ $context = (new ErrorContext())
+ ->setReportLocation($location)
+ ->setUser($user);
-$event = (new ReportedErrorEvent())
- ->setMessage($message)
- ->setContext($context);
+ $event = (new ReportedErrorEvent())
+ ->setMessage($message)
+ ->setContext($context);
-$errors->reportErrorEvent($projectName, $event);
+ $errors->reportErrorEvent($projectName, $event);
+ print('Reported an exception to Stackdriver' . PHP_EOL);
+}
# [END report_error]
-print('Reported an exception to Stackdriver' . PHP_EOL);
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/error_reporting/test/report_errorTest.php b/error_reporting/test/report_errorTest.php
index d1dce80d83..d959d9ced1 100644
--- a/error_reporting/test/report_errorTest.php
+++ b/error_reporting/test/report_errorTest.php
@@ -17,6 +17,7 @@
namespace Google\Cloud\Samples\ErrorReporting;
+use Google\Cloud\TestUtils\TestTrait;
use PHPUnit\Framework\TestCase;
// Load the testing trait
@@ -24,12 +25,14 @@
class report_errorTest extends TestCase
{
+ use TestTrait;
use VerifyReportedErrorTrait;
public function testReportError()
{
$message = sprintf('Test Report Error (%s)', date('Y-m-d H:i:s'));
- $output = $this->runSnippet('report_error', [
+ $output = $this->runFunctionSnippet('report_error', [
+ self::$projectId,
$message,
'unittests@google.com',
]);
@@ -40,12 +43,4 @@ public function testReportError()
$this->verifyReportedError(self::$projectId, $message);
}
-
- private function runSnippet($sampleName, $params = [])
- {
- $argv = array_merge([0, self::$projectId], $params);
- ob_start();
- require __DIR__ . "/../src/$sampleName.php";
- return ob_get_clean();
- }
}
diff --git a/firestore/src/City.php b/firestore/src/City.php
index 1ceb1108bb..48598a0af9 100644
--- a/firestore/src/City.php
+++ b/firestore/src/City.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
diff --git a/firestore/src/data_batch_writes.php b/firestore/src/data_batch_writes.php
index d8d6d2d3ca..156637ec41 100644
--- a/firestore/src/data_batch_writes.php
+++ b/firestore/src/data_batch_writes.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function data_batch_writes(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_batch_write]
# [START firestore_data_batch_writes]
$batch = $db->batch();
@@ -59,7 +58,6 @@ function data_batch_writes(string $projectId): void
# Commit the batch
$batch->commit();
# [END firestore_data_batch_writes]
- # [END fs_batch_write]
printf('Batch write successfully completed.' . PHP_EOL);
}
diff --git a/firestore/src/data_delete_collection.php b/firestore/src/data_delete_collection.php
index d1f63ff329..c5292c75b5 100644
--- a/firestore/src/data_delete_collection.php
+++ b/firestore/src/data_delete_collection.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -32,7 +32,6 @@
* @param string $collectionName
* @param int $batchSize
*/
-# [START fs_delete_collection]
# [START firestore_data_delete_collection]
function data_delete_collection(string $projectId, string $collectionName, int $batchSize)
{
@@ -51,7 +50,6 @@ function data_delete_collection(string $projectId, string $collectionName, int $
}
}
# [END firestore_data_delete_collection]
-# [END fs_delete_collection]
// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
diff --git a/firestore/src/data_delete_doc.php b/firestore/src/data_delete_doc.php
index 0c6fd1b6ec..95d4992e59 100644
--- a/firestore/src/data_delete_doc.php
+++ b/firestore/src/data_delete_doc.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,11 +36,9 @@ function data_delete_doc(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_delete_doc]
# [START firestore_data_delete_doc]
$db->collection('samples/php/cities')->document('DC')->delete();
# [END firestore_data_delete_doc]
- # [END fs_delete_doc]
printf('Deleted the DC document in the cities collection.' . PHP_EOL);
}
diff --git a/firestore/src/data_delete_field.php b/firestore/src/data_delete_field.php
index bd6a9273e7..27a622fbb4 100644
--- a/firestore/src/data_delete_field.php
+++ b/firestore/src/data_delete_field.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,14 +37,12 @@ function data_delete_field(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_delete_field]
# [START firestore_data_delete_field]
$cityRef = $db->collection('samples/php/cities')->document('BJ');
$cityRef->update([
['path' => 'capital', 'value' => FieldValue::deleteField()]
]);
# [END firestore_data_delete_field]
- # [END fs_delete_field]
printf('Deleted the capital field from the BJ document in the cities collection.' . PHP_EOL);
}
diff --git a/firestore/src/data_get_all_documents.php b/firestore/src/data_get_all_documents.php
index 59b1c8d48e..1116fb3bfa 100644
--- a/firestore/src/data_get_all_documents.php
+++ b/firestore/src/data_get_all_documents.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function data_get_all_documents(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_get_all_docs]
# [START firestore_data_get_all_documents]
$citiesRef = $db->collection('samples/php/cities');
$documents = $citiesRef->documents();
@@ -50,7 +49,6 @@ function data_get_all_documents(string $projectId): void
}
}
# [END firestore_data_get_all_documents]
- # [END fs_get_all_docs]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/data_get_as_custom_type.php b/firestore/src/data_get_as_custom_type.php
index 00dca47f0c..b833f1370e 100644
--- a/firestore/src/data_get_as_custom_type.php
+++ b/firestore/src/data_get_as_custom_type.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
diff --git a/firestore/src/data_get_as_map.php b/firestore/src/data_get_as_map.php
index b3bf800b7e..f34bd793ff 100644
--- a/firestore/src/data_get_as_map.php
+++ b/firestore/src/data_get_as_map.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function data_get_as_map(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_get_document]
# [START firestore_data_get_as_map]
$docRef = $db->collection('samples/php/cities')->document('SF');
$snapshot = $docRef->snapshot();
@@ -48,7 +47,6 @@ function data_get_as_map(string $projectId): void
printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
}
# [END firestore_data_get_as_map]
- # [END fs_get_document]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/data_get_dataset.php b/firestore/src/data_get_dataset.php
index bb53f120b0..c25db511d9 100644
--- a/firestore/src/data_get_dataset.php
+++ b/firestore/src/data_get_dataset.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function data_get_dataset(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_retrieve_create_examples]
# [START firestore_data_get_dataset]
$citiesRef = $db->collection('samples/php/cities');
$citiesRef->document('SF')->set([
@@ -76,7 +75,6 @@ function data_get_dataset(string $projectId): void
]);
printf('Added example cities data to the cities collection.' . PHP_EOL);
# [END firestore_data_get_dataset]
- # [END fs_retrieve_create_examples]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/data_get_sub_collections.php b/firestore/src/data_get_sub_collections.php
index afad70d95b..c5242c5e81 100644
--- a/firestore/src/data_get_sub_collections.php
+++ b/firestore/src/data_get_sub_collections.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function data_get_sub_collections(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_get_collections]
# [START firestore_data_get_sub_collections]
$cityRef = $db->collection('samples/php/cities')->document('SF');
$collections = $cityRef->collections();
@@ -44,7 +43,6 @@ function data_get_sub_collections(string $projectId): void
printf('Found subcollection with id: %s' . PHP_EOL, $collection->id());
}
# [END firestore_data_get_sub_collections]
- # [END fs_get_collections]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/data_query.php b/firestore/src/data_query.php
index 5e36fce3c1..f6fa7d1847 100644
--- a/firestore/src/data_query.php
+++ b/firestore/src/data_query.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function data_query(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_get_multiple_docs]
# [START firestore_data_query]
$citiesRef = $db->collection('samples/php/cities');
$query = $citiesRef->where('capital', '=', true);
@@ -51,7 +50,6 @@ function data_query(string $projectId): void
}
}
# [END firestore_data_query]
- # [END fs_get_multiple_docs]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/data_reference_collection.php b/firestore/src/data_reference_collection.php
index 2bb3e477f7..7c6c1ba339 100644
--- a/firestore/src/data_reference_collection.php
+++ b/firestore/src/data_reference_collection.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,11 +36,9 @@ function data_reference_collection(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_collection_ref]
# [START firestore_data_reference_collection]
$collection = $db->collection('samples/php/users');
# [END firestore_data_reference_collection]
- # [END fs_collection_ref]
printf('Retrieved collection: %s' . PHP_EOL, $collection->name());
}
diff --git a/firestore/src/data_reference_document.php b/firestore/src/data_reference_document.php
index f1c4554f3f..a01b60709e 100644
--- a/firestore/src/data_reference_document.php
+++ b/firestore/src/data_reference_document.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,11 +36,9 @@ function data_reference_document(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_document_ref]
# [START firestore_data_reference_document]
$document = $db->collection('samples/php/users')->document('alovelace');
# [END firestore_data_reference_document]
- # [END fs_document_ref]
printf('Retrieved document: %s' . PHP_EOL, $document->name());
}
diff --git a/firestore/src/data_reference_document_path.php b/firestore/src/data_reference_document_path.php
index ef0c0c5309..1af4e84f65 100644
--- a/firestore/src/data_reference_document_path.php
+++ b/firestore/src/data_reference_document_path.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,11 +36,9 @@ function data_reference_document_path(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_document_path_ref]
# [START firestore_data_reference_document_path]
$document = $db->document('users/alovelace');
# [END firestore_data_reference_document_path]
- # [END fs_document_path_ref]
printf('Retrieved document from path: %s' . PHP_EOL, $document->name());
}
diff --git a/firestore/src/data_reference_subcollection.php b/firestore/src/data_reference_subcollection.php
index a86288accc..2266b1e360 100644
--- a/firestore/src/data_reference_subcollection.php
+++ b/firestore/src/data_reference_subcollection.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function data_reference_subcollection(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_subcollection_ref]
# [START firestore_data_reference_subcollection]
$document = $db
->collection('rooms')
@@ -44,7 +43,6 @@ function data_reference_subcollection(string $projectId): void
->collection('messages')
->document('message1');
# [END firestore_data_reference_subcollection]
- # [END fs_subcollection_ref]
printf('Retrieved document from subcollection: %s' . PHP_EOL, $document->name());
}
diff --git a/firestore/src/data_set_array_operations.php b/firestore/src/data_set_array_operations.php
index 8c14867503..c0b9433e46 100644
--- a/firestore/src/data_set_array_operations.php
+++ b/firestore/src/data_set_array_operations.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,7 +37,6 @@ function data_set_array_operations(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_update_doc_array]
# [START firestore_data_set_array_operations]
$cityRef = $db->collection('samples/php/cities')->document('DC');
@@ -51,7 +50,6 @@ function data_set_array_operations(string $projectId): void
['path' => 'regions', 'value' => FieldValue::arrayRemove(['east_coast'])]
]);
# [END firestore_data_set_array_operations]
- # [END fs_update_doc_array]
printf('Updated the regions field of the DC document in the cities collection.' . PHP_EOL);
}
diff --git a/firestore/src/data_set_doc_upsert.php b/firestore/src/data_set_doc_upsert.php
index 5ebf5dc684..ae194c6c8b 100644
--- a/firestore/src/data_set_doc_upsert.php
+++ b/firestore/src/data_set_doc_upsert.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,14 +36,12 @@ function data_set_doc_upsert(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_set_document_merge]
# [START firestore_data_set_doc_upsert]
$cityRef = $db->collection('samples/php/cities')->document('BJ');
$cityRef->set([
'capital' => true
], ['merge' => true]);
# [END firestore_data_set_doc_upsert]
- # [END fs_set_document_merge]
printf('Set document data by merging it into the existing BJ document in the cities collection.' . PHP_EOL);
}
diff --git a/firestore/src/data_set_field.php b/firestore/src/data_set_field.php
index b0bbfb95fb..82ef394650 100644
--- a/firestore/src/data_set_field.php
+++ b/firestore/src/data_set_field.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,14 +36,12 @@ function data_set_field(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_update_doc]
# [START firestore_data_set_field]
$cityRef = $db->collection('samples/php/cities')->document('DC');
$cityRef->update([
['path' => 'capital', 'value' => true]
]);
# [END firestore_data_set_field]
- # [END fs_update_doc]
printf('Updated the capital field of the DC document in the cities collection.' . PHP_EOL);
}
diff --git a/firestore/src/data_set_from_map.php b/firestore/src/data_set_from_map.php
index d9563e22e4..a8a420199c 100644
--- a/firestore/src/data_set_from_map.php
+++ b/firestore/src/data_set_from_map.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function data_set_from_map(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_set_document]
# [START firestore_data_set_from_map]
$data = [
'name' => 'Los Angeles',
@@ -45,7 +44,6 @@ function data_set_from_map(string $projectId): void
];
$db->collection('samples/php/cities')->document('LA')->set($data);
# [END firestore_data_set_from_map]
- # [END fs_set_document]
printf('Set data for the LA document in the cities collection.' . PHP_EOL);
}
diff --git a/firestore/src/data_set_from_map_nested.php b/firestore/src/data_set_from_map_nested.php
index 278d5cf29f..856fe67e9c 100644
--- a/firestore/src/data_set_from_map_nested.php
+++ b/firestore/src/data_set_from_map_nested.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -40,7 +40,6 @@ function data_set_from_map_nested(string $projectId): void
]);
// Set the reference document
$db->collection('samples/php/data')->document('two')->set(['foo' => 'bar']);
- # [START fs_add_doc_data_types]
# [START firestore_data_set_from_map_nested]
$data = [
'stringExample' => 'Hello World',
@@ -55,7 +54,6 @@ function data_set_from_map_nested(string $projectId): void
$db->collection('samples/php/data')->document('one')->set($data);
printf('Set multiple data-type data for the one document in the data collection.' . PHP_EOL);
# [END firestore_data_set_from_map_nested]
- # [END fs_add_doc_data_types]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/data_set_id_random_collection.php b/firestore/src/data_set_id_random_collection.php
index b9d7ab1eba..d0da16812a 100644
--- a/firestore/src/data_set_id_random_collection.php
+++ b/firestore/src/data_set_id_random_collection.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function data_set_id_random_collection(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_add_doc_data_with_auto_id]
# [START firestore_data_set_id_random_collection]
$data = [
'name' => 'Tokyo',
@@ -45,7 +44,6 @@ function data_set_id_random_collection(string $projectId): void
$addedDocRef = $db->collection('samples/php/cities')->add($data);
printf('Added document with ID: %s' . PHP_EOL, $addedDocRef->id());
# [END firestore_data_set_id_random_collection]
- # [END fs_add_doc_data_with_auto_id]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/data_set_id_random_document_ref.php b/firestore/src/data_set_id_random_document_ref.php
index 6bb6af4563..632de8c2de 100644
--- a/firestore/src/data_set_id_random_document_ref.php
+++ b/firestore/src/data_set_id_random_document_ref.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -40,13 +40,11 @@ function data_set_id_random_document_ref(string $projectId): void
'name' => 'Moscow',
'country' => 'Russia'
];
- # [START fs_add_doc_data_after_auto_id]
# [START firestore_data_set_id_random_document_ref]
$addedDocRef = $db->collection('samples/php/cities')->newDocument();
printf('Added document with ID: %s' . PHP_EOL, $addedDocRef->id());
$addedDocRef->set($data);
# [END firestore_data_set_id_random_document_ref]
- # [END fs_add_doc_data_after_auto_id]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/data_set_id_specified.php b/firestore/src/data_set_id_specified.php
index 650a3e54d7..ec4ab13f78 100644
--- a/firestore/src/data_set_id_specified.php
+++ b/firestore/src/data_set_id_specified.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -40,11 +40,9 @@ function data_set_id_specified(string $projectId): void
'name' => 'Phuket',
'country' => 'Thailand'
];
- # [START fs_set_requires_id]
# [START firestore_data_set_id_specified]
$db->collection('samples/php/cities')->document('new-city-id')->set($data);
# [END firestore_data_set_id_specified]
- # [END fs_set_requires_id]
printf('Added document with ID: new-city-id' . PHP_EOL);
}
diff --git a/firestore/src/data_set_nested_fields.php b/firestore/src/data_set_nested_fields.php
index 6f35137d16..351e4699e5 100644
--- a/firestore/src/data_set_nested_fields.php
+++ b/firestore/src/data_set_nested_fields.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function data_set_nested_fields(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_update_nested_fields]
# [START firestore_data_set_nested_fields]
// Create an initial document to update
$frankRef = $db->collection('samples/php/users')->document('frank');
@@ -53,7 +52,6 @@ function data_set_nested_fields(string $projectId): void
['path' => 'favorites.color', 'value' => 'Red']
]);
# [END firestore_data_set_nested_fields]
- # [END fs_update_nested_fields]
printf('Updated the age and favorite color fields of the frank document in the users collection.' . PHP_EOL);
}
diff --git a/firestore/src/data_set_numeric_increment.php b/firestore/src/data_set_numeric_increment.php
index de23944f05..a09cde5d7f 100644
--- a/firestore/src/data_set_numeric_increment.php
+++ b/firestore/src/data_set_numeric_increment.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,7 +37,6 @@ function data_set_numeric_increment(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_update_doc_increment]
# [START firestore_data_set_numeric_increment]
$cityRef = $db->collection('samples/php/cities')->document('DC');
@@ -46,7 +45,6 @@ function data_set_numeric_increment(string $projectId): void
['path' => 'regions', 'value' => FieldValue::increment(50)]
]);
# [END firestore_data_set_numeric_increment]
- # [END fs_update_doc_increment]
printf('Updated the population of the DC document in the cities collection.' . PHP_EOL);
}
diff --git a/firestore/src/data_set_server_timestamp.php b/firestore/src/data_set_server_timestamp.php
index 102d7c6169..6aaba0de04 100644
--- a/firestore/src/data_set_server_timestamp.php
+++ b/firestore/src/data_set_server_timestamp.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -41,14 +41,12 @@ function data_set_server_timestamp(string $projectId): void
$docRef->set([
'timestamp' => 'N/A'
]);
- # [START fs_update_server_timestamp]
# [START firestore_data_set_server_timestamp]
$docRef = $db->collection('samples/php/objects')->document('some-id');
$docRef->update([
['path' => 'timestamp', 'value' => FieldValue::serverTimestamp()]
]);
# [END firestore_data_set_server_timestamp]
- # [END fs_update_server_timestamp]
printf('Updated the timestamp field of the some-id document in the objects collection.' . PHP_EOL);
}
diff --git a/firestore/src/query_collection_group_dataset.php b/firestore/src/query_collection_group_dataset.php
index 34419d1d9d..97d5b05d69 100644
--- a/firestore/src/query_collection_group_dataset.php
+++ b/firestore/src/query_collection_group_dataset.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,7 +37,6 @@ function query_collection_group_dataset(string $projectId): void
'projectId' => $projectId,
]);
- # [START fs_collection_group_query_data_setup]
# [START firestore_query_collection_group_dataset]
$citiesRef = $db->collection('samples/php/cities');
$citiesRef->document('SF')->collection('landmarks')->newDocument()->set([
@@ -82,7 +81,6 @@ function query_collection_group_dataset(string $projectId): void
]);
print('Added example landmarks collections to the cities collection.' . PHP_EOL);
# [END firestore_query_collection_group_dataset]
- # [END fs_collection_group_query_data_setup]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/query_collection_group_filter_eq.php b/firestore/src/query_collection_group_filter_eq.php
index d06c24e132..1b366d3a98 100644
--- a/firestore/src/query_collection_group_filter_eq.php
+++ b/firestore/src/query_collection_group_filter_eq.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -39,14 +39,12 @@ function query_collection_group_filter_eq(string $projectId): void
'projectId' => $projectId,
]);
- # [START fs_collection_group_query]
# [START firestore_query_collection_group_filter_eq]
$museums = $db->collectionGroup('landmarks')->where('type', '==', 'museum');
foreach ($museums->documents() as $document) {
printf('%s => %s' . PHP_EOL, $document->id(), $document->data()['name']);
}
# [END firestore_query_collection_group_filter_eq]
- # [END fs_collection_group_query]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/query_cursor_end_at_field_value_single.php b/firestore/src/query_cursor_end_at_field_value_single.php
index d1182fcf1f..38e8f84273 100644
--- a/firestore/src/query_cursor_end_at_field_value_single.php
+++ b/firestore/src/query_cursor_end_at_field_value_single.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,13 +37,11 @@ function query_cursor_end_at_field_value_single(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_end_at_field_query_cursor]
# [START firestore_query_cursor_end_at_field_value_single]
$query = $citiesRef
->orderBy('population')
->endAt([1000000]);
# [END firestore_query_cursor_end_at_field_value_single]
- # [END fs_end_at_field_query_cursor]
$snapshot = $query->documents();
foreach ($snapshot as $document) {
printf('Document %s returned by end at population 1000000 field query cursor.' . PHP_EOL, $document->id());
diff --git a/firestore/src/query_cursor_pagination.php b/firestore/src/query_cursor_pagination.php
index ce57153416..a66f00adfa 100644
--- a/firestore/src/query_cursor_pagination.php
+++ b/firestore/src/query_cursor_pagination.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function query_cursor_pagination(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_paginated_query_cursor]
# [START firestore_query_cursor_pagination]
$citiesRef = $db->collection('samples/php/cities');
$firstQuery = $citiesRef->orderBy('population')->limit(3);
@@ -53,7 +52,6 @@ function query_cursor_pagination(string $projectId): void
$nextQuery = $citiesRef->orderBy('population')->startAfter([$lastPopulation]);
$snapshot = $nextQuery->documents();
# [END firestore_query_cursor_pagination]
- # [END fs_paginated_query_cursor]
foreach ($snapshot as $document) {
printf('Document %s returned by paginated query cursor.' . PHP_EOL, $document->id());
}
diff --git a/firestore/src/query_cursor_start_at_document.php b/firestore/src/query_cursor_start_at_document.php
index 0cf7e813b5..27cce51158 100644
--- a/firestore/src/query_cursor_start_at_document.php
+++ b/firestore/src/query_cursor_start_at_document.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function query_cursor_start_at_document(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_start_at_snapshot_query_cursor]
# [START firestore_query_cursor_start_at_document]
$citiesRef = $db->collection('samples/php/cities');
$docRef = $citiesRef->document('SF');
@@ -46,7 +45,6 @@ function query_cursor_start_at_document(string $projectId): void
->orderBy('population')
->startAt($snapshot);
# [END firestore_query_cursor_start_at_document]
- # [END fs_start_at_snapshot_query_cursor]
$snapshot = $query->documents();
foreach ($snapshot as $document) {
printf('Document %s returned by start at SF snapshot query cursor.' . PHP_EOL, $document->id());
diff --git a/firestore/src/query_cursor_start_at_field_value_multi.php b/firestore/src/query_cursor_start_at_field_value_multi.php
index a71b32819f..0f047f45f4 100644
--- a/firestore/src/query_cursor_start_at_field_value_multi.php
+++ b/firestore/src/query_cursor_start_at_field_value_multi.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function query_cursor_start_at_field_value_multi(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_multiple_cursor_conditions]
# [START firestore_query_cursor_start_at_field_value_multi]
// Will return all Springfields
$query1 = $db
@@ -52,7 +51,6 @@ function query_cursor_start_at_field_value_multi(string $projectId): void
->orderBy('state')
->startAt(['Springfield', 'Missouri']);
# [END firestore_query_cursor_start_at_field_value_multi]
- # [END fs_multiple_cursor_conditions]
$snapshot1 = $query1->documents();
foreach ($snapshot1 as $document) {
printf('Document %s returned by start at Springfield query.' . PHP_EOL, $document->id());
diff --git a/firestore/src/query_cursor_start_at_field_value_single.php b/firestore/src/query_cursor_start_at_field_value_single.php
index ecadcffd02..40e69743d6 100644
--- a/firestore/src/query_cursor_start_at_field_value_single.php
+++ b/firestore/src/query_cursor_start_at_field_value_single.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,13 +37,11 @@ function query_cursor_start_at_field_value_single(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_start_at_field_query_cursor]
# [START firestore_query_cursor_start_at_field_value_single]
$query = $citiesRef
->orderBy('population')
->startAt([1000000]);
# [END firestore_query_cursor_start_at_field_value_single]
- # [END fs_start_at_field_query_cursor]
$snapshot = $query->documents();
foreach ($snapshot as $document) {
printf('Document %s returned by start at population 1000000 field query cursor.' . PHP_EOL, $document->id());
diff --git a/firestore/src/query_filter_array_contains.php b/firestore/src/query_filter_array_contains.php
index 2852e23ccf..1aca499285 100644
--- a/firestore/src/query_filter_array_contains.php
+++ b/firestore/src/query_filter_array_contains.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,11 +37,9 @@ function query_filter_array_contains(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_array_membership]
# [START firestore_query_filter_array_contains]
$containsQuery = $citiesRef->where('regions', 'array-contains', 'west_coast');
# [END firestore_query_filter_array_contains]
- # [END fs_array_membership]
foreach ($containsQuery->documents() as $document) {
printf('Document %s returned by query regions array-contains west_coast' . PHP_EOL, $document->id());
}
diff --git a/firestore/src/query_filter_array_contains_any.php b/firestore/src/query_filter_array_contains_any.php
index 3c82c89250..d40932e56b 100644
--- a/firestore/src/query_filter_array_contains_any.php
+++ b/firestore/src/query_filter_array_contains_any.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,11 +37,9 @@ function query_filter_array_contains_any(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_query_filter_array_contains_any]
# [START firestore_query_filter_array_contains_any]
$containsQuery = $citiesRef->where('regions', 'array-contains-any', ['west_coast', 'east_coast']);
# [END firestore_query_filter_array_contains_any]
- # [END fs_query_filter_array_contains_any]
foreach ($containsQuery->documents() as $document) {
printf('Document %s returned by query regions array-contains-any [west_coast, east_coast]' . PHP_EOL, $document->id());
}
diff --git a/firestore/src/query_filter_compound_multi_eq.php b/firestore/src/query_filter_compound_multi_eq.php
index fdb921ce21..004ea5471a 100644
--- a/firestore/src/query_filter_compound_multi_eq.php
+++ b/firestore/src/query_filter_compound_multi_eq.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,13 +37,11 @@ function query_filter_compound_multi_eq(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_chained_query]
# [START firestore_query_filter_compound_multi_eq]
$chainedQuery = $citiesRef
->where('state', '=', 'CA')
->where('name', '=', 'San Francisco');
# [END firestore_query_filter_compound_multi_eq]
- # [END fs_chained_query]
foreach ($chainedQuery->documents() as $document) {
printf('Document %s returned by query state=CA and name=San Francisco' . PHP_EOL, $document->id());
}
diff --git a/firestore/src/query_filter_compound_multi_eq_lt.php b/firestore/src/query_filter_compound_multi_eq_lt.php
index 86b98df194..92adcab11f 100644
--- a/firestore/src/query_filter_compound_multi_eq_lt.php
+++ b/firestore/src/query_filter_compound_multi_eq_lt.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -38,13 +38,11 @@ function query_filter_compound_multi_eq_lt(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_composite_index_chained_query]
# [START firestore_query_filter_compound_multi_eq_lt]
$chainedQuery = $citiesRef
->where('state', '=', 'CA')
->where('population', '<', 1000000);
# [END firestore_query_filter_compound_multi_eq_lt]
- # [END fs_composite_index_chained_query]
foreach ($chainedQuery->documents() as $document) {
printf('Document %s returned by query state=CA and population<1000000' . PHP_EOL, $document->id());
}
diff --git a/firestore/src/query_filter_dataset.php b/firestore/src/query_filter_dataset.php
index e203364ea5..a94d963f05 100644
--- a/firestore/src/query_filter_dataset.php
+++ b/firestore/src/query_filter_dataset.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function query_filter_dataset(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_query_create_examples]
# [START firestore_query_filter_dataset]
$citiesRef = $db->collection('samples/php/cities');
$citiesRef->document('SF')->set([
@@ -81,7 +80,6 @@ function query_filter_dataset(string $projectId): void
]);
printf('Added example cities data to the cities collection.' . PHP_EOL);
# [END firestore_query_filter_dataset]
- # [END fs_query_create_examples]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/query_filter_eq_boolean.php b/firestore/src/query_filter_eq_boolean.php
index 1d827e7bc4..f1069907a3 100644
--- a/firestore/src/query_filter_eq_boolean.php
+++ b/firestore/src/query_filter_eq_boolean.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function query_filter_eq_boolean(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_create_query_capital]
# [START firestore_query_filter_eq_boolean]
$citiesRef = $db->collection('samples/php/cities');
$query = $citiesRef->where('capital', '=', true);
@@ -45,7 +44,6 @@ function query_filter_eq_boolean(string $projectId): void
printf('Document %s returned by query capital=true' . PHP_EOL, $document->id());
}
# [END firestore_query_filter_eq_boolean]
- # [END fs_create_query_capital]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/query_filter_eq_string.php b/firestore/src/query_filter_eq_string.php
index 82ff8742bf..c6b4dc4b2e 100644
--- a/firestore/src/query_filter_eq_string.php
+++ b/firestore/src/query_filter_eq_string.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function query_filter_eq_string(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_create_query_state]
# [START firestore_query_filter_eq_string]
$citiesRef = $db->collection('samples/php/cities');
$query = $citiesRef->where('state', '=', 'CA');
@@ -45,7 +44,6 @@ function query_filter_eq_string(string $projectId): void
printf('Document %s returned by query state=CA' . PHP_EOL, $document->id());
}
# [END firestore_query_filter_eq_string]
- # [END fs_create_query_state]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/query_filter_in.php b/firestore/src/query_filter_in.php
index 421df14d5a..f2f536ab68 100644
--- a/firestore/src/query_filter_in.php
+++ b/firestore/src/query_filter_in.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,11 +37,9 @@ function query_filter_in(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_query_filter_in]
# [START firestore_query_filter_in]
$rangeQuery = $citiesRef->where('country', 'in', ['USA', 'Japan']);
# [END firestore_query_filter_in]
- # [END fs_query_filter_in]
foreach ($rangeQuery->documents() as $document) {
printf('Document %s returned by query country in [USA, Japan]' . PHP_EOL, $document->id());
}
diff --git a/firestore/src/query_filter_in_with_array.php b/firestore/src/query_filter_in_with_array.php
index 3883027546..24fe6121bf 100644
--- a/firestore/src/query_filter_in_with_array.php
+++ b/firestore/src/query_filter_in_with_array.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,11 +37,9 @@ function query_filter_in_with_array(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_query_filter_in_array]
# [START firestore_query_filter_in_with_array]
$rangeQuery = $citiesRef->where('regions', 'in', [['west_coast'], ['east_coast']]);
# [END firestore_query_filter_in_with_array]
- # [END fs_query_filter_in_array]
foreach ($rangeQuery->documents() as $document) {
printf('Document %s returned by query regions in [[west_coast], [east_coast]]' . PHP_EOL, $document->id());
}
diff --git a/firestore/src/query_filter_not_eq.php b/firestore/src/query_filter_not_eq.php
index aa7d4b8690..0903825876 100644
--- a/firestore/src/query_filter_not_eq.php
+++ b/firestore/src/query_filter_not_eq.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
diff --git a/firestore/src/query_filter_not_in.php b/firestore/src/query_filter_not_in.php
index b3ceda9c87..5996717ebc 100644
--- a/firestore/src/query_filter_not_in.php
+++ b/firestore/src/query_filter_not_in.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
diff --git a/firestore/src/query_filter_range_invalid.php b/firestore/src/query_filter_range_invalid.php
index 1090537a73..11902a4d56 100644
--- a/firestore/src/query_filter_range_invalid.php
+++ b/firestore/src/query_filter_range_invalid.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,13 +37,11 @@ function query_filter_range_invalid(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_invalid_range_query]
# [START firestore_query_filter_range_invalid]
$invalidRangeQuery = $citiesRef
->where('state', '>=', 'CA')
->where('population', '>', 1000000);
# [END firestore_query_filter_range_invalid]
- # [END fs_invalid_range_query]
// This will throw an exception
$invalidRangeQuery->documents();
diff --git a/firestore/src/query_filter_range_valid.php b/firestore/src/query_filter_range_valid.php
index 2f0bd64350..5146709f36 100644
--- a/firestore/src/query_filter_range_valid.php
+++ b/firestore/src/query_filter_range_valid.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,13 +37,11 @@ function query_filter_range_valid(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_range_query]
# [START firestore_query_filter_range_valid]
$rangeQuery = $citiesRef
->where('state', '>=', 'CA')
->where('state', '<=', 'IN');
# [END firestore_query_filter_range_valid]
- # [END fs_range_query]
foreach ($rangeQuery->documents() as $document) {
printf('Document %s returned by query CA<=state<=IN' . PHP_EOL, $document->id());
}
diff --git a/firestore/src/query_filter_single_examples.php b/firestore/src/query_filter_single_examples.php
index 0403dcc485..8160cc313e 100644
--- a/firestore/src/query_filter_single_examples.php
+++ b/firestore/src/query_filter_single_examples.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,13 +37,11 @@ function query_filter_single_examples(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_simple_queries]
# [START firestore_query_filter_single_examples]
$stateQuery = $citiesRef->where('state', '=', 'CA');
$populationQuery = $citiesRef->where('population', '>', 1000000);
$nameQuery = $citiesRef->where('name', '>=', 'San Francisco');
# [END firestore_query_filter_single_examples]
- # [END fs_simple_queries]
foreach ($stateQuery->documents() as $document) {
printf('Document %s returned by query state=CA' . PHP_EOL, $document->id());
}
diff --git a/firestore/src/query_order_desc_limit.php b/firestore/src/query_order_desc_limit.php
index 8d10734891..e6923c0782 100644
--- a/firestore/src/query_order_desc_limit.php
+++ b/firestore/src/query_order_desc_limit.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,11 +37,9 @@ function query_order_desc_limit(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_order_by_name_desc_limit_query]
# [START firestore_query_order_desc_limit]
$query = $citiesRef->orderBy('name', 'DESC')->limit(3);
# [END firestore_query_order_desc_limit]
- # [END fs_order_by_name_desc_limit_query]
$snapshot = $query->documents();
foreach ($snapshot as $document) {
printf('Document %s returned by order by name descending with limit query' . PHP_EOL, $document->id());
diff --git a/firestore/src/query_order_field_invalid.php b/firestore/src/query_order_field_invalid.php
index 0fc46ba803..ff9e94a565 100644
--- a/firestore/src/query_order_field_invalid.php
+++ b/firestore/src/query_order_field_invalid.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,13 +37,11 @@ function query_order_field_invalid(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_invalid_range_order_by_query]
# [START firestore_query_order_field_invalid]
$invalidRangeQuery = $citiesRef
->where('population', '>', 2500000)
->orderBy('country');
# [END firestore_query_order_field_invalid]
- # [END fs_invalid_range_order_by_query]
// This will throw an exception
$invalidRangeQuery->documents();
diff --git a/firestore/src/query_order_limit.php b/firestore/src/query_order_limit.php
index f63193f9d3..2183fcfc90 100644
--- a/firestore/src/query_order_limit.php
+++ b/firestore/src/query_order_limit.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,11 +37,9 @@ function query_order_limit(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_order_by_name_limit_query]
# [START firestore_query_order_limit]
$query = $citiesRef->orderBy('name')->limit(3);
# [END firestore_query_order_limit]
- # [END fs_order_by_name_limit_query]
$snapshot = $query->documents();
foreach ($snapshot as $document) {
printf('Document %s returned by order by name with limit query' . PHP_EOL, $document->id());
diff --git a/firestore/src/query_order_limit_field_valid.php b/firestore/src/query_order_limit_field_valid.php
index 816317f060..ad5d2eee6f 100644
--- a/firestore/src/query_order_limit_field_valid.php
+++ b/firestore/src/query_order_limit_field_valid.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,14 +37,12 @@ function query_order_limit_field_valid(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_where_order_by_limit_query]
# [START firestore_query_order_limit_field_valid]
$query = $citiesRef
->where('population', '>', 2500000)
->orderBy('population')
->limit(2);
# [END firestore_query_order_limit_field_valid]
- # [END fs_where_order_by_limit_query]
$snapshot = $query->documents();
foreach ($snapshot as $document) {
printf('Document %s returned by where order by limit query' . PHP_EOL, $document->id());
diff --git a/firestore/src/query_order_multi.php b/firestore/src/query_order_multi.php
index fd74454b1d..feef87dc2b 100644
--- a/firestore/src/query_order_multi.php
+++ b/firestore/src/query_order_multi.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,11 +37,9 @@ function query_order_multi(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_order_by_state_and_population_query]
# [START firestore_query_order_multi]
$query = $citiesRef->orderBy('state')->orderBy('population', 'DESC');
# [END firestore_query_order_multi]
- # [END fs_order_by_state_and_population_query]
$snapshot = $query->documents();
foreach ($snapshot as $document) {
printf('Document %s returned by order by state and descending population query' . PHP_EOL, $document->id());
diff --git a/firestore/src/query_order_with_filter.php b/firestore/src/query_order_with_filter.php
index 0f4b7f445c..4f03e0cd02 100644
--- a/firestore/src/query_order_with_filter.php
+++ b/firestore/src/query_order_with_filter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,13 +37,11 @@ function query_order_with_filter(string $projectId): void
'projectId' => $projectId,
]);
$citiesRef = $db->collection('samples/php/cities');
- # [START fs_range_order_by_query]
# [START firestore_query_order_with_filter]
$query = $citiesRef
->where('population', '>', 2500000)
->orderBy('population');
# [END firestore_query_order_with_filter]
- # [END fs_range_order_by_query]
$snapshot = $query->documents();
foreach ($snapshot as $document) {
printf('Document %s returned by range with order by query' . PHP_EOL, $document->id());
diff --git a/firestore/src/setup_client_create.php b/firestore/src/setup_client_create.php
index 89a4b35bdf..34ec765bf6 100644
--- a/firestore/src/setup_client_create.php
+++ b/firestore/src/setup_client_create.php
@@ -18,12 +18,11 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
-# [START fs_initialize]
# [START firestore_setup_client_create]
use Google\Cloud\Firestore\FirestoreClient;
@@ -47,7 +46,6 @@ function setup_client_create(string $projectId = null)
}
}
# [END firestore_setup_client_create]
-# [END fs_initialize]
// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
diff --git a/firestore/src/setup_client_create_with_project_id.php b/firestore/src/setup_client_create_with_project_id.php
index d349ee325b..35f43f65d2 100644
--- a/firestore/src/setup_client_create_with_project_id.php
+++ b/firestore/src/setup_client_create_with_project_id.php
@@ -18,14 +18,13 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
# TODO(craiglabenz): Remove the `firestore_setup_client_create_with_project_id`
# region tag after consolidating to `firestore_setup_client_create`
-# [START fs_initialize_project_id]
# [START firestore_setup_client_create_with_project_id]
use Google\Cloud\Firestore\FirestoreClient;
@@ -43,7 +42,6 @@ function setup_client_create_with_project_id(string $projectId): void
printf('Created Cloud Firestore client with project ID: %s' . PHP_EOL, $projectId);
}
# [END firestore_setup_client_create_with_project_id]
-# [END fs_initialize_project_id]
# TODO(craiglabenz): Remove the `firestore_setup_client_create_with_project_id`
# region tag after consolidating to `firestore_setup_client_create`
diff --git a/firestore/src/setup_dataset.php b/firestore/src/setup_dataset.php
index 30eed1f28e..f53658fe29 100644
--- a/firestore/src/setup_dataset.php
+++ b/firestore/src/setup_dataset.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function setup_dataset(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_add_data_1]
# [START firestore_setup_dataset_pt1]
$docRef = $db->collection('samples/php/users')->document('alovelace');
$docRef->set([
@@ -46,8 +45,6 @@ function setup_dataset(string $projectId): void
]);
printf('Added data to the lovelace document in the users collection.' . PHP_EOL);
# [END firestore_setup_dataset_pt1]
- # [END fs_add_data_1]
- # [START fs_add_data_2]
# [START firestore_setup_dataset_pt2]
$docRef = $db->collection('samples/php/users')->document('aturing');
$docRef->set([
@@ -58,7 +55,6 @@ function setup_dataset(string $projectId): void
]);
printf('Added data to the aturing document in the users collection.' . PHP_EOL);
# [END firestore_setup_dataset_pt2]
- # [END fs_add_data_2]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/setup_dataset_read.php b/firestore/src/setup_dataset_read.php
index b652c4ceb2..26bc91cdf2 100644
--- a/firestore/src/setup_dataset_read.php
+++ b/firestore/src/setup_dataset_read.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function setup_dataset_read(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_get_all]
# [START firestore_setup_dataset_read]
$usersRef = $db->collection('samples/php/users');
$snapshot = $usersRef->documents();
@@ -52,7 +51,6 @@ function setup_dataset_read(string $projectId): void
}
printf('Retrieved and printed out all documents from the users collection.' . PHP_EOL);
# [END firestore_setup_dataset_read]
- # [END fs_get_all]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/solution_sharded_counter_create.php b/firestore/src/solution_sharded_counter_create.php
index 05a29e9281..6cd896a54c 100644
--- a/firestore/src/solution_sharded_counter_create.php
+++ b/firestore/src/solution_sharded_counter_create.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function solution_sharded_counter_create(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_initialize_distributed_counter]
# [START firestore_solution_sharded_counter_create]
$numShards = 10;
$ref = $db->collection('samples/php/distributedCounters');
@@ -45,7 +44,6 @@ function solution_sharded_counter_create(string $projectId): void
$doc->set(['Cnt' => 0]);
}
# [END firestore_solution_sharded_counter_create]
- # [END fs_initialize_distributed_counter]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/solution_sharded_counter_get.php b/firestore/src/solution_sharded_counter_get.php
index 3b32f9f284..6c29423ead 100644
--- a/firestore/src/solution_sharded_counter_get.php
+++ b/firestore/src/solution_sharded_counter_get.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -36,7 +36,6 @@ function solution_sharded_counter_get(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_get_distributed_counter_value]
# [START firestore_solution_sharded_counter_get]
$result = 0;
$docCollection = $db->collection('samples/php/distributedCounters')->documents();
@@ -44,7 +43,6 @@ function solution_sharded_counter_get(string $projectId): void
$result += $doc->data()['Cnt'];
}
# [END firestore_solution_sharded_counter_get]
- # [END fs_get_distributed_counter_value]
printf('The current value of the distributed counter: %d' . PHP_EOL, $result);
}
diff --git a/firestore/src/solution_sharded_counter_increment.php b/firestore/src/solution_sharded_counter_increment.php
index e92dc19e79..b9981a04c0 100644
--- a/firestore/src/solution_sharded_counter_increment.php
+++ b/firestore/src/solution_sharded_counter_increment.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -38,7 +38,6 @@ function solution_sharded_counter_increment(string $projectId): void
'projectId' => $projectId,
]);
- # [START fs_update_distributed_counter]
# [START firestore_solution_sharded_counter_increment]
$ref = $db->collection('samples/php/distributedCounters');
$numShards = 0;
@@ -52,7 +51,6 @@ function solution_sharded_counter_increment(string $projectId): void
['path' => 'Cnt', 'value' => FieldValue::increment(1)]
]);
# [END firestore_solution_sharded_counter_increment]
- # [END fs_update_distributed_counter]
}
// The following 2 lines are only needed to run the samples
diff --git a/firestore/src/transaction_document_update.php b/firestore/src/transaction_document_update.php
index 697510b4c8..0ecfbf8c12 100644
--- a/firestore/src/transaction_document_update.php
+++ b/firestore/src/transaction_document_update.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,7 +37,6 @@ function transaction_document_update(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_run_simple_transaction]
# [START firestore_transaction_document_update]
$cityRef = $db->collection('samples/php/cities')->document('SF');
$db->runTransaction(function (Transaction $transaction) use ($cityRef) {
@@ -48,7 +47,6 @@ function transaction_document_update(string $projectId): void
]);
});
# [END firestore_transaction_document_update]
- # [END fs_run_simple_transaction]
printf('Ran a simple transaction to update the population field in the SF document in the cities collection.' . PHP_EOL);
}
diff --git a/firestore/src/transaction_document_update_conditional.php b/firestore/src/transaction_document_update_conditional.php
index c2f76ba110..e0e49ea3e2 100644
--- a/firestore/src/transaction_document_update_conditional.php
+++ b/firestore/src/transaction_document_update_conditional.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/firestore/README.md
*/
namespace Google\Cloud\Samples\Firestore;
@@ -37,7 +37,6 @@ function transaction_document_update_conditional(string $projectId): void
$db = new FirestoreClient([
'projectId' => $projectId,
]);
- # [START fs_return_info_transaction]
# [START firestore_transaction_document_update_conditional]
$cityRef = $db->collection('samples/php/cities')->document('SF');
$transactionResult = $db->runTransaction(function (Transaction $transaction) use ($cityRef) {
@@ -59,7 +58,6 @@ function transaction_document_update_conditional(string $projectId): void
printf('Sorry! Population is too big.' . PHP_EOL);
}
# [END firestore_transaction_document_update_conditional]
- # [END fs_return_info_transaction]
}
// The following 2 lines are only needed to run the samples
diff --git a/functions/helloworld_pubsub/SampleUnitTest.php b/functions/helloworld_pubsub/SampleUnitTest.php
index d168645383..a37e50cabd 100644
--- a/functions/helloworld_pubsub/SampleUnitTest.php
+++ b/functions/helloworld_pubsub/SampleUnitTest.php
@@ -18,6 +18,7 @@
declare(strict_types=1);
+// [START functions_cloudevent_pubsub_unit_test]
// [START functions_pubsub_unit_test]
namespace Google\Cloud\Samples\Functions\HelloworldPubsub\Test;
@@ -82,4 +83,5 @@ public function testFunction(
}
}
+// [END functions_cloudevent_pubsub_unit_test]
// [END functions_pubsub_unit_test]
diff --git a/functions/helloworld_pubsub/index.php b/functions/helloworld_pubsub/index.php
index 54aa180183..3aac9ff60f 100644
--- a/functions/helloworld_pubsub/index.php
+++ b/functions/helloworld_pubsub/index.php
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+// [START functions_cloudevent_pubsub]
// [START functions_helloworld_pubsub]
use CloudEvents\V1\CloudEventInterface;
@@ -38,3 +39,4 @@ function helloworldPubsub(CloudEventInterface $event): void
fwrite($log, "Hello, $name!" . PHP_EOL);
}
// [END functions_helloworld_pubsub]
+// [END functions_cloudevent_pubsub]
diff --git a/functions/helloworld_storage/SampleUnitTest.php b/functions/helloworld_storage/SampleUnitTest.php
index 5ac8545830..9ccb6a9a54 100644
--- a/functions/helloworld_storage/SampleUnitTest.php
+++ b/functions/helloworld_storage/SampleUnitTest.php
@@ -19,6 +19,7 @@
declare(strict_types=1);
// [START functions_storage_unit_test]
+// [START functions_cloudevent_storage_unit_test]
namespace Google\Cloud\Samples\Functions\HelloworldStorage\Test;
@@ -89,4 +90,5 @@ public function testFunction(CloudEventInterface $cloudevent): void
}
}
+// [END functions_cloudevent_storage_unit_test]
// [END functions_storage_unit_test]
diff --git a/functions/helloworld_storage/index.php b/functions/helloworld_storage/index.php
index a2a1e5046f..f3e886c027 100644
--- a/functions/helloworld_storage/index.php
+++ b/functions/helloworld_storage/index.php
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+// [START functions_cloudevent_storage]
// [START functions_helloworld_storage]
use CloudEvents\V1\CloudEventInterface;
@@ -41,4 +42,5 @@ function helloGCS(CloudEventInterface $cloudevent)
fwrite($log, 'Updated: ' . $data['updated'] . PHP_EOL);
}
+// [END functions_cloudevent_storage]
// [END functions_helloworld_storage]
diff --git a/iap/README.md b/iap/README.md
index 33c3b5ce74..e6eb93a11a 100644
--- a/iap/README.md
+++ b/iap/README.md
@@ -47,7 +47,7 @@ Usage: validate_jwt.php $iapJwt $expectedAudience
[iap]: http://cloud.google.com/iap
[iap-quickstart]: https://cloud.google.com/iap/docs/app-engine-quickstart
-[iap-app-engine]: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/iap/app_engine_app
+[iap-app-engine]: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/iap/app_engine_app
[iap-enable]: https://cloud.google.com/iap/docs/app-engine-quickstart#enabling_iap
[create-service-account]: https://console.cloud.google.com/iam-admin/serviceaccounts?_ga=2.249998854.-1228762175.1480648951
[iap-manage-access]: https://cloud.google.com/iap/docs/managing-access
diff --git a/iap/src/make_iap_request.php b/iap/src/make_iap_request.php
index beb1372dfa..5ff6289523 100644
--- a/iap/src/make_iap_request.php
+++ b/iap/src/make_iap_request.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/iap/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/iap/README.md
*/
# [START iap_make_request]
diff --git a/iap/src/validate_jwt.php b/iap/src/validate_jwt.php
index 73c8a892fc..91c53e0fbe 100644
--- a/iap/src/validate_jwt.php
+++ b/iap/src/validate_jwt.php
@@ -17,7 +17,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/iap/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/iap/README.md
*/
# [START iap_validate_jwt]
diff --git a/iot/src/set_device_state.php b/iot/src/set_device_state.php
index c8eaa984ea..aca79d572a 100644
--- a/iot/src/set_device_state.php
+++ b/iot/src/set_device_state.php
@@ -22,7 +22,7 @@
use Firebase\JWT\JWT;
/**
- * Set a device's configuration.
+ * Set a device's state.
*
* @param string $registryId IOT Device Registry ID
* @param string $deviceId IOT Device ID
diff --git a/language/composer.json b/language/composer.json
index ee6944dbcf..d519c9ac28 100644
--- a/language/composer.json
+++ b/language/composer.json
@@ -1,6 +1,6 @@
{
"require": {
- "google/cloud-language": "^0.26.0",
+ "google/cloud-language": "^0.27.0",
"google/cloud-storage": "^1.20.1"
}
}
diff --git a/language/src/analyze_all.php b/language/src/analyze_all.php
index 46e43585fb..2b3949a6c3 100644
--- a/language/src/analyze_all.php
+++ b/language/src/analyze_all.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/analyze_all_from_file.php b/language/src/analyze_all_from_file.php
index 0bd1d0ced8..3700f436db 100644
--- a/language/src/analyze_all_from_file.php
+++ b/language/src/analyze_all_from_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/analyze_entities.php b/language/src/analyze_entities.php
index c615601222..aae01e4a20 100644
--- a/language/src/analyze_entities.php
+++ b/language/src/analyze_entities.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/analyze_entities_from_file.php b/language/src/analyze_entities_from_file.php
index 0c086d0ea7..ad46f17d6b 100644
--- a/language/src/analyze_entities_from_file.php
+++ b/language/src/analyze_entities_from_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/analyze_entity_sentiment.php b/language/src/analyze_entity_sentiment.php
index 7bef5c1b98..4b786b15ed 100644
--- a/language/src/analyze_entity_sentiment.php
+++ b/language/src/analyze_entity_sentiment.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/analyze_entity_sentiment_from_file.php b/language/src/analyze_entity_sentiment_from_file.php
index 7f66334062..686b953930 100644
--- a/language/src/analyze_entity_sentiment_from_file.php
+++ b/language/src/analyze_entity_sentiment_from_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/analyze_sentiment.php b/language/src/analyze_sentiment.php
index df71159641..e56ede362d 100644
--- a/language/src/analyze_sentiment.php
+++ b/language/src/analyze_sentiment.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/analyze_sentiment_from_file.php b/language/src/analyze_sentiment_from_file.php
index ca3feda0a8..6e1a166316 100644
--- a/language/src/analyze_sentiment_from_file.php
+++ b/language/src/analyze_sentiment_from_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/analyze_syntax.php b/language/src/analyze_syntax.php
index 1f9ebb7c54..dd47188bd8 100644
--- a/language/src/analyze_syntax.php
+++ b/language/src/analyze_syntax.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/analyze_syntax_from_file.php b/language/src/analyze_syntax_from_file.php
index fb3e367820..76f33bd572 100644
--- a/language/src/analyze_syntax_from_file.php
+++ b/language/src/analyze_syntax_from_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/classify_text.php b/language/src/classify_text.php
index 276f87392b..aceeeb9b64 100644
--- a/language/src/classify_text.php
+++ b/language/src/classify_text.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/language/src/classify_text_from_file.php b/language/src/classify_text_from_file.php
index f122e212e9..b73027eb89 100644
--- a/language/src/classify_text_from_file.php
+++ b/language/src/classify_text_from_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/language/README.md
*/
namespace Google\Cloud\Samples\Language;
diff --git a/logging/README.md b/logging/README.md
index 02728d6043..f062efb9ae 100644
--- a/logging/README.md
+++ b/logging/README.md
@@ -8,9 +8,16 @@
This directory contains samples for calling [Stackdriver Logging][logging]
from PHP.
-`logging.php` is a simple command-line program to demonstrate writing to a log,
-listing its entries, deleting it, interacting with sinks to export logs to
-Google Cloud Storage.
+Execute the snippets in the [src/](src/) directory by running
+`php src/SNIPPET_NAME.php`. The usage will print for each if no arguments
+are provided:
+```sh
+$ php src/list_entries.php
+Usage: php src/list_entries.php PROJECT_ID LOGGER_NAME
+
+$ php src/list_entries.php your-project-id 'your-logger-name'
+[list of entries...]
+```
To use logging sinks, you will also need a Google Cloud Storage Bucket.
@@ -27,11 +34,4 @@ Use the [Cloud SDK](https://cloud.google.com/sdk) to provide authentication:
gcloud beta auth application-default login
-Run the samples:
-
- ```
- php logging.php list # For getting sub command list
- php logging.php help write # For showing help for write sub command `write`
- ```
-
[logging]: https://cloud.google.com/logging/docs/reference/libraries
diff --git a/logging/composer.json b/logging/composer.json
index 45dd9ec6c9..96c11a65f5 100644
--- a/logging/composer.json
+++ b/logging/composer.json
@@ -1,15 +1,6 @@
{
"require": {
"google/cloud-logging": "^1.20.0",
- "symfony/console": "^5.0",
"monolog/monolog": "^2.0"
- },
- "autoload": {
- "files": [
- "src/log_entry_functions.php",
- "src/write_with_psr_logger.php",
- "src/write_with_monolog_logger.php",
- "src/sink_functions.php"
- ]
}
}
diff --git a/logging/logging.php b/logging/logging.php
deleted file mode 100644
index 290dcfdeb2..0000000000
--- a/logging/logging.php
+++ /dev/null
@@ -1,232 +0,0 @@
-add(new Command('create-sink'))
- ->setDefinition(clone $inputDefinition)
- ->setDescription('Creates a Logging sink')
- ->addOption('sink',
- null,
- InputOption::VALUE_OPTIONAL,
- 'The name of the Logging sink',
- 'my_sink'
- )->addOption(
- 'bucket',
- null,
- InputOption::VALUE_REQUIRED,
- 'The destination bucket name'
- )->addOption(
- 'filter',
- null,
- InputOption::VALUE_OPTIONAL,
- 'The filter expression for the sink',
- ''
- )->setCode(function ($input, $output) {
- $projectId = $input->getArgument('project');
- $sinkName = $input->getOption('sink');
- $loggerName = $input->getOption('logger');
- $filter = $input->getOption('filter');
- $bucketName = $input->getOption('bucket');
- $destination = sprintf(
- 'storage.googleapis.com/%s',
- $bucketName
- );
- $loggerFullName = sprintf(
- 'projects/%s/logs/%s',
- $projectId,
- $loggerName
- );
- $filterString = sprintf('logName = "%s"', $loggerFullName);
- if (!empty($filter)) {
- $filterString .= ' AND ' . $filter;
- }
- create_sink($projectId, $sinkName, $destination, $filterString);
- });
-
-$application->add(new Command('delete-logger'))
- ->setDefinition($inputDefinition)
- ->setDescription('Deletes the given logger and its entries')
- ->setCode(function ($input, $output) {
- $projectId = $input->getArgument('project');
- $loggerName = $input->getOption('logger');
- delete_logger($projectId, $loggerName);
- });
-
-$application->add(new Command('delete-sink'))
- ->setDefinition(clone $inputDefinition)
- ->setDescription('Deletes a Logging sink')
- ->addOption(
- 'sink',
- null,
- InputOption::VALUE_OPTIONAL,
- 'The name of the Logging sink',
- 'my_sink'
- )->setCode(function ($input, $output) {
- $projectId = $input->getArgument('project');
- $sinkName = $input->getOption('sink');
- delete_sink($projectId, $sinkName);
- });
-
-$application->add(new Command('list-entries'))
- ->setDefinition($inputDefinition)
- ->setDescription('Lists log entries in the logger')
- ->setCode(function ($input, $output) {
- $projectId = $input->getArgument('project');
- $loggerName = $input->getOption('logger');
- $entries = list_entries($projectId, $loggerName);
- });
-
-$application->add(new Command('list-sinks'))
- ->setDefinition($inputDefinition)
- ->setDescription('Lists sinks')
- ->setCode(function ($input, $output) {
- $projectId = $input->getArgument('project');
- $sinks = list_sinks($projectId);
- });
-
-$application->add(new Command('update-sink'))
- ->setDefinition(clone $inputDefinition)
- ->setDescription('Updates a Logging sink')
- ->addOption(
- 'sink',
- null,
- InputOption::VALUE_OPTIONAL,
- 'The name of the Logging sink',
- 'my_sink'
- )->addOption(
- 'filter',
- null,
- InputOption::VALUE_OPTIONAL,
- 'The filter expression for the sink',
- ''
- )->setCode(function ($input, $output) {
- $projectId = $input->getArgument('project');
- $sinkName = $input->getOption('sink');
- $loggerName = $input->getOption('logger');
- $filter = $input->getOption('filter');
- $loggerFullName = sprintf(
- 'projects/%s/logs/%s',
- $projectId,
- $loggerName
- );
- $filterString = sprintf('logName = "%s"', $loggerFullName);
- if (!empty($filter)) {
- $filterString .= ' AND ' . $filter;
- }
- update_sink($projectId, $sinkName, $filterString);
- });
-
-$application->add(new Command('write'))
- ->setDefinition(clone $inputDefinition)
- ->setDescription('Writes log entries to the given logger')
- ->addArgument(
- 'message',
- InputArgument::OPTIONAL,
- 'The log message to write',
- 'Hello'
- )
- ->setCode(function ($input, $output) {
- $projectId = $input->getArgument('project');
- $message = $input->getArgument('message');
- $loggerName = $input->getOption('logger');
- write_log($projectId, $loggerName, $message);
- });
-
-$application->add(new Command('write-psr'))
- ->setDefinition(clone $inputDefinition)
- ->setDescription('Writes log entries using a PSR logger')
- ->addArgument(
- 'message',
- InputArgument::OPTIONAL,
- 'The log message to write',
- 'Hello'
- )
- ->addOption(
- 'level',
- null,
- InputOption::VALUE_REQUIRED,
- 'The log level for the PSR logger',
- \Psr\Log\LogLevel::WARNING
- )
- ->setCode(function ($input, $output) {
- $projectId = $input->getArgument('project');
- $message = $input->getArgument('message');
- $loggerName = $input->getOption('logger');
- $level = $input->getOption('level');
- write_with_psr_logger($projectId, $loggerName, $message, $level);
- });
-
-$application->add(new Command('write-monolog'))
- ->setDefinition(clone $inputDefinition)
- ->setDescription('Writes log entries using a Monolog logger')
- ->addArgument(
- 'message',
- InputArgument::OPTIONAL,
- 'The log message to write',
- 'Hello'
- )
- ->addOption(
- 'level',
- null,
- InputOption::VALUE_REQUIRED,
- 'The log level for the PSR logger',
- \Psr\Log\LogLevel::WARNING
- )
- ->setCode(function ($input, $output) {
- $projectId = $input->getArgument('project');
- $message = $input->getArgument('message');
- $loggerName = $input->getOption('logger');
- $level = $input->getOption('level');
- write_with_monolog_logger($projectId, $loggerName, $message, $level);
- });
-
-// for testing
-if (getenv('PHPUNIT_TESTS') === '1') {
- return $application;
-}
-
-$application->run();
diff --git a/logging/src/create_sink.php b/logging/src/create_sink.php
new file mode 100644
index 0000000000..54b7c03fd6
--- /dev/null
+++ b/logging/src/create_sink.php
@@ -0,0 +1,45 @@
+ $projectId]);
+ $logging->createSink(
+ $sinkName,
+ $destination,
+ ['filter' => $filterString]
+ );
+ printf("Created a sink '%s'." . PHP_EOL, $sinkName);
+}
+// [END logging_create_sink]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/logging/src/delete_logger.php b/logging/src/delete_logger.php
new file mode 100644
index 0000000000..77ad5122a1
--- /dev/null
+++ b/logging/src/delete_logger.php
@@ -0,0 +1,39 @@
+ $projectId]);
+ $logger = $logging->logger($loggerName);
+ $logger->delete();
+ printf("Deleted a logger '%s'." . PHP_EOL, $loggerName);
+}
+// [END logging_delete_log]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/logging/src/delete_sink.php b/logging/src/delete_sink.php
new file mode 100644
index 0000000000..9cdb1f52bd
--- /dev/null
+++ b/logging/src/delete_sink.php
@@ -0,0 +1,39 @@
+ $projectId]);
+ $logging->sink($sinkName)->delete();
+ printf("Deleted a sink '%s'." . PHP_EOL, $sinkName);
+}
+// [END logging_delete_sink]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/logging/src/log_entry_functions.php b/logging/src/list_entries.php
similarity index 58%
rename from logging/src/log_entry_functions.php
rename to logging/src/list_entries.php
index fce7e4e1c8..68b2a47425 100644
--- a/logging/src/log_entry_functions.php
+++ b/logging/src/list_entries.php
@@ -17,40 +17,9 @@
namespace Google\Cloud\Samples\Logging;
-// [START logging_write_log_entry]
// [START logging_list_log_entries]
-// [START logging_delete_log]
use Google\Cloud\Logging\LoggingClient;
-// [END logging_write_log_entry]
-// [END logging_list_log_entries]
-// [END logging_delete_log]
-
-// [START logging_write_log_entry]
-/** Write a log message via the Stackdriver Logging API.
- *
- * @param string $projectId The Google project ID.
- * @param string $loggerName The name of the logger.
- * @param string $message The log message.
- */
-function write_log($projectId, $loggerName, $message)
-{
- $logging = new LoggingClient(['projectId' => $projectId]);
- $logger = $logging->logger($loggerName, [
- 'resource' => [
- 'type' => 'gcs_bucket',
- 'labels' => [
- 'bucket_name' => 'my_bucket'
- ]
- ]
- ]);
- $entry = $logger->entry($message);
- $logger->write($entry);
- printf("Wrote a log to a logger '%s'." . PHP_EOL, $loggerName);
-}
-// [END logging_write_log_entry]
-
-// [START logging_list_log_entries]
/**
* Print the timestamp and entry for the project and logger.
*
@@ -90,17 +59,6 @@ function list_entries($projectId, $loggerName)
}
// [END logging_list_log_entries]
-// [START logging_delete_log]
-/** Delete a logger and all its entries.
- *
- * @param string $projectId The Google project ID.
- * @param string $loggerName The name of the logger.
- */
-function delete_logger($projectId, $loggerName)
-{
- $logging = new LoggingClient(['projectId' => $projectId]);
- $logger = $logging->logger($loggerName);
- $logger->delete();
- printf("Deleted a logger '%s'." . PHP_EOL, $loggerName);
-}
-// [END logging_delete_log]
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/logging/src/list_sinks.php b/logging/src/list_sinks.php
new file mode 100644
index 0000000000..b3eb138b3e
--- /dev/null
+++ b/logging/src/list_sinks.php
@@ -0,0 +1,47 @@
+ $projectId]);
+ $sinks = $logging->sinks();
+ foreach ($sinks as $sink) {
+ /* @var $sink \Google\Cloud\Logging\Sink */
+ foreach ($sink->info() as $key => $value) {
+ printf('%s:%s' . PHP_EOL,
+ $key,
+ is_string($value) ? $value : var_export($value, true)
+ );
+ }
+ print PHP_EOL;
+ }
+}
+// [END logging_list_sinks]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/logging/src/sink_functions.php b/logging/src/sink_functions.php
deleted file mode 100644
index 8db530ef43..0000000000
--- a/logging/src/sink_functions.php
+++ /dev/null
@@ -1,97 +0,0 @@
- $projectId]);
- $logging->createSink(
- $sinkName,
- $destination,
- ['filter' => $filterString]
- );
- printf("Created a sink '%s'." . PHP_EOL, $sinkName);
-}
-// [END logging_create_sink]
-
-// [START logging_delete_sink]
-/** Delete a log sink.
- *
- * @param string $projectId The Google project ID.
- * @param string $sinkName The name of the sink.
- */
-function delete_sink($projectId, $sinkName)
-{
- $logging = new LoggingClient(['projectId' => $projectId]);
- $logging->sink($sinkName)->delete();
- printf("Deleted a sink '%s'." . PHP_EOL, $sinkName);
-}
-// [END logging_delete_sink]
-
-// [START logging_list_sinks]
-/**
- * List log sinks.
- *
- * @param string $projectId
- */
-function list_sinks($projectId)
-{
- $logging = new LoggingClient(['projectId' => $projectId]);
- $sinks = $logging->sinks();
- foreach ($sinks as $sink) {
- /* @var $sink \Google\Cloud\Logging\Sink */
- foreach ($sink->info() as $key => $value) {
- printf('%s:%s' . PHP_EOL,
- $key,
- is_string($value) ? $value : var_export($value, true)
- );
- }
- print PHP_EOL;
- }
-}
-// [END logging_list_sinks]
-
-// [START logging_update_sink]
-/**
- * Update a log sink.
- *
- * @param string $projectId
- * @param string sinkName
- * @param string $filterString
- */
-function update_sink($projectId, $sinkName, $filterString)
-{
- $logging = new LoggingClient(['projectId' => $projectId]);
- $sink = $logging->sink($sinkName);
- $sink->update(['filter' => $filterString]);
- printf("Updated a sink '%s'." . PHP_EOL, $sinkName);
-}
-// [END logging_update_sink]
diff --git a/logging/src/update_sink.php b/logging/src/update_sink.php
new file mode 100644
index 0000000000..7bbe7f6c37
--- /dev/null
+++ b/logging/src/update_sink.php
@@ -0,0 +1,41 @@
+ $projectId]);
+ $sink = $logging->sink($sinkName);
+ $sink->update(['filter' => $filterString]);
+ printf("Updated a sink '%s'." . PHP_EOL, $sinkName);
+}
+// [END logging_update_sink]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/logging/src/write_log.php b/logging/src/write_log.php
new file mode 100644
index 0000000000..889c4a910a
--- /dev/null
+++ b/logging/src/write_log.php
@@ -0,0 +1,48 @@
+ $projectId]);
+ $logger = $logging->logger($loggerName, [
+ 'resource' => [
+ 'type' => 'gcs_bucket',
+ 'labels' => [
+ 'bucket_name' => 'my_bucket'
+ ]
+ ]
+ ]);
+ $entry = $logger->entry($message);
+ $logger->write($entry);
+ printf("Wrote a log to a logger '%s'." . PHP_EOL, $loggerName);
+}
+// [END logging_write_log_entry]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/logging/src/write_with_monolog_logger.php b/logging/src/write_with_monolog_logger.php
index 4554e4943d..caa5c84a99 100644
--- a/logging/src/write_with_monolog_logger.php
+++ b/logging/src/write_with_monolog_logger.php
@@ -23,14 +23,20 @@
use Monolog\Logger as MonologLogger;
use Psr\Log\LogLevel;
-/** Write a log message via the Stackdriver Logging API.
+/**
+ * Write a log message via the Stackdriver Logging API.
*
* @param string $projectId The Google project ID.
* @param string $loggerName The name of the logger.
* @param string $message The log message.
+ * @param int $level
*/
-function write_with_monolog_logger($projectId, $loggerName, $message, $level = LogLevel::WARNING)
-{
+function write_with_monolog_logger(
+ string $projectId,
+ string $loggerName,
+ string $message,
+ string $level = LogLevel::WARNING
+) {
$logging = new LoggingClient([
'projectId' => $projectId
]);
@@ -49,3 +55,7 @@ function write_with_monolog_logger($projectId, $loggerName, $message, $level = L
printf("Wrote to monolog logger '%s' at level '%s'." . PHP_EOL, $loggerName, $level);
}
// [END write_with_monolog_logger]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/logging/src/write_with_psr_logger.php b/logging/src/write_with_psr_logger.php
index 8f5daf23ee..29ebf7552c 100644
--- a/logging/src/write_with_psr_logger.php
+++ b/logging/src/write_with_psr_logger.php
@@ -21,17 +21,26 @@
use Google\Cloud\Logging\LoggingClient;
use Psr\Log\LogLevel;
-/** Write a log message via the Stackdriver Logging API.
+/**
+ * Write a log message via the Stackdriver Logging API.
*
* @param string $projectId The Google project ID.
* @param string $loggerName The name of the logger.
* @param string $message The log message.
*/
-function write_with_psr_logger($projectId, $loggerName, $message, $level = LogLevel::WARNING)
-{
+function write_with_psr_logger(
+ string $projectId,
+ string $loggerName,
+ string $message,
+ string $level = LogLevel::WARNING
+) {
$logging = new LoggingClient(['projectId' => $projectId]);
$logger = $logging->psrLogger($loggerName);
$logger->log($level, $message);
printf("Wrote to PSR logger '%s' at level '%s'." . PHP_EOL, $loggerName, $level);
}
// [END write_with_psr_logger]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/logging/test/loggingTest.php b/logging/test/loggingTest.php
index ccf7120d6e..66245cad53 100644
--- a/logging/test/loggingTest.php
+++ b/logging/test/loggingTest.php
@@ -19,8 +19,8 @@
use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\TestUtils\TestTrait;
-use Google\Cloud\TestUtils\ExecuteCommandTrait;
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
+use Google\Cloud\TestUtils\ExponentialBackoffTrait;
use PHPUnit\Framework\TestCase;
/**
@@ -29,10 +29,9 @@
class loggingTest extends TestCase
{
use TestTrait;
- use ExecuteCommandTrait;
use EventuallyConsistentTestTrait;
+ use ExponentialBackoffTrait;
- private static $commandFile = __DIR__ . '/../logging.php';
protected static $sinkName;
protected static $loggerName = 'my_test_logger';
@@ -49,11 +48,12 @@ public function setUp(): void
public function testCreateSink()
{
- $output = $this->runCommand('create-sink', [
- 'project' => self::$projectId,
- '--logger' => self::$loggerName,
- '--bucket' => self::$projectId . '/logging',
- '--sink' => self::$sinkName,
+ $loggerFullName = sprintf('projects/%s/logs/%s', self::$projectId, self::$loggerName);
+ $output = $this->runFunctionSnippet('create_sink', [
+ 'projectId' => self::$projectId,
+ 'sinkName' => self::$sinkName,
+ 'destination' => sprintf('storage.googleapis.com/%s/logging', self::$projectId),
+ 'filterString' => sprintf('logName = "%s"', $loggerFullName),
]);
$this->assertEquals(
sprintf("Created a sink '%s'.\n", self::$sinkName),
@@ -66,8 +66,8 @@ public function testCreateSink()
*/
public function testListSinks()
{
- $output = $this->runCommand('list-sinks', [
- 'project' => self::$projectId,
+ $output = $this->runFunctionSnippet('list_sinks', [
+ 'projectId' => self::$projectId,
]);
$this->assertStringContainsString('name:' . self::$sinkName, $output);
}
@@ -77,10 +77,11 @@ public function testListSinks()
*/
public function testUpdateSink()
{
- $output = $this->runCommand('update-sink', [
- 'project' => self::$projectId,
- '--sink' => self::$sinkName,
- '--logger' => 'updated-logger',
+ $loggerFullName = sprintf('projects/%s/logs/updated-logger', self::$projectId);
+ $output = $this->runFunctionSnippet('update_sink', [
+ 'projectId' => self::$projectId,
+ 'sinkName' => self::$sinkName,
+ 'filterString' => sprintf('logName = "%s"', $loggerFullName),
]);
$this->assertEquals(
sprintf("Updated a sink '%s'.\n", self::$sinkName),
@@ -105,10 +106,10 @@ public function testUpdateSink()
*/
public function testUpdateSinkWithFilter()
{
- $output = $this->runCommand('update-sink', [
- 'project' => self::$projectId,
- '--sink' => self::$sinkName,
- '--filter' => 'severity >= INFO',
+ $output = $this->runFunctionSnippet('update_sink', [
+ 'projectId' => self::$projectId,
+ 'sinkName' => self::$sinkName,
+ 'filterString' => 'severity >= INFO',
]);
$this->assertEquals(
sprintf("Updated a sink '%s'.\n", self::$sinkName),
@@ -126,9 +127,9 @@ public function testUpdateSinkWithFilter()
*/
public function testDeleteSink()
{
- $output = $this->runCommand('delete-sink', [
- 'project' => self::$projectId,
- '--sink' => self::$sinkName,
+ $output = $this->runFunctionSnippet('delete_sink', [
+ 'projectId' => self::$projectId,
+ 'sinkName' => self::$sinkName,
]);
$this->assertEquals(
sprintf("Deleted a sink '%s'.\n", self::$sinkName),
@@ -139,10 +140,10 @@ public function testDeleteSink()
public function testWriteAndList()
{
$message = sprintf('Test Message %s', uniqid());
- $output = $this->runCommand('write', [
- 'project' => self::$projectId,
+ $output = $this->runFunctionSnippet('write_log', [
+ 'projectId' => self::$projectId,
+ 'loggerName' => self::$loggerName,
'message' => $message,
- '--logger' => self::$loggerName,
]);
$this->assertEquals(
sprintf("Wrote a log to a logger '%s'.\n", self::$loggerName),
@@ -151,9 +152,9 @@ public function testWriteAndList()
$loggerName = self::$loggerName;
$this->runEventuallyConsistentTest(function () use ($loggerName, $message) {
- $output = $this->runCommand('list-entries', [
- 'project' => self::$projectId,
- '--logger' => $loggerName,
+ $output = $this->runFunctionSnippet('list_entries', [
+ 'projectId' => self::$projectId,
+ 'loggerName' => $loggerName,
]);
$this->assertStringContainsString($message, $output);
}, $retries = 10);
@@ -164,9 +165,9 @@ public function testWriteAndList()
*/
public function testDeleteLogger()
{
- $output = $this->runCommand('delete-logger', [
- 'project' => self::$projectId,
- '--logger' => self::$loggerName,
+ $output = $this->runFunctionSnippet('delete_logger', [
+ 'projectId' => self::$projectId,
+ 'loggerName' => self::$loggerName,
]);
$this->assertEquals(
sprintf("Deleted a logger '%s'.\n", self::$loggerName),
@@ -177,11 +178,11 @@ public function testDeleteLogger()
public function testWritePsr()
{
$message = 'Test Message';
- $output = $this->runCommand('write-psr', [
- 'project' => self::$projectId,
+ $output = $this->runFunctionSnippet('write_with_psr_logger', [
+ 'projectId' => self::$projectId,
+ 'loggerName' => self::$loggerName,
'message' => $message,
- '--logger' => self::$loggerName,
- '--level' => 'emergency',
+ 'level' => 'emergency',
]);
$this->assertEquals(
sprintf("Wrote to PSR logger '%s' at level 'emergency'.\n", self::$loggerName),
@@ -192,11 +193,11 @@ public function testWritePsr()
public function testWriteMonolog()
{
$message = 'Test Message';
- $output = $this->runCommand('write-monolog', [
- 'project' => self::$projectId,
+ $output = $this->runFunctionSnippet('write_with_monolog_logger', [
+ 'projectId' => self::$projectId,
+ 'loggerName' => self::$loggerName,
'message' => $message,
- '--logger' => self::$loggerName,
- '--level' => 'emergency',
+ 'level' => 'emergency',
]);
$this->assertEquals(
sprintf("Wrote to monolog logger '%s' at level 'emergency'.\n", self::$loggerName),
diff --git a/media/transcoder/src/create_job_from_ad_hoc.php b/media/transcoder/src/create_job_from_ad_hoc.php
index 96d25fd8f4..294401a755 100644
--- a/media/transcoder/src/create_job_from_ad_hoc.php
+++ b/media/transcoder/src/create_job_from_ad_hoc.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/create_job_from_preset.php b/media/transcoder/src/create_job_from_preset.php
index 2ec16b8b37..ef9a8b2216 100644
--- a/media/transcoder/src/create_job_from_preset.php
+++ b/media/transcoder/src/create_job_from_preset.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/create_job_from_template.php b/media/transcoder/src/create_job_from_template.php
index dc5ade47e0..811866daa4 100644
--- a/media/transcoder/src/create_job_from_template.php
+++ b/media/transcoder/src/create_job_from_template.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/create_job_template.php b/media/transcoder/src/create_job_template.php
index cffa891cf8..debbe4184a 100644
--- a/media/transcoder/src/create_job_template.php
+++ b/media/transcoder/src/create_job_template.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/create_job_with_animated_overlay.php b/media/transcoder/src/create_job_with_animated_overlay.php
index 4f4138fd73..3fbc97aaf8 100644
--- a/media/transcoder/src/create_job_with_animated_overlay.php
+++ b/media/transcoder/src/create_job_with_animated_overlay.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/create_job_with_concatenated_inputs.php b/media/transcoder/src/create_job_with_concatenated_inputs.php
index ad304c4b12..ab9d5a553d 100644
--- a/media/transcoder/src/create_job_with_concatenated_inputs.php
+++ b/media/transcoder/src/create_job_with_concatenated_inputs.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/create_job_with_periodic_images_spritesheet.php b/media/transcoder/src/create_job_with_periodic_images_spritesheet.php
index 944c683916..9baf2d6088 100644
--- a/media/transcoder/src/create_job_with_periodic_images_spritesheet.php
+++ b/media/transcoder/src/create_job_with_periodic_images_spritesheet.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/create_job_with_set_number_images_spritesheet.php b/media/transcoder/src/create_job_with_set_number_images_spritesheet.php
index f58591cfc8..5051e7b4b1 100644
--- a/media/transcoder/src/create_job_with_set_number_images_spritesheet.php
+++ b/media/transcoder/src/create_job_with_set_number_images_spritesheet.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/create_job_with_static_overlay.php b/media/transcoder/src/create_job_with_static_overlay.php
index 8ba1e1eeb6..dae4758101 100644
--- a/media/transcoder/src/create_job_with_static_overlay.php
+++ b/media/transcoder/src/create_job_with_static_overlay.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/delete_job.php b/media/transcoder/src/delete_job.php
index a492163909..5be6cf30a0 100644
--- a/media/transcoder/src/delete_job.php
+++ b/media/transcoder/src/delete_job.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/delete_job_template.php b/media/transcoder/src/delete_job_template.php
index 9f31ffaea9..9071b84bb6 100644
--- a/media/transcoder/src/delete_job_template.php
+++ b/media/transcoder/src/delete_job_template.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/get_job.php b/media/transcoder/src/get_job.php
index 55fa92611a..5b26ed530c 100644
--- a/media/transcoder/src/get_job.php
+++ b/media/transcoder/src/get_job.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/get_job_state.php b/media/transcoder/src/get_job_state.php
index 4a24a899fa..2f4331bad6 100644
--- a/media/transcoder/src/get_job_state.php
+++ b/media/transcoder/src/get_job_state.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/get_job_template.php b/media/transcoder/src/get_job_template.php
index f4aca36f40..e03e8238cf 100644
--- a/media/transcoder/src/get_job_template.php
+++ b/media/transcoder/src/get_job_template.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/list_job_templates.php b/media/transcoder/src/list_job_templates.php
index ec9a3767f2..18e0ae7230 100644
--- a/media/transcoder/src/list_job_templates.php
+++ b/media/transcoder/src/list_job_templates.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/transcoder/src/list_jobs.php b/media/transcoder/src/list_jobs.php
index 7bd44d7643..b890568400 100644
--- a/media/transcoder/src/list_jobs.php
+++ b/media/transcoder/src/list_jobs.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/transcoder/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/media/transcoder/README.md
*/
namespace Google\Cloud\Samples\Media\Transcoder;
diff --git a/media/videostitcher/README.md b/media/videostitcher/README.md
new file mode 100644
index 0000000000..bae372e4ef
--- /dev/null
+++ b/media/videostitcher/README.md
@@ -0,0 +1,56 @@
+# Google Cloud Video Stitcher PHP Sample Application
+
+[![Open in Cloud Shell][shell_img]][shell_link]
+
+[shell_img]: http://gstatic.com/cloudssh/images/open-btn.svg
+[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googlecloudplatform/php-docs-samples&page=editor&working_dir=media/videostitcher
+
+## Description
+
+This simple command-line application demonstrates how to invoke
+[Cloud Video Stitcher API][videostitcher-api] from PHP.
+
+[videostitcher-api]: https://cloud.google.com/video-stitcher/docs/reference/libraries
+
+## Build and Run
+1. **Enable APIs** - [Enable the Video Stitcher API](
+ https://console.cloud.google.com/flows/enableapi?apiid=videostitcher.googleapis.com)
+ and create a new project or select an existing project.
+2. **Download The Credentials** - Click "Go to credentials" after enabling the APIs. Click
+ "New Credentials"
+ and select "Service Account Key". Create a new service account, use the JSON key type, and
+ select "Create". Once downloaded, set the environment variable `GOOGLE_APPLICATION_CREDENTIALS`
+ to the path of the JSON key that was downloaded.
+3. **Clone the repo** and cd into this directory
+```
+ $ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
+ $ cd media/videostitcher
+```
+4. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md).
+ Run `php composer.phar install` (if composer is installed locally) or `composer install`
+ (if composer is installed globally).
+5. Execute the snippets in the [src/](src/) directory by running
+ `php src/SNIPPET_NAME.php`. The usage will print for each if no arguments
+ are provided:
+ ```sh
+ $ php src/create_slate.php
+ Usage: create_slate.php $callingProjectId $location $slateId $slateUri
+
+ @param string $callingProjectId The project ID to run the API call under
+ @param string $location The location of the slate
+ @param string $slateId The name of the slate to be created
+ @param string $slateUri The public URI for an MP4 video with at least one audio track
+
+ $ php create_slate.php my-project us-central1 my-slate https://storage.googleapis.com/my-bucket/my-slate.mp4
+ Slate: projects/123456789012/locations/us-central1/slates/my-slate
+ ```
+
+See the [Video Stitcher Documentation](https://cloud.google.com/video-stitcher/docs/) for more information.
+
+## Contributing changes
+
+* See [CONTRIBUTING.md](../../CONTRIBUTING.md)
+
+## Licensing
+
+* See [LICENSE](../../LICENSE)
diff --git a/media/videostitcher/composer.json b/media/videostitcher/composer.json
new file mode 100644
index 0000000000..15a32e7306
--- /dev/null
+++ b/media/videostitcher/composer.json
@@ -0,0 +1,7 @@
+{
+ "name": "google/video-stitcher-sample",
+ "type": "project",
+ "require": {
+ "google/cloud-video-stitcher": "^0.3.0"
+ }
+}
diff --git a/media/videostitcher/phpunit.xml.dist b/media/videostitcher/phpunit.xml.dist
new file mode 100644
index 0000000000..8f577f7ac2
--- /dev/null
+++ b/media/videostitcher/phpunit.xml.dist
@@ -0,0 +1,37 @@
+
+
+
+
+
+ test
+
+
+
+
+
+
+
+ ./src
+
+ ./vendor
+
+
+
+
+
+
+
diff --git a/media/videostitcher/src/create_slate.php b/media/videostitcher/src/create_slate.php
new file mode 100644
index 0000000000..aa54715bd7
--- /dev/null
+++ b/media/videostitcher/src/create_slate.php
@@ -0,0 +1,62 @@
+locationName($callingProjectId, $location);
+ $slate = new Slate();
+ $slate->setUri($slateUri);
+
+ // Run slate creation request
+ $response = $stitcherClient->createSlate($parent, $slateId, $slate);
+
+ // Print results
+ printf('Slate: %s' . PHP_EOL, $response->getName());
+}
+// [END videostitcher_create_slate]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/media/videostitcher/src/delete_slate.php b/media/videostitcher/src/delete_slate.php
new file mode 100644
index 0000000000..81eb1c5069
--- /dev/null
+++ b/media/videostitcher/src/delete_slate.php
@@ -0,0 +1,55 @@
+slateName($callingProjectId, $location, $slateId);
+ $stitcherClient->deleteSlate($formattedName);
+
+ // Print status
+ printf('Deleted slate %s' . PHP_EOL, $slateId);
+}
+// [END videostitcher_delete_slate]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/media/videostitcher/src/get_slate.php b/media/videostitcher/src/get_slate.php
new file mode 100644
index 0000000000..e9b3c15a13
--- /dev/null
+++ b/media/videostitcher/src/get_slate.php
@@ -0,0 +1,55 @@
+slateName($callingProjectId, $location, $slateId);
+ $slate = $stitcherClient->getSlate($formattedName);
+
+ // Print results
+ printf('Slate: %s' . PHP_EOL, $slate->getName());
+}
+// [END videostitcher_get_slate]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/media/videostitcher/src/list_slates.php b/media/videostitcher/src/list_slates.php
new file mode 100644
index 0000000000..96fd0fabaf
--- /dev/null
+++ b/media/videostitcher/src/list_slates.php
@@ -0,0 +1,57 @@
+locationName($callingProjectId, $location);
+ $response = $stitcherClient->listSlates($parent);
+
+ // Print the slate list.
+ $slates = $response->iterateAllElements();
+ print('Slates:' . PHP_EOL);
+ foreach ($slates as $slate) {
+ printf('%s' . PHP_EOL, $slate->getName());
+ }
+}
+// [END videostitcher_list_slates]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/media/videostitcher/src/update_slate.php b/media/videostitcher/src/update_slate.php
new file mode 100644
index 0000000000..857398421c
--- /dev/null
+++ b/media/videostitcher/src/update_slate.php
@@ -0,0 +1,67 @@
+slateName($callingProjectId, $location, $slateId);
+ $slate = new Slate();
+ $slate->setName($formattedName);
+ $slate->setUri($slateUri);
+ $updateMask = new FieldMask([
+ 'paths' => ['uri']
+ ]);
+
+ // Run slate update request
+ $response = $stitcherClient->updateSlate($slate, $updateMask);
+
+ // Print results
+ printf('Updated slate: %s' . PHP_EOL, $response->getName());
+}
+// [END videostitcher_update_slate]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/media/videostitcher/test/videoStitcherTest.php b/media/videostitcher/test/videoStitcherTest.php
new file mode 100644
index 0000000000..b9fa29ecc0
--- /dev/null
+++ b/media/videostitcher/test/videoStitcherTest.php
@@ -0,0 +1,121 @@
+runFunctionSnippet('create_slate', [
+ self::$projectId,
+ self::$location,
+ $slateId,
+ self::$slateUri
+ ]);
+ $this->assertStringContainsString($slateName, $output);
+
+ $output = $this->runFunctionSnippet('get_slate', [
+ self::$projectId,
+ self::$location,
+ $slateId
+ ]);
+ $this->assertStringContainsString($slateName, $output);
+
+ $output = $this->runFunctionSnippet('list_slates', [
+ self::$projectId,
+ self::$location
+ ]);
+ $this->assertStringContainsString($slateName, $output);
+
+ $output = $this->runFunctionSnippet('update_slate', [
+ self::$projectId,
+ self::$location,
+ $slateId,
+ self::$updatedSlateUri
+ ]);
+ $this->assertStringContainsString($slateName, $output);
+
+ $output = $this->runFunctionSnippet('delete_slate', [
+ self::$projectId,
+ self::$location,
+ $slateId
+ ]);
+ $this->assertStringContainsString('Deleted slate', $output);
+ }
+
+ private static function deleteOldSlates(): void
+ {
+ $stitcherClient = new VideoStitcherServiceClient();
+ $parent = $stitcherClient->locationName(self::$projectId, self::$location);
+ $response = $stitcherClient->listSlates($parent);
+ $slates = $response->iterateAllElements();
+
+ $currentTime = time();
+ $oneHourInSecs = 60 * 60 * 1;
+
+ foreach ($slates as $slate) {
+ $tmp = explode('/', $slate->getName());
+ $id = end($tmp);
+ $tmp = explode('-', $id);
+ $timestamp = intval(end($tmp));
+
+ if ($currentTime - $timestamp >= $oneHourInSecs) {
+ $stitcherClient->deleteSlate($slate->getName());
+ }
+ }
+ }
+}
diff --git a/monitoring/src/alert_backup_policies.php b/monitoring/src/alert_backup_policies.php
index 1a8918e280..32c100fe68 100644
--- a/monitoring/src/alert_backup_policies.php
+++ b/monitoring/src/alert_backup_policies.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/alert_create_channel.php b/monitoring/src/alert_create_channel.php
index ecb0adc44c..3e6faaff2b 100644
--- a/monitoring/src/alert_create_channel.php
+++ b/monitoring/src/alert_create_channel.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/alert_create_policy.php b/monitoring/src/alert_create_policy.php
index 9f587b4fb7..b69ffc344e 100644
--- a/monitoring/src/alert_create_policy.php
+++ b/monitoring/src/alert_create_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/alert_delete_channel.php b/monitoring/src/alert_delete_channel.php
index 8f5c76fc89..97faadd38c 100644
--- a/monitoring/src/alert_delete_channel.php
+++ b/monitoring/src/alert_delete_channel.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/alert_enable_policies.php b/monitoring/src/alert_enable_policies.php
index e3fc61a59d..7f5102933d 100644
--- a/monitoring/src/alert_enable_policies.php
+++ b/monitoring/src/alert_enable_policies.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/alert_list_channels.php b/monitoring/src/alert_list_channels.php
index 3f49451fe9..2512c7d9d5 100644
--- a/monitoring/src/alert_list_channels.php
+++ b/monitoring/src/alert_list_channels.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/alert_list_policies.php b/monitoring/src/alert_list_policies.php
index a7e997de24..651a3bcf17 100644
--- a/monitoring/src/alert_list_policies.php
+++ b/monitoring/src/alert_list_policies.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/alert_replace_channels.php b/monitoring/src/alert_replace_channels.php
index 76cbe4ee46..9113333032 100644
--- a/monitoring/src/alert_replace_channels.php
+++ b/monitoring/src/alert_replace_channels.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/alert_restore_policies.php b/monitoring/src/alert_restore_policies.php
index 2722a6a791..de5f3caf50 100644
--- a/monitoring/src/alert_restore_policies.php
+++ b/monitoring/src/alert_restore_policies.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/create_metric.php b/monitoring/src/create_metric.php
index f8cf4d7a97..f54c250d8b 100644
--- a/monitoring/src/create_metric.php
+++ b/monitoring/src/create_metric.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/create_uptime_check.php b/monitoring/src/create_uptime_check.php
index f842514771..cc134ef3da 100644
--- a/monitoring/src/create_uptime_check.php
+++ b/monitoring/src/create_uptime_check.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/delete_metric.php b/monitoring/src/delete_metric.php
index 9dd8acbe79..733e9ad301 100644
--- a/monitoring/src/delete_metric.php
+++ b/monitoring/src/delete_metric.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/delete_uptime_check.php b/monitoring/src/delete_uptime_check.php
index 077ea5b6ab..2c53443e24 100644
--- a/monitoring/src/delete_uptime_check.php
+++ b/monitoring/src/delete_uptime_check.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/get_descriptor.php b/monitoring/src/get_descriptor.php
index ccebd7e45c..1f26fb4d66 100644
--- a/monitoring/src/get_descriptor.php
+++ b/monitoring/src/get_descriptor.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/get_resource.php b/monitoring/src/get_resource.php
index bee985f901..0ed709066f 100644
--- a/monitoring/src/get_resource.php
+++ b/monitoring/src/get_resource.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/get_uptime_check.php b/monitoring/src/get_uptime_check.php
index 6c3f8a0aa9..36c4e26e8e 100644
--- a/monitoring/src/get_uptime_check.php
+++ b/monitoring/src/get_uptime_check.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/list_descriptors.php b/monitoring/src/list_descriptors.php
index 075639344d..93b3ed4b18 100644
--- a/monitoring/src/list_descriptors.php
+++ b/monitoring/src/list_descriptors.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/list_resources.php b/monitoring/src/list_resources.php
index ef05535151..3b9f46f8de 100644
--- a/monitoring/src/list_resources.php
+++ b/monitoring/src/list_resources.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/list_uptime_check_ips.php b/monitoring/src/list_uptime_check_ips.php
index b8a74c0f0f..2181b62939 100644
--- a/monitoring/src/list_uptime_check_ips.php
+++ b/monitoring/src/list_uptime_check_ips.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/list_uptime_checks.php b/monitoring/src/list_uptime_checks.php
index 2c0e2e9f1b..5f2e8d629f 100644
--- a/monitoring/src/list_uptime_checks.php
+++ b/monitoring/src/list_uptime_checks.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/read_timeseries_align.php b/monitoring/src/read_timeseries_align.php
index 021cd58d08..07c511e639 100644
--- a/monitoring/src/read_timeseries_align.php
+++ b/monitoring/src/read_timeseries_align.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/read_timeseries_fields.php b/monitoring/src/read_timeseries_fields.php
index ef271d0da5..11a588560d 100644
--- a/monitoring/src/read_timeseries_fields.php
+++ b/monitoring/src/read_timeseries_fields.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/read_timeseries_reduce.php b/monitoring/src/read_timeseries_reduce.php
index 7eddd886a6..de6b9212ac 100644
--- a/monitoring/src/read_timeseries_reduce.php
+++ b/monitoring/src/read_timeseries_reduce.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/read_timeseries_simple.php b/monitoring/src/read_timeseries_simple.php
index 05acc4b31e..3f999e26be 100644
--- a/monitoring/src/read_timeseries_simple.php
+++ b/monitoring/src/read_timeseries_simple.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/update_uptime_check.php b/monitoring/src/update_uptime_check.php
index e69cc6206d..214798bd59 100644
--- a/monitoring/src/update_uptime_check.php
+++ b/monitoring/src/update_uptime_check.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/monitoring/src/write_timeseries.php b/monitoring/src/write_timeseries.php
index 3c0a854976..3c511d4521 100644
--- a/monitoring/src/write_timeseries.php
+++ b/monitoring/src/write_timeseries.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/monitoring/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/monitoring/README.md
*/
namespace Google\Cloud\Samples\Monitoring;
diff --git a/pubsub/api/src/create_avro_schema.php b/pubsub/api/src/create_avro_schema.php
index 2955e6513d..54ed913505 100644
--- a/pubsub/api/src/create_avro_schema.php
+++ b/pubsub/api/src/create_avro_schema.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/create_bigquery_subscription.php b/pubsub/api/src/create_bigquery_subscription.php
index 3727a4dcbb..6c3e54b8c8 100644
--- a/pubsub/api/src/create_bigquery_subscription.php
+++ b/pubsub/api/src/create_bigquery_subscription.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/create_proto_schema.php b/pubsub/api/src/create_proto_schema.php
index b907a7b0b8..b6e5b3b93e 100644
--- a/pubsub/api/src/create_proto_schema.php
+++ b/pubsub/api/src/create_proto_schema.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/create_push_subscription.php b/pubsub/api/src/create_push_subscription.php
index 037d2bbae8..a3e1f71964 100644
--- a/pubsub/api/src/create_push_subscription.php
+++ b/pubsub/api/src/create_push_subscription.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/create_subscription.php b/pubsub/api/src/create_subscription.php
index 4bf8bb0df9..a8eef665d1 100644
--- a/pubsub/api/src/create_subscription.php
+++ b/pubsub/api/src/create_subscription.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/create_subscription_with_exactly_once_delivery.php b/pubsub/api/src/create_subscription_with_exactly_once_delivery.php
index f4ebda53eb..8d986aa14c 100644
--- a/pubsub/api/src/create_subscription_with_exactly_once_delivery.php
+++ b/pubsub/api/src/create_subscription_with_exactly_once_delivery.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/create_subscription_with_filter.php b/pubsub/api/src/create_subscription_with_filter.php
index d59e6d2966..fcd6436ce5 100644
--- a/pubsub/api/src/create_subscription_with_filter.php
+++ b/pubsub/api/src/create_subscription_with_filter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/create_topic.php b/pubsub/api/src/create_topic.php
index adf5b24de0..fd251ad97f 100644
--- a/pubsub/api/src/create_topic.php
+++ b/pubsub/api/src/create_topic.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/create_topic_with_schema.php b/pubsub/api/src/create_topic_with_schema.php
index 482b7c7eae..26aebf8902 100644
--- a/pubsub/api/src/create_topic_with_schema.php
+++ b/pubsub/api/src/create_topic_with_schema.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/dead_letter_create_subscription.php b/pubsub/api/src/dead_letter_create_subscription.php
index d18f2a4400..b796a51422 100644
--- a/pubsub/api/src/dead_letter_create_subscription.php
+++ b/pubsub/api/src/dead_letter_create_subscription.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/dead_letter_delivery_attempt.php b/pubsub/api/src/dead_letter_delivery_attempt.php
index b9adc7e071..b3cb80c5b7 100644
--- a/pubsub/api/src/dead_letter_delivery_attempt.php
+++ b/pubsub/api/src/dead_letter_delivery_attempt.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/dead_letter_remove.php b/pubsub/api/src/dead_letter_remove.php
index a947836950..d0787310c0 100644
--- a/pubsub/api/src/dead_letter_remove.php
+++ b/pubsub/api/src/dead_letter_remove.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/dead_letter_update_subscription.php b/pubsub/api/src/dead_letter_update_subscription.php
index 6293471a0f..655b4c07d8 100644
--- a/pubsub/api/src/dead_letter_update_subscription.php
+++ b/pubsub/api/src/dead_letter_update_subscription.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/delete_schema.php b/pubsub/api/src/delete_schema.php
index ea14d258c1..5fa85897ba 100644
--- a/pubsub/api/src/delete_schema.php
+++ b/pubsub/api/src/delete_schema.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/delete_subscription.php b/pubsub/api/src/delete_subscription.php
index 1bd1227a70..4db6698a82 100644
--- a/pubsub/api/src/delete_subscription.php
+++ b/pubsub/api/src/delete_subscription.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/delete_topic.php b/pubsub/api/src/delete_topic.php
index 3a0fff976a..d744683796 100644
--- a/pubsub/api/src/delete_topic.php
+++ b/pubsub/api/src/delete_topic.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/detach_subscription.php b/pubsub/api/src/detach_subscription.php
index 2c6ac5d85f..e99d24177a 100644
--- a/pubsub/api/src/detach_subscription.php
+++ b/pubsub/api/src/detach_subscription.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/get_schema.php b/pubsub/api/src/get_schema.php
index 9adb1e15c9..583b15f825 100644
--- a/pubsub/api/src/get_schema.php
+++ b/pubsub/api/src/get_schema.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/get_subscription_policy.php b/pubsub/api/src/get_subscription_policy.php
index 11730a75ee..325444687c 100644
--- a/pubsub/api/src/get_subscription_policy.php
+++ b/pubsub/api/src/get_subscription_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/get_topic_policy.php b/pubsub/api/src/get_topic_policy.php
index 186cd052a2..de74a36452 100644
--- a/pubsub/api/src/get_topic_policy.php
+++ b/pubsub/api/src/get_topic_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/list_schemas.php b/pubsub/api/src/list_schemas.php
index 061e572921..cac80b989e 100644
--- a/pubsub/api/src/list_schemas.php
+++ b/pubsub/api/src/list_schemas.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/list_subscriptions.php b/pubsub/api/src/list_subscriptions.php
index 94ae8234a3..39522d4585 100644
--- a/pubsub/api/src/list_subscriptions.php
+++ b/pubsub/api/src/list_subscriptions.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/list_topics.php b/pubsub/api/src/list_topics.php
index be679cb3ce..c3dd52f3ec 100644
--- a/pubsub/api/src/list_topics.php
+++ b/pubsub/api/src/list_topics.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/publish_avro_records.php b/pubsub/api/src/publish_avro_records.php
index 5015453f9c..9a10f10530 100644
--- a/pubsub/api/src/publish_avro_records.php
+++ b/pubsub/api/src/publish_avro_records.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/publish_message.php b/pubsub/api/src/publish_message.php
index 4eca7bb141..2f8c33624b 100644
--- a/pubsub/api/src/publish_message.php
+++ b/pubsub/api/src/publish_message.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/publish_message_batch.php b/pubsub/api/src/publish_message_batch.php
index 946ff1e8fb..e43f0dffc9 100644
--- a/pubsub/api/src/publish_message_batch.php
+++ b/pubsub/api/src/publish_message_batch.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/publish_proto_messages.php b/pubsub/api/src/publish_proto_messages.php
index be53a6a1b1..5f36cc51ce 100644
--- a/pubsub/api/src/publish_proto_messages.php
+++ b/pubsub/api/src/publish_proto_messages.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/pubsub_client.php b/pubsub/api/src/pubsub_client.php
index 26e7c610d2..8f35a5eeb8 100644
--- a/pubsub/api/src/pubsub_client.php
+++ b/pubsub/api/src/pubsub_client.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/pull_messages.php b/pubsub/api/src/pull_messages.php
index 36abed9c55..4b9f6d06aa 100644
--- a/pubsub/api/src/pull_messages.php
+++ b/pubsub/api/src/pull_messages.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/set_subscription_policy.php b/pubsub/api/src/set_subscription_policy.php
index 7043145cfa..a945880d93 100644
--- a/pubsub/api/src/set_subscription_policy.php
+++ b/pubsub/api/src/set_subscription_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/set_topic_policy.php b/pubsub/api/src/set_topic_policy.php
index b8fe331d66..e70010169d 100644
--- a/pubsub/api/src/set_topic_policy.php
+++ b/pubsub/api/src/set_topic_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/subscribe_avro_records.php b/pubsub/api/src/subscribe_avro_records.php
index e56def3cdf..f979341891 100644
--- a/pubsub/api/src/subscribe_avro_records.php
+++ b/pubsub/api/src/subscribe_avro_records.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/subscribe_exactly_once_delivery.php b/pubsub/api/src/subscribe_exactly_once_delivery.php
index 63cb3e927f..1c33c16e14 100644
--- a/pubsub/api/src/subscribe_exactly_once_delivery.php
+++ b/pubsub/api/src/subscribe_exactly_once_delivery.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/subscribe_proto_messages.php b/pubsub/api/src/subscribe_proto_messages.php
index d6e0aa701c..3ccbe1dc06 100644
--- a/pubsub/api/src/subscribe_proto_messages.php
+++ b/pubsub/api/src/subscribe_proto_messages.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/test_subscription_permissions.php b/pubsub/api/src/test_subscription_permissions.php
index 6738f0c18d..e871dd7961 100644
--- a/pubsub/api/src/test_subscription_permissions.php
+++ b/pubsub/api/src/test_subscription_permissions.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/pubsub/api/src/test_topic_permissions.php b/pubsub/api/src/test_topic_permissions.php
index 5a5c1f21d0..e820c14773 100644
--- a/pubsub/api/src/test_topic_permissions.php
+++ b/pubsub/api/src/test_topic_permissions.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/pubsub/api/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/
namespace Google\Cloud\Samples\PubSub;
diff --git a/recaptcha/src/create_key.php b/recaptcha/src/create_key.php
index 749ec2e70a..d36d8fcea5 100644
--- a/recaptcha/src/create_key.php
+++ b/recaptcha/src/create_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/recaptcha/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/recaptcha/README.md
*/
namespace Google\Cloud\Samples\Recaptcha;
diff --git a/recaptcha/src/delete_key.php b/recaptcha/src/delete_key.php
index e88976f0f7..3be945e085 100644
--- a/recaptcha/src/delete_key.php
+++ b/recaptcha/src/delete_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/recaptcha/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/recaptcha/README.md
*/
namespace Google\Cloud\Samples\Recaptcha;
diff --git a/recaptcha/src/get_key.php b/recaptcha/src/get_key.php
index c0688f5d0e..e1d7ce296f 100644
--- a/recaptcha/src/get_key.php
+++ b/recaptcha/src/get_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/recaptcha/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/recaptcha/README.md
*/
namespace Google\Cloud\Samples\Recaptcha;
diff --git a/recaptcha/src/list_keys.php b/recaptcha/src/list_keys.php
index fc39e02c30..fe1ba1ada4 100644
--- a/recaptcha/src/list_keys.php
+++ b/recaptcha/src/list_keys.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/recaptcha/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/recaptcha/README.md
*/
namespace Google\Cloud\Samples\Recaptcha;
diff --git a/recaptcha/src/update_key.php b/recaptcha/src/update_key.php
index f10f7a807b..18b1709e1b 100644
--- a/recaptcha/src/update_key.php
+++ b/recaptcha/src/update_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/recaptcha/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/recaptcha/README.md
*/
namespace Google\Cloud\Samples\Recaptcha;
diff --git a/secretmanager/src/access_secret_version.php b/secretmanager/src/access_secret_version.php
index 2b4cbb3d3c..2dbad57e98 100644
--- a/secretmanager/src/access_secret_version.php
+++ b/secretmanager/src/access_secret_version.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/add_secret_version.php b/secretmanager/src/add_secret_version.php
index f727735910..ed585ba318 100644
--- a/secretmanager/src/add_secret_version.php
+++ b/secretmanager/src/add_secret_version.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/create_secret.php b/secretmanager/src/create_secret.php
index 9975423236..30a46561c4 100644
--- a/secretmanager/src/create_secret.php
+++ b/secretmanager/src/create_secret.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/create_secret_with_user_managed_replication.php b/secretmanager/src/create_secret_with_user_managed_replication.php
index 4efd898fa6..0fe2df5d0f 100644
--- a/secretmanager/src/create_secret_with_user_managed_replication.php
+++ b/secretmanager/src/create_secret_with_user_managed_replication.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/delete_secret.php b/secretmanager/src/delete_secret.php
index 1a332e0104..7f7c7b8e1e 100644
--- a/secretmanager/src/delete_secret.php
+++ b/secretmanager/src/delete_secret.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/destroy_secret_version.php b/secretmanager/src/destroy_secret_version.php
index 4cc570f7f3..a26bf681b3 100644
--- a/secretmanager/src/destroy_secret_version.php
+++ b/secretmanager/src/destroy_secret_version.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/disable_secret_version.php b/secretmanager/src/disable_secret_version.php
index bc2f32369f..7866b9cb02 100644
--- a/secretmanager/src/disable_secret_version.php
+++ b/secretmanager/src/disable_secret_version.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/enable_secret_version.php b/secretmanager/src/enable_secret_version.php
index 2ab515609c..23a3251be4 100644
--- a/secretmanager/src/enable_secret_version.php
+++ b/secretmanager/src/enable_secret_version.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/get_secret.php b/secretmanager/src/get_secret.php
index 46de7fd467..32c31712e1 100644
--- a/secretmanager/src/get_secret.php
+++ b/secretmanager/src/get_secret.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/get_secret_version.php b/secretmanager/src/get_secret_version.php
index c1120c1681..10089642a7 100644
--- a/secretmanager/src/get_secret_version.php
+++ b/secretmanager/src/get_secret_version.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/iam_grant_access.php b/secretmanager/src/iam_grant_access.php
index 192b2199a2..4272447aa1 100644
--- a/secretmanager/src/iam_grant_access.php
+++ b/secretmanager/src/iam_grant_access.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/iam_revoke_access.php b/secretmanager/src/iam_revoke_access.php
index 939acfe865..5449e9961e 100644
--- a/secretmanager/src/iam_revoke_access.php
+++ b/secretmanager/src/iam_revoke_access.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/list_secret_versions.php b/secretmanager/src/list_secret_versions.php
index 6f2549ad17..9a5bbc5e7c 100644
--- a/secretmanager/src/list_secret_versions.php
+++ b/secretmanager/src/list_secret_versions.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/list_secrets.php b/secretmanager/src/list_secrets.php
index 7859b7f982..f7108d7dc3 100644
--- a/secretmanager/src/list_secrets.php
+++ b/secretmanager/src/list_secrets.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/update_secret.php b/secretmanager/src/update_secret.php
index dae2c141d0..ec49e62dc8 100644
--- a/secretmanager/src/update_secret.php
+++ b/secretmanager/src/update_secret.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/secretmanager/src/update_secret_with_alias.php b/secretmanager/src/update_secret_with_alias.php
index bdc9a83ab9..82ede70b00 100644
--- a/secretmanager/src/update_secret_with_alias.php
+++ b/secretmanager/src/update_secret_with_alias.php
@@ -18,7 +18,7 @@
/*
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/secretmanager/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/
declare(strict_types=1);
diff --git a/spanner/composer.json b/spanner/composer.json
index 46d057f11e..109f502236 100755
--- a/spanner/composer.json
+++ b/spanner/composer.json
@@ -1,5 +1,5 @@
{
"require": {
- "google/cloud-spanner": "^1.49.0"
+ "google/cloud-spanner": "^1.54.0"
}
}
diff --git a/spanner/src/add_column.php b/spanner/src/add_column.php
index 2a3cf41422..bad1195f88 100644
--- a/spanner/src/add_column.php
+++ b/spanner/src/add_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function add_column($instanceId, $databaseId)
+function add_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/add_drop_database_role.php b/spanner/src/add_drop_database_role.php
new file mode 100644
index 0000000000..c80870ff77
--- /dev/null
+++ b/spanner/src/add_drop_database_role.php
@@ -0,0 +1,76 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ $roleParent = 'new_parent';
+ $roleChild = 'new_child';
+
+ $operation = $database->updateDdlBatch([
+ sprintf('CREATE ROLE %s', $roleParent),
+ sprintf('GRANT SELECT ON TABLE Singers TO ROLE %s', $roleParent),
+ sprintf('CREATE ROLE %s', $roleChild),
+ sprintf('GRANT ROLE %s TO ROLE %s', $roleParent, $roleChild)
+ ]);
+
+ printf('Waiting for create role and grant operation to complete... %s', PHP_EOL);
+ $operation->pollUntilComplete();
+
+ printf('Created roles %s and %s and granted privileges %s', $roleParent, $roleChild, PHP_EOL);
+
+ $operation = $database->updateDdlBatch([
+ sprintf('REVOKE ROLE %s FROM ROLE %s', $roleParent, $roleChild),
+ sprintf('DROP ROLE %s', $roleChild),
+ sprintf('REVOKE SELECT ON TABLE Singers FROM ROLE %s', $roleParent),
+ sprintf('DROP ROLE %s', $roleParent)
+ ]);
+
+ printf('Waiting for revoke role and drop role operation to complete... %s', PHP_EOL);
+ $operation->pollUntilComplete();
+
+ printf('Revoked privileges and dropped roles %s and %s %s', $roleChild, $roleParent, PHP_EOL);
+}
+// [END spanner_add_and_drop_database_role]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/add_json_column.php b/spanner/src/add_json_column.php
index bd5b320fb3..6495448add 100644
--- a/spanner/src/add_json_column.php
+++ b/spanner/src/add_json_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function add_json_column($instanceId, $databaseId)
+function add_json_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/add_numeric_column.php b/spanner/src/add_numeric_column.php
index 0a9ca1e1b2..636d1ab004 100644
--- a/spanner/src/add_numeric_column.php
+++ b/spanner/src/add_numeric_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function add_numeric_column($instanceId, $databaseId)
+function add_numeric_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/add_timestamp_column.php b/spanner/src/add_timestamp_column.php
index fa40a0f0e1..69737a58ea 100644
--- a/spanner/src/add_timestamp_column.php
+++ b/spanner/src/add_timestamp_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function add_timestamp_column($instanceId, $databaseId)
+function add_timestamp_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/batch_query_data.php b/spanner/src/batch_query_data.php
index 2ae8a1d69c..e7c7b6490d 100644
--- a/spanner/src/batch_query_data.php
+++ b/spanner/src/batch_query_data.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function batch_query_data($instanceId, $databaseId)
+function batch_query_data(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$batch = $spanner->batch($instanceId, $databaseId);
diff --git a/spanner/src/cancel_backup.php b/spanner/src/cancel_backup.php
index 0173ee7219..ea3e449df9 100644
--- a/spanner/src/cancel_backup.php
+++ b/spanner/src/cancel_backup.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function cancel_backup($instanceId, $databaseId)
+function cancel_backup(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/copy_backup.php b/spanner/src/copy_backup.php
index 7e47a2f334..3de00eb28f 100644
--- a/spanner/src/copy_backup.php
+++ b/spanner/src/copy_backup.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -39,7 +39,7 @@
* @param string $sourceInstanceId The Spanner instance ID of the source backup.
* @param string $sourceBackupId The Spanner backup ID of the source.
*/
-function copy_backup($destInstanceId, $destBackupId, $sourceInstanceId, $sourceBackupId)
+function copy_backup(string $destInstanceId, string $destBackupId, string $sourceInstanceId, string $sourceBackupId): void
{
$spanner = new SpannerClient();
diff --git a/spanner/src/create_backup.php b/spanner/src/create_backup.php
index 6386153b59..2f80efc201 100644
--- a/spanner/src/create_backup.php
+++ b/spanner/src/create_backup.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -39,7 +39,7 @@
* @param string $backupId The Spanner backup ID.
* @param string $versionTime The version of the database to backup.
*/
-function create_backup($instanceId, $databaseId, $backupId, $versionTime)
+function create_backup(string $instanceId, string $databaseId, string $backupId, string $versionTime): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/create_backup_with_encryption_key.php b/spanner/src/create_backup_with_encryption_key.php
index 000b34e859..a4d434632f 100644
--- a/spanner/src/create_backup_with_encryption_key.php
+++ b/spanner/src/create_backup_with_encryption_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -40,7 +40,7 @@
* @param string $backupId The Spanner backup ID.
* @param string $kmsKeyName The KMS key used for encryption.
*/
-function create_backup_with_encryption_key($instanceId, $databaseId, $backupId, $kmsKeyName)
+function create_backup_with_encryption_key(string $instanceId, string $databaseId, string $backupId, string $kmsKeyName): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/create_client_with_query_options.php b/spanner/src/create_client_with_query_options.php
index 448540348a..c8882697fd 100644
--- a/spanner/src/create_client_with_query_options.php
+++ b/spanner/src/create_client_with_query_options.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function create_client_with_query_options($instanceId, $databaseId)
+function create_client_with_query_options(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient([
'queryOptions' => [
diff --git a/spanner/src/create_database.php b/spanner/src/create_database.php
index d755e1f564..6803147265 100644
--- a/spanner/src/create_database.php
+++ b/spanner/src/create_database.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function create_database($instanceId, $databaseId)
+function create_database(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/create_database_with_default_leader.php b/spanner/src/create_database_with_default_leader.php
index b503a59e5f..a02a35ed9c 100644
--- a/spanner/src/create_database_with_default_leader.php
+++ b/spanner/src/create_database_with_default_leader.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $databaseId The Spanner database ID.
* @param string $defaultLeader The leader instance configuration used by default.
*/
-function create_database_with_default_leader($instanceId, $databaseId, $defaultLeader)
+function create_database_with_default_leader(string $instanceId, string $databaseId, string $defaultLeader): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/create_database_with_encryption_key.php b/spanner/src/create_database_with_encryption_key.php
index 9448630e31..0785290cae 100644
--- a/spanner/src/create_database_with_encryption_key.php
+++ b/spanner/src/create_database_with_encryption_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $databaseId The Spanner database ID.
* @param string $kmsKeyName The KMS key used for encryption.
*/
-function create_database_with_encryption_key($instanceId, $databaseId, $kmsKeyName)
+function create_database_with_encryption_key(string $instanceId, string $databaseId, string $kmsKeyName): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/create_database_with_version_retention_period.php b/spanner/src/create_database_with_version_retention_period.php
index 06c89fc04d..1f59a5cb59 100644
--- a/spanner/src/create_database_with_version_retention_period.php
+++ b/spanner/src/create_database_with_version_retention_period.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $databaseId The Spanner database ID.
* @param string $retentionPeriod The data retention period for the database.
*/
-function create_database_with_version_retention_period($instanceId, $databaseId, $retentionPeriod)
+function create_database_with_version_retention_period(string $instanceId, string $databaseId, string $retentionPeriod): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/create_index.php b/spanner/src/create_index.php
index 9fcbb50223..17a34a76d7 100644
--- a/spanner/src/create_index.php
+++ b/spanner/src/create_index.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function create_index($instanceId, $databaseId)
+function create_index(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/create_instance.php b/spanner/src/create_instance.php
index 4ce8bd4550..e4977411bf 100644
--- a/spanner/src/create_instance.php
+++ b/spanner/src/create_instance.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -35,7 +35,7 @@
*
* @param string $instanceId The Spanner instance ID.
*/
-function create_instance($instanceId)
+function create_instance(string $instanceId): void
{
$spanner = new SpannerClient();
$instanceConfig = $spanner->instanceConfiguration(
diff --git a/spanner/src/create_instance_config.php b/spanner/src/create_instance_config.php
new file mode 100644
index 0000000000..3602b69491
--- /dev/null
+++ b/spanner/src/create_instance_config.php
@@ -0,0 +1,82 @@
+instanceConfiguration(
+ $baseConfigId
+ );
+
+ $instanceConfiguration = $spanner->instanceConfiguration($userConfigId);
+ $operation = $instanceConfiguration->create(
+ $baseInstanceConfig,
+ array_merge(
+ $baseInstanceConfig->info()['replicas'],
+ // The replicas for the custom instance configuration must include all the replicas of the base
+ // configuration, in addition to at least one from the list of optional replicas of the base
+ // configuration.
+ [new ReplicaInfo(
+ [
+ 'location' => 'us-east1',
+ 'type' => ReplicaInfo\ReplicaType::READ_ONLY,
+ 'default_leader_location' => false
+ ]
+ )]
+ ),
+ [
+ 'displayName' => 'This is a display name',
+ 'labels' => [
+ 'php_cloud_spanner_samples' => true,
+ ]
+ ]
+ );
+
+ print('Waiting for operation to complete...' . PHP_EOL);
+ $operation->pollUntilComplete();
+
+ printf('Created instance configuration %s' . PHP_EOL, $userConfigId);
+}
+// [END spanner_create_instance_config]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/create_instance_with_processing_units.php b/spanner/src/create_instance_with_processing_units.php
index f11e769c2d..cd336efaa1 100644
--- a/spanner/src/create_instance_with_processing_units.php
+++ b/spanner/src/create_instance_with_processing_units.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/create_storing_index.php b/spanner/src/create_storing_index.php
index 759f86232a..c50b3fa397 100644
--- a/spanner/src/create_storing_index.php
+++ b/spanner/src/create_storing_index.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*
* For more information on this function:
*
@@ -47,7 +47,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function create_storing_index($instanceId, $databaseId)
+function create_storing_index(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/create_table_with_datatypes.php b/spanner/src/create_table_with_datatypes.php
index d78c831113..cdabd8e803 100644
--- a/spanner/src/create_table_with_datatypes.php
+++ b/spanner/src/create_table_with_datatypes.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function create_table_with_datatypes($instanceId, $databaseId)
+function create_table_with_datatypes(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/create_table_with_timestamp_column.php b/spanner/src/create_table_with_timestamp_column.php
index 6b44b98f41..f203c7e322 100644
--- a/spanner/src/create_table_with_timestamp_column.php
+++ b/spanner/src/create_table_with_timestamp_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function create_table_with_timestamp_column($instanceId, $databaseId)
+function create_table_with_timestamp_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/delete_backup.php b/spanner/src/delete_backup.php
index b8a881e18d..329d0d6920 100644
--- a/spanner/src/delete_backup.php
+++ b/spanner/src/delete_backup.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -35,7 +35,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $backupId The Spanner backup ID.
*/
-function delete_backup($instanceId, $backupId)
+function delete_backup(string $instanceId, string $backupId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/delete_data.php b/spanner/src/delete_data.php
index d9ed65db44..3ca9448858 100644
--- a/spanner/src/delete_data.php
+++ b/spanner/src/delete_data.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -35,7 +35,7 @@
* @param string $databaseId The Spanner database ID.
* @throws GoogleException
*/
-function delete_data($instanceId, $databaseId)
+function delete_data(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/delete_data_with_dml.php b/spanner/src/delete_data_with_dml.php
index 1862b8758f..7ba0cef5c9 100644
--- a/spanner/src/delete_data_with_dml.php
+++ b/spanner/src/delete_data_with_dml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -33,7 +33,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function delete_data_with_dml($instanceId, $databaseId)
+function delete_data_with_dml(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/delete_data_with_partitioned_dml.php b/spanner/src/delete_data_with_partitioned_dml.php
index 075bd57cb5..2ad0225585 100644
--- a/spanner/src/delete_data_with_partitioned_dml.php
+++ b/spanner/src/delete_data_with_partitioned_dml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -43,7 +43,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function delete_data_with_partitioned_dml($instanceId, $databaseId)
+function delete_data_with_partitioned_dml(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/delete_dml_returning.php b/spanner/src/delete_dml_returning.php
new file mode 100644
index 0000000000..4f3673d5b4
--- /dev/null
+++ b/spanner/src/delete_dml_returning.php
@@ -0,0 +1,67 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ $transaction = $database->transaction();
+
+ // DML returning sql delete query
+ $result = $transaction->execute(
+ 'DELETE FROM Singers WHERE FirstName = @firstName '
+ . 'THEN RETURN *',
+ [
+ 'parameters' => [
+ 'firstName' => 'Melissa',
+ ]
+ ]
+ );
+ foreach ($result->rows() as $row) {
+ printf(
+ 'Row (%s, %s, %s) deleted' . PHP_EOL,
+ $row['SingerId'],
+ $row['FirstName'],
+ $row['LastName']
+ );
+ }
+ $transaction->commit();
+}
+// [END spanner_delete_dml_returning]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/delete_instance_config.php b/spanner/src/delete_instance_config.php
new file mode 100644
index 0000000000..1e15355748
--- /dev/null
+++ b/spanner/src/delete_instance_config.php
@@ -0,0 +1,51 @@
+instanceConfiguration($instanceConfigId);
+
+ $instanceConfiguration->delete();
+
+ printf('Deleted instance configuration %s' . PHP_EOL, $instanceConfigId);
+}
+// [END spanner_delete_instance_config]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/dml_batch_update_request_priority.php b/spanner/src/dml_batch_update_request_priority.php
new file mode 100644
index 0000000000..9b366a8919
--- /dev/null
+++ b/spanner/src/dml_batch_update_request_priority.php
@@ -0,0 +1,82 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ $batchDmlResult = $database->runTransaction(function (Transaction $t) {
+ // Variable to define the Priority of this operation
+ // For more information read [
+ // the upstream documentation](https://cloud.google.com/spanner/docs/reference/rest/v1/RequestOptions)
+ $priority = Priority::PRIORITY_LOW;
+
+ $result = $t->executeUpdateBatch([
+ [
+ 'sql' => 'UPDATE Albums '
+ . 'SET MarketingBudget = MarketingBudget * 2 '
+ . 'WHERE SingerId = 1 and AlbumId = 3'
+ ],
+ [
+ 'sql' => 'UPDATE Albums '
+ . 'SET MarketingBudget = MarketingBudget * 2 '
+ . 'WHERE SingerId = 2 and AlbumId = 3'
+ ],
+ ], array('priority' => $priority));
+ $t->commit();
+ $rowCounts = count($result->rowCounts());
+ printf('Executed %s SQL statements using Batch DML with PRIORITY_LOW.' . PHP_EOL,
+ $rowCounts);
+ });
+}
+// [END spanner_dml_batch_update_request_priority]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/get_commit_stats.php b/spanner/src/get_commit_stats.php
index e92e7fc636..9c0eceefac 100644
--- a/spanner/src/get_commit_stats.php
+++ b/spanner/src/get_commit_stats.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function get_commit_stats($instanceId, $databaseId)
+function get_commit_stats(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/get_database_ddl.php b/spanner/src/get_database_ddl.php
index 5645a44613..3b0c475a02 100644
--- a/spanner/src/get_database_ddl.php
+++ b/spanner/src/get_database_ddl.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function get_database_ddl($instanceId, $databaseId)
+function get_database_ddl(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/get_instance_config.php b/spanner/src/get_instance_config.php
index 7ef49a78bc..803927b6c5 100644
--- a/spanner/src/get_instance_config.php
+++ b/spanner/src/get_instance_config.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -31,7 +31,7 @@
*
* @param string $instanceConfig The name of the instance configuration.
*/
-function get_instance_config($instanceConfig)
+function get_instance_config(string $instanceConfig): void
{
$spanner = new SpannerClient();
$config = $spanner->instanceConfiguration($instanceConfig);
diff --git a/spanner/src/insert_data.php b/spanner/src/insert_data.php
index 7351d2f602..6ca06fc50a 100644
--- a/spanner/src/insert_data.php
+++ b/spanner/src/insert_data.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -39,7 +39,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function insert_data($instanceId, $databaseId)
+function insert_data(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/insert_data_with_datatypes.php b/spanner/src/insert_data_with_datatypes.php
index 1ad24845e5..2ff6b7fe7d 100644
--- a/spanner/src/insert_data_with_datatypes.php
+++ b/spanner/src/insert_data_with_datatypes.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -39,7 +39,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function insert_data_with_datatypes($instanceId, $databaseId)
+function insert_data_with_datatypes(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/insert_data_with_dml.php b/spanner/src/insert_data_with_dml.php
index fa4b0f5a88..95e5faf5d2 100644
--- a/spanner/src/insert_data_with_dml.php
+++ b/spanner/src/insert_data_with_dml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -40,7 +40,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function insert_data_with_dml($instanceId, $databaseId)
+function insert_data_with_dml(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/insert_data_with_timestamp_column.php b/spanner/src/insert_data_with_timestamp_column.php
index 04be9e10c0..58f4ccedd9 100644
--- a/spanner/src/insert_data_with_timestamp_column.php
+++ b/spanner/src/insert_data_with_timestamp_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -39,7 +39,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function insert_data_with_timestamp_column($instanceId, $databaseId)
+function insert_data_with_timestamp_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/insert_dml_returning.php b/spanner/src/insert_dml_returning.php
new file mode 100644
index 0000000000..00fbea54e1
--- /dev/null
+++ b/spanner/src/insert_dml_returning.php
@@ -0,0 +1,64 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ // DML returning sql insert query
+ $sql = 'INSERT INTO Singers (SingerId, FirstName, LastName) '
+ . "VALUES (12, 'Melissa', 'Garcia'), "
+ . "(13, 'Russell', 'Morales'), "
+ . "(14, 'Jacqueline', 'Long'), "
+ . "(15, 'Dylan', 'Shaw') "
+ . 'THEN RETURN *';
+
+ $transaction = $database->transaction();
+ $result = $transaction->execute($sql);
+ foreach ($result->rows() as $row) {
+ printf(
+ 'Row (%s, %s, %s) inserted' . PHP_EOL,
+ $row['SingerId'],
+ $row['FirstName'],
+ $row['LastName']
+ );
+ }
+ $transaction->commit();
+}
+// [END spanner_insert_dml_returning]
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/insert_struct_data.php b/spanner/src/insert_struct_data.php
index 30ad11c0d3..0f3777ed68 100644
--- a/spanner/src/insert_struct_data.php
+++ b/spanner/src/insert_struct_data.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -39,7 +39,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function insert_struct_data($instanceId, $databaseId)
+function insert_struct_data(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/list_backup_operations.php b/spanner/src/list_backup_operations.php
index 0dc6fdd5dd..e5257f39c1 100644
--- a/spanner/src/list_backup_operations.php
+++ b/spanner/src/list_backup_operations.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/list_backups.php b/spanner/src/list_backups.php
index 6250b76405..9246745d84 100644
--- a/spanner/src/list_backups.php
+++ b/spanner/src/list_backups.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -35,7 +35,7 @@
*
* @param string $instanceId The Spanner instance ID.
*/
-function list_backups($instanceId)
+function list_backups(string $instanceId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/list_database_operations.php b/spanner/src/list_database_operations.php
index 7d74bc2e24..104e4143ae 100644
--- a/spanner/src/list_database_operations.php
+++ b/spanner/src/list_database_operations.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -35,7 +35,7 @@
*
* @param string $instanceId The Spanner instance ID.
*/
-function list_database_operations($instanceId)
+function list_database_operations(string $instanceId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/list_databases.php b/spanner/src/list_databases.php
index 17dd57a144..2affbd9299 100644
--- a/spanner/src/list_databases.php
+++ b/spanner/src/list_databases.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -33,9 +33,9 @@
* list_databases($instanceId);
* ```
*
- * @param $instanceId The Spanner instance ID.
+ * @param string $instanceId The Spanner instance ID.
*/
-function list_databases($instanceId)
+function list_databases(string $instanceId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/list_instance_config_operations.php b/spanner/src/list_instance_config_operations.php
new file mode 100644
index 0000000000..732566f3ee
--- /dev/null
+++ b/spanner/src/list_instance_config_operations.php
@@ -0,0 +1,58 @@
+instanceConfigOperations();
+ foreach ($operations as $operation) {
+ $meta = $operation->info()['metadata'];
+ $instanceConfig = $meta['instanceConfig'];
+ $configName = basename($instanceConfig['name']);
+ $type = $meta['typeUrl'];
+ printf(
+ 'Instance config operation for %s of type %s has status %s.' . PHP_EOL,
+ $configName,
+ $type,
+ $operation->done() ? 'done' : 'running'
+ );
+ }
+}
+// [END spanner_list_instance_config_operations]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/list_instance_configs.php b/spanner/src/list_instance_configs.php
index e6ba90d0c0..f12c1c81e7 100644
--- a/spanner/src/list_instance_configs.php
+++ b/spanner/src/list_instance_configs.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -33,7 +33,7 @@
* list_instance_configs();
* ```
*/
-function list_instance_configs()
+function list_instance_configs(): void
{
$spanner = new SpannerClient();
foreach ($spanner->instanceConfigurations() as $config) {
diff --git a/spanner/src/pg_add_column.php b/spanner/src/pg_add_column.php
index c76117d7ce..c785933f13 100755
--- a/spanner/src/pg_add_column.php
+++ b/spanner/src/pg_add_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_add_jsonb_column.php b/spanner/src/pg_add_jsonb_column.php
new file mode 100644
index 0000000000..2a3a62ec7f
--- /dev/null
+++ b/spanner/src/pg_add_jsonb_column.php
@@ -0,0 +1,58 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ $operation = $database->updateDdl(
+ sprintf('ALTER TABLE %s ADD COLUMN VenueDetails JSONB', $tableName)
+ );
+
+ print('Waiting for operation to complete...' . PHP_EOL);
+ $operation->pollUntilComplete();
+
+ print(sprintf('Added column VenueDetails on table %s.', $tableName) . PHP_EOL);
+}
+// [END spanner_postgresql_jsonb_add_column]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/pg_batch_dml.php b/spanner/src/pg_batch_dml.php
index d63bf0e655..6f81d7c945 100644
--- a/spanner/src/pg_batch_dml.php
+++ b/spanner/src/pg_batch_dml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_case_sensitivity.php b/spanner/src/pg_case_sensitivity.php
index 2b94d12075..f8100d5191 100644
--- a/spanner/src/pg_case_sensitivity.php
+++ b/spanner/src/pg_case_sensitivity.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_cast_data_type.php b/spanner/src/pg_cast_data_type.php
index a09a17ee58..01394e135f 100644
--- a/spanner/src/pg_cast_data_type.php
+++ b/spanner/src/pg_cast_data_type.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_connect_to_db.php b/spanner/src/pg_connect_to_db.php
index e588736c55..e6b8ecd9e5 100644
--- a/spanner/src/pg_connect_to_db.php
+++ b/spanner/src/pg_connect_to_db.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_create_database.php b/spanner/src/pg_create_database.php
index 8739c23c27..ef157b6e01 100755
--- a/spanner/src/pg_create_database.php
+++ b/spanner/src/pg_create_database.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_create_storing_index.php b/spanner/src/pg_create_storing_index.php
index 2159c37858..5d1c116c8c 100644
--- a/spanner/src/pg_create_storing_index.php
+++ b/spanner/src/pg_create_storing_index.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_delete_dml_returning.php b/spanner/src/pg_delete_dml_returning.php
new file mode 100644
index 0000000000..733acfd482
--- /dev/null
+++ b/spanner/src/pg_delete_dml_returning.php
@@ -0,0 +1,67 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ $transaction = $database->transaction();
+
+ // DML returning postgresql delete query
+ $result = $transaction->execute(
+ 'DELETE FROM singers WHERE firstname = $1 '
+ . 'RETURNING *',
+ [
+ 'parameters' => [
+ 'p1' => 'Melissa',
+ ]
+ ]
+ );
+ foreach ($result->rows() as $row) {
+ printf(
+ 'Row (%s, %s, %s) deleted' . PHP_EOL,
+ $row['singerid'],
+ $row['firstname'],
+ $row['lastname']
+ );
+ }
+ $transaction->commit();
+}
+// [END spanner_postgresql_delete_dml_returning]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/pg_dml_getting_started_update.php b/spanner/src/pg_dml_getting_started_update.php
index 695a76d775..f82c132b68 100644
--- a/spanner/src/pg_dml_getting_started_update.php
+++ b/spanner/src/pg_dml_getting_started_update.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_dml_with_params.php b/spanner/src/pg_dml_with_params.php
index dffd313def..69029b0d99 100644
--- a/spanner/src/pg_dml_with_params.php
+++ b/spanner/src/pg_dml_with_params.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_functions.php b/spanner/src/pg_functions.php
index ef62558fbe..2bac2ea64f 100644
--- a/spanner/src/pg_functions.php
+++ b/spanner/src/pg_functions.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_information_schema.php b/spanner/src/pg_information_schema.php
index 051e62df81..ef1873dfa6 100644
--- a/spanner/src/pg_information_schema.php
+++ b/spanner/src/pg_information_schema.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_insert_dml_returning.php b/spanner/src/pg_insert_dml_returning.php
new file mode 100644
index 0000000000..e42d6d9ceb
--- /dev/null
+++ b/spanner/src/pg_insert_dml_returning.php
@@ -0,0 +1,66 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ // DML returning postgresql insert query
+ $sql = 'INSERT INTO singers (singerid, firstname, lastname) '
+ . "VALUES (16, 'Melissa', 'Garcia'), "
+ . "(17, 'Russell', 'Morales'), "
+ . "(18, 'Jacqueline', 'Long'), "
+ . "(19, 'Dylan', 'Shaw') "
+ . 'RETURNING *';
+
+ $transaction = $database->transaction();
+ $result = $transaction->execute($sql);
+ foreach ($result->rows() as $row) {
+ printf(
+ 'Row (%s, %s, %s) inserted' . PHP_EOL,
+ $row['singerid'],
+ $row['firstname'],
+ $row['lastname']
+ );
+ }
+ $transaction->commit();
+}
+// [END spanner_postgresql_insert_dml_returning]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/pg_interleaved_table.php b/spanner/src/pg_interleaved_table.php
index b7ce64734f..41dfa07811 100644
--- a/spanner/src/pg_interleaved_table.php
+++ b/spanner/src/pg_interleaved_table.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_jsonb_query_parameter.php b/spanner/src/pg_jsonb_query_parameter.php
new file mode 100644
index 0000000000..05f270b785
--- /dev/null
+++ b/spanner/src/pg_jsonb_query_parameter.php
@@ -0,0 +1,67 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ $results = $database->execute(
+ sprintf('SELECT venueid, venuedetails FROM %s', $tableName) .
+ " WHERE CAST(venuedetails ->> 'rating' AS INTEGER) > $1",
+ [
+ 'parameters' => [
+ 'p1' => 2
+ ],
+ 'types' => [
+ 'p1' => Database::TYPE_INT64
+ ]
+ ]);
+
+ foreach ($results as $row) {
+ printf('VenueId: %s, VenueDetails: %s' . PHP_EOL, $row['venueid'], $row['venuedetails']);
+ }
+}
+// [END spanner_postgresql_jsonb_query_parameter]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/pg_jsonb_update_data.php b/spanner/src/pg_jsonb_update_data.php
new file mode 100644
index 0000000000..ecef50f1f8
--- /dev/null
+++ b/spanner/src/pg_jsonb_update_data.php
@@ -0,0 +1,91 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ $database->insertOrUpdateBatch($tableName, [
+ [
+ 'VenueId' => 1,
+ 'VenueDetails' => '{"rating": 9, "open": true}'
+ ],
+ [
+ 'VenueId' => 4,
+ 'VenueDetails' => '[
+ {
+ "name": null,
+ "available": true
+ },' .
+ // PG JSONB sorts first by key length and then lexicographically with
+ // equivalent key length and takes the last value in the case of duplicate keys
+ '{
+ "name": "room 2",
+ "available": false,
+ "name": "room 3"
+ },
+ {
+ "main hall": {
+ "description": "this is the biggest space",
+ "size": 200
+ }
+ }
+ ]'
+ ],
+ [
+ 'VenueId' => 42,
+ 'VenueDetails' => $spanner->pgJsonb([
+ 'name' => null,
+ 'open' => [
+ 'Monday' => true,
+ 'Tuesday' => false
+ ],
+ 'tags' => ['large', 'airy'],
+ ])
+ ]
+ ]);
+
+ print(sprintf('Inserted/updated 3 rows in table %s', $tableName) . PHP_EOL);
+}
+// [END spanner_postgresql_jsonb_update_data]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/pg_numeric_data_type.php b/spanner/src/pg_numeric_data_type.php
index 7928082206..76124eaa94 100644
--- a/spanner/src/pg_numeric_data_type.php
+++ b/spanner/src/pg_numeric_data_type.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_order_nulls.php b/spanner/src/pg_order_nulls.php
index f8ffe4fe6c..c77167d293 100644
--- a/spanner/src/pg_order_nulls.php
+++ b/spanner/src/pg_order_nulls.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_partitioned_dml.php b/spanner/src/pg_partitioned_dml.php
index 8a8dae37b7..eaa0829300 100644
--- a/spanner/src/pg_partitioned_dml.php
+++ b/spanner/src/pg_partitioned_dml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_query_parameter.php b/spanner/src/pg_query_parameter.php
index ef5ac3166c..80a9984909 100644
--- a/spanner/src/pg_query_parameter.php
+++ b/spanner/src/pg_query_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/pg_update_dml_returning.php b/spanner/src/pg_update_dml_returning.php
new file mode 100644
index 0000000000..c60c2fcf79
--- /dev/null
+++ b/spanner/src/pg_update_dml_returning.php
@@ -0,0 +1,68 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ $transaction = $database->transaction();
+
+ // DML returning postgresql update query
+ $result = $transaction->execute(
+ 'UPDATE singers SET lastname = $1 WHERE singerid = $2 RETURNING *',
+ [
+ 'parameters' => [
+ 'p1' => 'Missing',
+ 'p2' => 16,
+ ]
+ ]
+ );
+ foreach ($result->rows() as $row) {
+ printf(
+ 'Row with singerid %s updated to (%s, %s, %s)' . PHP_EOL,
+ $row['singerid'],
+ $row['singerid'],
+ $row['firstname'],
+ $row['lastname']
+ );
+ }
+ $transaction->commit();
+}
+// [END spanner_postgresql_update_dml_returning]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/query_data.php b/spanner/src/query_data.php
index 5099d1a997..91505376cf 100644
--- a/spanner/src/query_data.php
+++ b/spanner/src/query_data.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data($instanceId, $databaseId)
+function query_data(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_array_of_struct.php b/spanner/src/query_data_with_array_of_struct.php
index abc6604dc7..8cbc8293f1 100644
--- a/spanner/src/query_data_with_array_of_struct.php
+++ b/spanner/src/query_data_with_array_of_struct.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -39,7 +39,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_array_of_struct($instanceId, $databaseId)
+function query_data_with_array_of_struct(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_array_parameter.php b/spanner/src/query_data_with_array_parameter.php
index e4f36411c5..f813f2284e 100644
--- a/spanner/src/query_data_with_array_parameter.php
+++ b/spanner/src/query_data_with_array_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -38,7 +38,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_array_parameter($instanceId, $databaseId)
+function query_data_with_array_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_bool_parameter.php b/spanner/src/query_data_with_bool_parameter.php
index 2ecec63ae1..fbc8eafe59 100644
--- a/spanner/src/query_data_with_bool_parameter.php
+++ b/spanner/src/query_data_with_bool_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_bool_parameter($instanceId, $databaseId)
+function query_data_with_bool_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_bytes_parameter.php b/spanner/src/query_data_with_bytes_parameter.php
index 71704e186e..d592c7efa5 100644
--- a/spanner/src/query_data_with_bytes_parameter.php
+++ b/spanner/src/query_data_with_bytes_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_bytes_parameter($instanceId, $databaseId)
+function query_data_with_bytes_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_date_parameter.php b/spanner/src/query_data_with_date_parameter.php
index d0cd972caf..54c41eaf59 100644
--- a/spanner/src/query_data_with_date_parameter.php
+++ b/spanner/src/query_data_with_date_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_date_parameter($instanceId, $databaseId)
+function query_data_with_date_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_float_parameter.php b/spanner/src/query_data_with_float_parameter.php
index 7c5d07cbbe..1c0b920208 100644
--- a/spanner/src/query_data_with_float_parameter.php
+++ b/spanner/src/query_data_with_float_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_float_parameter($instanceId, $databaseId)
+function query_data_with_float_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_index.php b/spanner/src/query_data_with_index.php
index f3e3629134..c5e781f3a9 100644
--- a/spanner/src/query_data_with_index.php
+++ b/spanner/src/query_data_with_index.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -46,11 +46,11 @@
* @param string $endTitle The end of the title index.
*/
function query_data_with_index(
- $instanceId,
- $databaseId,
- $startTitle = 'Aardvark',
- $endTitle = 'Goo'
-) {
+ string $instanceId,
+ string $databaseId,
+ string $startTitle = 'Aardvark',
+ string $endTitle = 'Goo'
+): void {
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
$database = $instance->database($databaseId);
diff --git a/spanner/src/query_data_with_int_parameter.php b/spanner/src/query_data_with_int_parameter.php
index b31111b6cc..abef9b55f1 100644
--- a/spanner/src/query_data_with_int_parameter.php
+++ b/spanner/src/query_data_with_int_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_int_parameter($instanceId, $databaseId)
+function query_data_with_int_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_json_parameter.php b/spanner/src/query_data_with_json_parameter.php
index 369a538d07..ad8f3e02cb 100644
--- a/spanner/src/query_data_with_json_parameter.php
+++ b/spanner/src/query_data_with_json_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_json_parameter($instanceId, $databaseId)
+function query_data_with_json_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_nested_struct_field.php b/spanner/src/query_data_with_nested_struct_field.php
index 2146aa4502..a45297e0d8 100644
--- a/spanner/src/query_data_with_nested_struct_field.php
+++ b/spanner/src/query_data_with_nested_struct_field.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -40,7 +40,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_nested_struct_field($instanceId, $databaseId)
+function query_data_with_nested_struct_field(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_new_column.php b/spanner/src/query_data_with_new_column.php
index 0cba7d6b0f..f8e505652b 100644
--- a/spanner/src/query_data_with_new_column.php
+++ b/spanner/src/query_data_with_new_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -42,7 +42,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_new_column($instanceId, $databaseId)
+function query_data_with_new_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_numeric_parameter.php b/spanner/src/query_data_with_numeric_parameter.php
index d195186054..0cea1ea8b8 100644
--- a/spanner/src/query_data_with_numeric_parameter.php
+++ b/spanner/src/query_data_with_numeric_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_numeric_parameter($instanceId, $databaseId)
+function query_data_with_numeric_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_parameter.php b/spanner/src/query_data_with_parameter.php
index 37a37ae253..47db1101e5 100644
--- a/spanner/src/query_data_with_parameter.php
+++ b/spanner/src/query_data_with_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_parameter($instanceId, $databaseId)
+function query_data_with_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_query_options.php b/spanner/src/query_data_with_query_options.php
index 45ea9f1378..5af91ca298 100644
--- a/spanner/src/query_data_with_query_options.php
+++ b/spanner/src/query_data_with_query_options.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_query_options($instanceId, $databaseId)
+function query_data_with_query_options(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_string_parameter.php b/spanner/src/query_data_with_string_parameter.php
index 8cb9af2f8d..6442892c70 100644
--- a/spanner/src/query_data_with_string_parameter.php
+++ b/spanner/src/query_data_with_string_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_string_parameter($instanceId, $databaseId)
+function query_data_with_string_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_struct.php b/spanner/src/query_data_with_struct.php
index d1446ad1f6..6e3153f175 100644
--- a/spanner/src/query_data_with_struct.php
+++ b/spanner/src/query_data_with_struct.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -38,7 +38,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_struct($instanceId, $databaseId)
+function query_data_with_struct(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_struct_field.php b/spanner/src/query_data_with_struct_field.php
index 9950792df5..da2b7cb858 100644
--- a/spanner/src/query_data_with_struct_field.php
+++ b/spanner/src/query_data_with_struct_field.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -38,7 +38,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_struct_field($instanceId, $databaseId)
+function query_data_with_struct_field(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_timestamp_column.php b/spanner/src/query_data_with_timestamp_column.php
index ae4ea6091f..6b0fac0392 100644
--- a/spanner/src/query_data_with_timestamp_column.php
+++ b/spanner/src/query_data_with_timestamp_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -49,7 +49,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_timestamp_column($instanceId, $databaseId)
+function query_data_with_timestamp_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_data_with_timestamp_parameter.php b/spanner/src/query_data_with_timestamp_parameter.php
index 001779e3bb..c4ad8c7ed5 100644
--- a/spanner/src/query_data_with_timestamp_parameter.php
+++ b/spanner/src/query_data_with_timestamp_parameter.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_data_with_timestamp_parameter($instanceId, $databaseId)
+function query_data_with_timestamp_parameter(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/query_information_schema_database_options.php b/spanner/src/query_information_schema_database_options.php
index 74d5fbbfdb..5215c48b93 100644
--- a/spanner/src/query_information_schema_database_options.php
+++ b/spanner/src/query_information_schema_database_options.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function query_information_schema_database_options($instanceId, $databaseId)
+function query_information_schema_database_options(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/read_data.php b/spanner/src/read_data.php
index d5df827cd5..514cc12c08 100644
--- a/spanner/src/read_data.php
+++ b/spanner/src/read_data.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function read_data($instanceId, $databaseId)
+function read_data(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/read_data_with_index.php b/spanner/src/read_data_with_index.php
index 0226829fb5..366cb6f1a5 100644
--- a/spanner/src/read_data_with_index.php
+++ b/spanner/src/read_data_with_index.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -43,7 +43,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function read_data_with_index($instanceId, $databaseId)
+function read_data_with_index(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/read_data_with_storing_index.php b/spanner/src/read_data_with_storing_index.php
index 93c190cb77..b45116f512 100644
--- a/spanner/src/read_data_with_storing_index.php
+++ b/spanner/src/read_data_with_storing_index.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*
* For more information on this function:
*
@@ -49,7 +49,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function read_data_with_storing_index($instanceId, $databaseId)
+function read_data_with_storing_index(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/read_only_transaction.php b/spanner/src/read_only_transaction.php
index bc04b0d003..1fb603e25f 100644
--- a/spanner/src/read_only_transaction.php
+++ b/spanner/src/read_only_transaction.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -39,7 +39,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function read_only_transaction($instanceId, $databaseId)
+function read_only_transaction(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/read_stale_data.php b/spanner/src/read_stale_data.php
index f684b1eb95..f06695410c 100644
--- a/spanner/src/read_stale_data.php
+++ b/spanner/src/read_stale_data.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -39,7 +39,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function read_stale_data($instanceId, $databaseId)
+function read_stale_data(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/read_write_retry.php b/spanner/src/read_write_retry.php
new file mode 100644
index 0000000000..8120e564e7
--- /dev/null
+++ b/spanner/src/read_write_retry.php
@@ -0,0 +1,81 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+ $maxRetries = 2;
+
+ $database->runTransaction(function (Transaction $t) use ($spanner) {
+ // Read the second album's budget.
+ $secondAlbumKey = [2, 2];
+ $secondAlbumKeySet = $spanner->keySet(['keys' => [$secondAlbumKey]]);
+ $secondAlbumResult = $t->read(
+ 'Albums',
+ $secondAlbumKeySet,
+ ['MarketingBudget'],
+ ['limit' => 1]
+ );
+ $firstRow = $secondAlbumResult->rows()->current();
+ $secondAlbumBudget = $firstRow['MarketingBudget'];
+
+ printf('Setting second album\'s budget as the first album\'s budget.' . PHP_EOL);
+
+ // Update the row.
+ $t->updateBatch('Albums', [
+ ['SingerId' => 1, 'AlbumId' => 1, 'MarketingBudget' => $secondAlbumBudget],
+ ]);
+
+ // Commit the transaction!
+ $t->commit();
+
+ print('Transaction complete.' . PHP_EOL);
+ }, ['maxRetries' => $maxRetries]);
+}
+// [END spanner_read_write_retry]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/read_write_transaction.php b/spanner/src/read_write_transaction.php
index 775d81108a..08086ae219 100644
--- a/spanner/src/read_write_transaction.php
+++ b/spanner/src/read_write_transaction.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -46,7 +46,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function read_write_transaction($instanceId, $databaseId)
+function read_write_transaction(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/restore_backup.php b/spanner/src/restore_backup.php
index 010c90a976..7ac4ee82dc 100644
--- a/spanner/src/restore_backup.php
+++ b/spanner/src/restore_backup.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $databaseId The Spanner database ID.
* @param string $backupId The Spanner backup ID.
*/
-function restore_backup($instanceId, $databaseId, $backupId)
+function restore_backup(string $instanceId, string $databaseId, string $backupId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/restore_backup_with_encryption_key.php b/spanner/src/restore_backup_with_encryption_key.php
index f45c533187..f2207aa68c 100644
--- a/spanner/src/restore_backup_with_encryption_key.php
+++ b/spanner/src/restore_backup_with_encryption_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -38,7 +38,7 @@
* @param string $backupId The Spanner backup ID.
* @param string $kmsKeyName The KMS key used for encryption.
*/
-function restore_backup_with_encryption_key($instanceId, $databaseId, $backupId, $kmsKeyName)
+function restore_backup_with_encryption_key(string $instanceId, string $databaseId, string $backupId, string $kmsKeyName): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/set_request_tag.php b/spanner/src/set_request_tag.php
index 8e7d4a44df..85d6b35e88 100644
--- a/spanner/src/set_request_tag.php
+++ b/spanner/src/set_request_tag.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/set_transaction_tag.php b/spanner/src/set_transaction_tag.php
index e087bc7bfd..5499aa0c28 100644
--- a/spanner/src/set_transaction_tag.php
+++ b/spanner/src/set_transaction_tag.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
diff --git a/spanner/src/update_backup.php b/spanner/src/update_backup.php
index a63c647f9b..4ce15b0ff0 100644
--- a/spanner/src/update_backup.php
+++ b/spanner/src/update_backup.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -36,7 +36,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $backupId The Spanner backup ID.
*/
-function update_backup($instanceId, $backupId)
+function update_backup(string $instanceId, string $backupId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_data.php b/spanner/src/update_data.php
index 6024cb1b4c..662179401a 100644
--- a/spanner/src/update_data.php
+++ b/spanner/src/update_data.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -43,7 +43,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function update_data($instanceId, $databaseId)
+function update_data(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_data_with_batch_dml.php b/spanner/src/update_data_with_batch_dml.php
index eba07e4308..86d9ec9396 100644
--- a/spanner/src/update_data_with_batch_dml.php
+++ b/spanner/src/update_data_with_batch_dml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -44,7 +44,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function update_data_with_batch_dml($instanceId, $databaseId)
+function update_data_with_batch_dml(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_data_with_dml.php b/spanner/src/update_data_with_dml.php
index 14eac097f0..fd5d77358c 100644
--- a/spanner/src/update_data_with_dml.php
+++ b/spanner/src/update_data_with_dml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -44,7 +44,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function update_data_with_dml($instanceId, $databaseId)
+function update_data_with_dml(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_data_with_dml_structs.php b/spanner/src/update_data_with_dml_structs.php
index 029765c19f..3431d4de67 100644
--- a/spanner/src/update_data_with_dml_structs.php
+++ b/spanner/src/update_data_with_dml_structs.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -43,7 +43,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function update_data_with_dml_structs($instanceId, $databaseId)
+function update_data_with_dml_structs(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_data_with_dml_timestamp.php b/spanner/src/update_data_with_dml_timestamp.php
index 8bb476ea23..9297cace6f 100644
--- a/spanner/src/update_data_with_dml_timestamp.php
+++ b/spanner/src/update_data_with_dml_timestamp.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -40,7 +40,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function update_data_with_dml_timestamp($instanceId, $databaseId)
+function update_data_with_dml_timestamp(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_data_with_json_column.php b/spanner/src/update_data_with_json_column.php
index fa01681ba1..d18d422b5b 100644
--- a/spanner/src/update_data_with_json_column.php
+++ b/spanner/src/update_data_with_json_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -40,7 +40,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function update_data_with_json_column($instanceId, $databaseId)
+function update_data_with_json_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_data_with_numeric_column.php b/spanner/src/update_data_with_numeric_column.php
index 86e3d02fa9..a737fa1487 100644
--- a/spanner/src/update_data_with_numeric_column.php
+++ b/spanner/src/update_data_with_numeric_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -40,7 +40,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function update_data_with_numeric_column($instanceId, $databaseId)
+function update_data_with_numeric_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_data_with_partitioned_dml.php b/spanner/src/update_data_with_partitioned_dml.php
index d9cd608a7f..1fd34c1e41 100644
--- a/spanner/src/update_data_with_partitioned_dml.php
+++ b/spanner/src/update_data_with_partitioned_dml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -43,7 +43,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function update_data_with_partitioned_dml($instanceId, $databaseId)
+function update_data_with_partitioned_dml(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_data_with_timestamp_column.php b/spanner/src/update_data_with_timestamp_column.php
index 6402160a33..c4b1b585c6 100644
--- a/spanner/src/update_data_with_timestamp_column.php
+++ b/spanner/src/update_data_with_timestamp_column.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -43,7 +43,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function update_data_with_timestamp_column($instanceId, $databaseId)
+function update_data_with_timestamp_column(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_database_with_default_leader.php b/spanner/src/update_database_with_default_leader.php
index f9ad762b76..eb1ddeff50 100644
--- a/spanner/src/update_database_with_default_leader.php
+++ b/spanner/src/update_database_with_default_leader.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -37,7 +37,7 @@
* @param string $databaseId The Spanner database ID.
* @param string $defaultLeader The leader instance configuration used by default.
*/
-function update_database_with_default_leader($instanceId, $databaseId, $defaultLeader)
+function update_database_with_default_leader(string $instanceId, string $databaseId, string $defaultLeader): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/update_dml_returning.php b/spanner/src/update_dml_returning.php
new file mode 100644
index 0000000000..987ba8cdc8
--- /dev/null
+++ b/spanner/src/update_dml_returning.php
@@ -0,0 +1,69 @@
+instance($instanceId);
+ $database = $instance->database($databaseId);
+
+ $transaction = $database->transaction();
+
+ // DML returning sql update query
+ $result = $transaction->execute(
+ 'UPDATE Singers SET LastName = @lastName '
+ . 'WHERE SingerId = @singerId THEN RETURN *',
+ [
+ 'parameters' => [
+ 'lastName' => 'Missing',
+ 'singerId' => 12,
+ ]
+ ]
+ );
+ foreach ($result->rows() as $row) {
+ printf(
+ 'Row with SingerId %s updated to (%s, %s, %s)' . PHP_EOL,
+ $row['SingerId'],
+ $row['SingerId'],
+ $row['FirstName'],
+ $row['LastName']
+ );
+ }
+ $transaction->commit();
+}
+// [END spanner_update_dml_returning]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/update_instance_config.php b/spanner/src/update_instance_config.php
new file mode 100644
index 0000000000..f268d24b12
--- /dev/null
+++ b/spanner/src/update_instance_config.php
@@ -0,0 +1,62 @@
+instanceConfiguration($instanceConfigId);
+
+ $operation = $instanceConfiguration->update(
+ [
+ 'displayName' => 'New display name',
+ 'labels' => [
+ 'cloud_spanner_samples' => true,
+ 'updated' => true,
+ ]
+ ]
+ );
+
+ print('Waiting for operation to complete...' . PHP_EOL);
+ $operation->pollUntilComplete();
+
+ printf('Updated instance configuration %s' . PHP_EOL, $instanceConfigId);
+}
+// [END spanner_update_instance_config]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/spanner/src/write_data_with_dml.php b/spanner/src/write_data_with_dml.php
index 0d5abf75d9..cfe5f24b59 100644
--- a/spanner/src/write_data_with_dml.php
+++ b/spanner/src/write_data_with_dml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -40,7 +40,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function write_data_with_dml($instanceId, $databaseId)
+function write_data_with_dml(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/write_data_with_dml_transaction.php b/spanner/src/write_data_with_dml_transaction.php
index 8fca2a39e7..500f6b4ddb 100644
--- a/spanner/src/write_data_with_dml_transaction.php
+++ b/spanner/src/write_data_with_dml_transaction.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -45,7 +45,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function write_data_with_dml_transaction($instanceId, $databaseId)
+function write_data_with_dml_transaction(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/src/write_read_with_dml.php b/spanner/src/write_read_with_dml.php
index 722d35f353..e2b62f693e 100644
--- a/spanner/src/write_read_with_dml.php
+++ b/spanner/src/write_read_with_dml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/spanner/README.md
*/
namespace Google\Cloud\Samples\Spanner;
@@ -40,7 +40,7 @@
* @param string $instanceId The Spanner instance ID.
* @param string $databaseId The Spanner database ID.
*/
-function write_read_with_dml($instanceId, $databaseId)
+function write_read_with_dml(string $instanceId, string $databaseId): void
{
$spanner = new SpannerClient();
$instance = $spanner->instance($instanceId);
diff --git a/spanner/test/spannerBackupTest.php b/spanner/test/spannerBackupTest.php
index e53f5704f5..1d6535f749 100644
--- a/spanner/test/spannerBackupTest.php
+++ b/spanner/test/spannerBackupTest.php
@@ -72,6 +72,9 @@ public static function setUpBeforeClass(): void
if (!extension_loaded('grpc')) {
self::markTestSkipped('Must enable grpc extension.');
}
+ if ('true' !== getenv('GOOGLE_SPANNER_RUN_BACKUP_TESTS')) {
+ self::markTestSkipped('Skipping backup tests.');
+ }
self::$instanceId = self::requireEnv('GOOGLE_SPANNER_INSTANCE_ID');
$spanner = new SpannerClient([
diff --git a/spanner/test/spannerPgTest.php b/spanner/test/spannerPgTest.php
index 1611bf957f..e1371b665d 100644
--- a/spanner/test/spannerPgTest.php
+++ b/spanner/test/spannerPgTest.php
@@ -22,20 +22,15 @@
use Google\Cloud\Spanner\Transaction;
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
use Google\Cloud\TestUtils\TestTrait;
-use PHPUnitRetry\RetryTrait;
use PHPUnit\Framework\TestCase;
-/**
- * @retryAttempts 3
- * @retryDelayMethod exponentialBackoff
- */
class spannerPgTest extends TestCase
{
use TestTrait {
TestTrait::runFunctionSnippet as traitRunFunctionSnippet;
}
- use RetryTrait, EventuallyConsistentTestTrait;
+ use EventuallyConsistentTestTrait;
/** @var string instanceId */
protected static $instanceId;
@@ -49,6 +44,9 @@ class spannerPgTest extends TestCase
/** @var $lastUpdateData int */
protected static $lastUpdateDataTimestamp;
+ /** @var $jsonbTable string */
+ protected static $jsonbTable;
+
public static function setUpBeforeClass(): void
{
self::checkProjectEnvVars();
@@ -245,6 +243,58 @@ public function testNumericDataType()
$this->assertStringContainsString('Inserted 1 venue(s) with NaN revenue.', $output);
}
+ /**
+ * @depends testCreateDatabase
+ */
+ public function testJsonbAddColumn()
+ {
+ self::$jsonbTable = 'Venues' . time() . rand();
+
+ // Create the table for our JSONB tests.
+ $database = self::$instance->database(self::$databaseId);
+ $op = $database->updateDdl(
+ sprintf('CREATE TABLE %s (
+ VenueId bigint NOT NULL PRIMARY KEY
+ )', self::$jsonbTable)
+ );
+
+ $op->pollUntilComplete();
+
+ // Now run the test
+ $output = $this->runFunctionSnippet('pg_add_jsonb_column', [
+ self::$instanceId, self::$databaseId, self::$jsonbTable
+ ]);
+ self::$lastUpdateDataTimestamp = time();
+
+ $this->assertStringContainsString(sprintf('Added column VenueDetails on table %s.', self::$jsonbTable), $output);
+ }
+
+ /**
+ * @depends testJsonbAddColumn
+ */
+ public function testJsonbUpdateData()
+ {
+ $output = $this->runFunctionSnippet('pg_jsonb_update_data', [
+ self::$instanceId, self::$databaseId, self::$jsonbTable
+ ]);
+ self::$lastUpdateDataTimestamp = time();
+
+ $this->assertStringContainsString(sprintf('Inserted/updated 3 rows in table %s', self::$jsonbTable), $output);
+ }
+
+ /**
+ * @depends testJsonbUpdateData
+ */
+ public function testJsonbQueryParam()
+ {
+ $output = $this->runFunctionSnippet('pg_jsonb_query_parameter', [
+ self::$instanceId, self::$databaseId, self::$jsonbTable
+ ]);
+ self::$lastUpdateDataTimestamp = time();
+
+ $this->assertEquals('VenueId: 1, VenueDetails: {"open": true, "rating": 9}' . PHP_EOL, $output);
+ }
+
/**
* @depends testCreateDatabase
*/
@@ -313,6 +363,50 @@ public function testDmlGettingStartedUpdate()
$this->assertStringContainsString('Marketing budget updated.', $output);
}
+ /**
+ * @depends testCreateDatabase
+ */
+ public function testDmlReturningInsert()
+ {
+ $output = $this->runFunctionSnippet('pg_insert_dml_returning');
+
+ $expectedOutput = sprintf('Row (16, Melissa, Garcia) inserted');
+ $this->assertStringContainsString($expectedOutput, $output);
+
+ $expectedOutput = sprintf('Row (17, Russell, Morales) inserted');
+ $this->assertStringContainsString('Russell', $output);
+
+ $expectedOutput = sprintf('Row (18, Jacqueline, Long) inserted');
+ $this->assertStringContainsString('Jacqueline', $output);
+
+ $expectedOutput = sprintf('Row (19, Dylan, Shaw) inserted');
+ $this->assertStringContainsString('Dylan', $output);
+ }
+
+ /**
+ * @depends testDmlReturningInsert
+ */
+ public function testDmlReturningUpdate()
+ {
+ $output = $this->runFunctionSnippet('pg_update_dml_returning');
+
+ $expectedOutput = sprintf(
+ 'Row with singerid 16 updated to (16, Melissa, Missing)'
+ );
+ $this->assertStringContainsString($expectedOutput, $output);
+ }
+
+ /**
+ * @depends testDmlReturningUpdate
+ */
+ public function testDmlReturningDelete()
+ {
+ $output = $this->runFunctionSnippet('pg_delete_dml_returning');
+
+ $expectedOutput = sprintf('Row (16, Melissa, Missing) deleted');
+ $this->assertStringContainsString($expectedOutput, $output);
+ }
+
public static function tearDownAfterClass(): void
{
// Clean up
diff --git a/spanner/test/spannerTest.php b/spanner/test/spannerTest.php
index 4b70793ec5..f18a4912d7 100644
--- a/spanner/test/spannerTest.php
+++ b/spanner/test/spannerTest.php
@@ -17,6 +17,7 @@
namespace Google\Cloud\Samples\Spanner;
+use Google\Cloud\Spanner\InstanceConfiguration;
use Google\Cloud\Spanner\SpannerClient;
use Google\Cloud\Spanner\Instance;
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
@@ -85,6 +86,15 @@ class spannerTest extends TestCase
/** @var $lastUpdateData int */
protected static $lastUpdateDataTimestamp;
+ /** @var string $baseConfigId */
+ protected static $baseConfigId;
+
+ /** @var string $customInstanceConfigId */
+ protected static $customInstanceConfigId;
+
+ /** @var InstanceConfiguration $customInstanceConfig */
+ protected static $customInstanceConfig;
+
public static function setUpBeforeClass(): void
{
self::checkProjectEnvVars();
@@ -113,6 +123,9 @@ public static function setUpBeforeClass(): void
self::$defaultLeader = 'us-central1';
self::$updatedDefaultLeader = 'us-east4';
self::$multiInstance = $spanner->instance(self::$multiInstanceId);
+ self::$baseConfigId = 'nam7';
+ self::$customInstanceConfigId = 'custom-' . time() . rand();
+ self::$customInstanceConfig = $spanner->instanceConfiguration(self::$customInstanceConfigId);
}
public function testCreateInstance()
@@ -133,6 +146,64 @@ public function testCreateInstanceWithProcessingUnits()
$this->assertStringContainsString('Created instance test-', $output);
}
+ public function testCreateInstanceConfig()
+ {
+ $output = $this->runFunctionSnippet('create_instance_config', [
+ self::$customInstanceConfigId, self::$baseConfigId
+ ]);
+
+ $this->assertStringContainsString(sprintf('Created instance configuration %s', self::$customInstanceConfigId), $output);
+ }
+
+ /**
+ * @depends testCreateInstanceConfig
+ */
+ public function testUpdateInstanceConfig()
+ {
+ $output = $this->runFunctionSnippet('update_instance_config', [
+ self::$customInstanceConfigId
+ ]);
+
+ $this->assertStringContainsString(sprintf('Updated instance configuration %s', self::$customInstanceConfigId), $output);
+ }
+
+ /**
+ * @depends testUpdateInstanceConfig
+ */
+ public function testDeleteInstanceConfig()
+ {
+ $output = $this->runFunctionSnippet('delete_instance_config', [
+ self::$customInstanceConfigId
+ ]);
+ $this->assertStringContainsString(sprintf('Deleted instance configuration %s', self::$customInstanceConfigId), $output);
+ }
+
+ /**
+ * @depends testUpdateInstanceConfig
+ */
+ public function testListInstanceConfigOperations()
+ {
+ $output = $this->runFunctionSnippet('list_instance_config_operations', [
+ self::$customInstanceConfigId
+ ]);
+
+ $this->assertStringContainsString(
+ sprintf(
+ 'Instance config operation for %s of type %s has status done.',
+ self::$customInstanceConfigId,
+ 'type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceConfigMetadata'
+ ),
+ $output);
+
+ $this->assertStringContainsString(
+ sprintf(
+ 'Instance config operation for %s of type %s has status done.',
+ self::$customInstanceConfigId,
+ 'type.googleapis.com/google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata'
+ ),
+ $output);
+ }
+
/**
* @depends testCreateInstance
*/
@@ -802,6 +873,81 @@ public function testCreateClientWithQueryOptions()
});
}
+ /**
+ * @depends testAddColumn
+ */
+ public function testSpannerDmlBatchUpdateRequestPriority()
+ {
+ $output = $this->runFunctionSnippet('dml_batch_update_request_priority');
+ $this->assertStringContainsString('Executed 2 SQL statements using Batch DML with PRIORITY_LOW.', $output);
+ }
+
+ /**
+ * @depends testCreateDatabase
+ */
+ public function testDmlReturningInsert()
+ {
+ $output = $this->runFunctionSnippet('insert_dml_returning');
+
+ $expectedOutput = sprintf('Row (12, Melissa, Garcia) inserted');
+ $this->assertStringContainsString($expectedOutput, $output);
+
+ $expectedOutput = sprintf('Row (13, Russell, Morales) inserted');
+ $this->assertStringContainsString('Russell', $output);
+
+ $expectedOutput = sprintf('Row (14, Jacqueline, Long) inserted');
+ $this->assertStringContainsString('Jacqueline', $output);
+
+ $expectedOutput = sprintf('Row (15, Dylan, Shaw) inserted');
+ $this->assertStringContainsString('Dylan', $output);
+ }
+
+ /**
+ * @depends testDmlReturningInsert
+ */
+ public function testDmlReturningUpdate()
+ {
+ $output = $this->runFunctionSnippet('update_dml_returning');
+
+ $expectedOutput = sprintf(
+ 'Row with SingerId 12 updated to (12, Melissa, Missing)'
+ );
+ $this->assertStringContainsString($expectedOutput, $output);
+ }
+
+ /**
+ * @depends testDmlReturningUpdate
+ */
+ public function testDmlReturningDelete()
+ {
+ $output = $this->runFunctionSnippet('delete_dml_returning');
+
+ $expectedOutput = sprintf('Row (12, Melissa, Missing) deleted');
+ $this->assertStringContainsString($expectedOutput, $output);
+ }
+
+ /**
+ * @depends testCreateDatabase
+ */
+ public function testAddDropDatabaseRole()
+ {
+ $output = $this->runFunctionSnippet('add_drop_database_role');
+ $this->assertStringContainsString('Waiting for create role and grant operation to complete... ' . PHP_EOL, $output);
+ $this->assertStringContainsString('Created roles new_parent and new_child and granted privileges ' . PHP_EOL, $output);
+ $this->assertStringContainsString('Waiting for revoke role and drop role operation to complete... ' . PHP_EOL, $output);
+ $this->assertStringContainsString('Revoked privileges and dropped roles new_child and new_parent ' . PHP_EOL, $output);
+ }
+
+ /**
+ * @depends testUpdateData
+ */
+ public function testReadWriteRetry()
+ {
+ $output = $this->runFunctionSnippet('read_write_retry');
+ $this->assertStringContainsString('Setting second album\'s budget as the first album\'s budget.', $output);
+ $this->assertStringContainsString('Transaction complete.', $output);
+ }
+
private function testGetInstanceConfig()
{
$output = $this->runFunctionSnippet('get_instance_config', [
@@ -893,5 +1039,8 @@ public static function tearDownAfterClass(): void
$database->drop();
self::$instance->delete();
self::$lowCostInstance->delete();
+ if (self::$customInstanceConfig->exists()) {
+ self::$customInstanceConfig->delete();
+ }
}
}
diff --git a/speech/src/base64_encode_audio.php b/speech/src/base64_encode_audio.php
index de6b4dc235..dd6ac32641 100644
--- a/speech/src/base64_encode_audio.php
+++ b/speech/src/base64_encode_audio.php
@@ -18,19 +18,23 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/speech/README.md
*/
-if (count($argv) != 2) {
- return print("Usage: php base64_encode_audio.php AUDIO_FILE\n");
-}
-list($_, $audioFile) = $argv;
+namespace Google\Cloud\Samples\Speech;
# [START base64_audio]
-/** Uncomment and populate these variables in your code */
-// $audioFile = 'path to an audio file';
+/**
+ * @param string $audioFile path to an audio file
+ */
+function base64_encode_audio(string $audioFile)
+{
+ $audioFileResource = fopen($audioFile, 'r');
+ $base64Audio = base64_encode(stream_get_contents($audioFileResource));
+ print($base64Audio);
+}
+# [END base64_audio]
-$audioFileResource = fopen($audioFile, 'r');
-$base64Audio = base64_encode(stream_get_contents($audioFileResource));
-print($base64Audio);
-# [end base64_audio]
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/multi_region_gcs.php b/speech/src/multi_region_gcs.php
index 15a5d890b0..2d65a9a783 100644
--- a/speech/src/multi_region_gcs.php
+++ b/speech/src/multi_region_gcs.php
@@ -15,46 +15,53 @@
* limitations under the License.
*/
-# [START speech_transcribe_with_multi_region_gcs]
-# Includes the autoloader for libraries installed with composer
-require __DIR__ . '/../vendor/autoload.php';
+namespace Google\Cloud\Samples\Speech;
+# [START speech_transcribe_with_multi_region_gcs]
# Imports the Google Cloud client library
use Google\Cloud\Speech\V1\SpeechClient;
use Google\Cloud\Speech\V1\RecognitionAudio;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-# The name of the audio file to transcribe
-$gcsURI = 'gs://cloud-samples-data/speech/brooklyn_bridge.raw';
+/**
+ * @param string $uri The Cloud Storage object to transcribe
+ * e.x. gs://cloud-samples-data/speech/brooklyn_bridge.raw
+ */
+function multi_region_gcs(string $uri)
+{
+ # set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setUri($uri);
-# set string as audio content
-$audio = (new RecognitionAudio())
- ->setUri($gcsURI);
+ # The audio file's encoding, sample rate and language
+ $config = new RecognitionConfig([
+ 'encoding' => AudioEncoding::LINEAR16,
+ 'sample_rate_hertz' => 16000,
+ 'language_code' => 'en-US'
+ ]);
-# The audio file's encoding, sample rate and language
-$config = new RecognitionConfig([
- 'encoding' => AudioEncoding::LINEAR16,
- 'sample_rate_hertz' => 16000,
- 'language_code' => 'en-US'
-]);
+ # Specify a new endpoint.
+ $options = ['apiEndpoint' => 'eu-speech.googleapis.com'];
-# Specify a new endpoint.
-$options = ['apiEndpoint' => 'eu-speech.googleapis.com'];
+ # Instantiates a client
+ $client = new SpeechClient($options);
-# Instantiates a client
-$client = new SpeechClient($options);
+ # Detects speech in the audio file
+ $response = $client->recognize($config, $audio);
-# Detects speech in the audio file
-$response = $client->recognize($config, $audio);
+ # Print most likely transcription
+ foreach ($response->getResults() as $result) {
+ $alternatives = $result->getAlternatives();
+ $mostLikely = $alternatives[0];
+ $transcript = $mostLikely->getTranscript();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ }
-# Print most likely transcription
-foreach ($response->getResults() as $result) {
- $alternatives = $result->getAlternatives();
- $mostLikely = $alternatives[0];
- $transcript = $mostLikely->getTranscript();
- printf('Transcript: %s' . PHP_EOL, $transcript);
+ $client->close();
}
-
-$client->close();
# [END speech_transcribe_with_multi_region_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/profanity_filter.php b/speech/src/profanity_filter.php
index 5430b3a288..cbe5ba5554 100644
--- a/speech/src/profanity_filter.php
+++ b/speech/src/profanity_filter.php
@@ -12,56 +12,55 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# [START speech_profanity_filter]
-
-# Includes the autoloader for libraries installed with composer
-require __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return print("Usage: php profanity_filter.php AUDIO_FILE\n");
-}
-list($_, $audioFile) = $argv;
+namespace Google\Cloud\Samples\Speech;
+# [START speech_profanity_filter]
use Google\Cloud\Speech\V1\SpeechClient;
use Google\Cloud\Speech\V1\RecognitionAudio;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** Uncomment and populate these variables in your code */
-// $audioFile = 'path to an audio file';
+/**
+ * @param string $audioFile path to an audio file
+ */
+function profanity_filter(string $audioFile)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 32000;
+ $languageCode = 'en-US';
+ $profanityFilter = true;
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 32000;
-$languageCode = 'en-US';
-$profanityFilter = true;
+ // get contents of a file into a string
+ $content = file_get_contents($audioFile);
-// get contents of a file into a string
-$content = file_get_contents($audioFile);
+ // set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setContent($content);
-// set string as audio content
-$audio = (new RecognitionAudio())
- ->setContent($content);
+ // set config
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode)
+ ->setProfanityFilter($profanityFilter);
-// set config
-$config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode)
- ->setProfanityFilter($profanityFilter);
+ // create the speech client
+ $client = new SpeechClient();
-// create the speech client
-$client = new SpeechClient();
+ # Detects speech in the audio file
+ $response = $client->recognize($config, $audio);
-# Detects speech in the audio file
-$response = $client->recognize($config, $audio);
+ # Print most likely transcription
+ foreach ($response->getResults() as $result) {
+ $transcript = $result->getAlternatives()[0]->getTranscript();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ }
-# Print most likely transcription
-foreach ($response->getResults() as $result) {
- $transcript = $result->getAlternatives()[0]->getTranscript();
- printf('Transcript: %s' . PHP_EOL, $transcript);
+ $client->close();
}
-
-$client->close();
-
# [END speech_profanity_filter]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/profanity_filter_gcs.php b/speech/src/profanity_filter_gcs.php
index ddcfb569d8..609e19e9c1 100644
--- a/speech/src/profanity_filter_gcs.php
+++ b/speech/src/profanity_filter_gcs.php
@@ -12,55 +12,52 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# [START speech_profanity_filter_gcs]
-# Includes the autoloader for libraries installed with composer
-require __DIR__ . '/../vendor/autoload.php';
-
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return print("Usage: php profanity_filter_gcs.php AUDIO_FILE\n");
-}
-list($_, $audioFile) = $argv;
+namespace Google\Cloud\Samples\Speech;
+# [START speech_profanity_filter_gcs]
use Google\Cloud\Speech\V1\SpeechClient;
use Google\Cloud\Speech\V1\RecognitionAudio;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** The Cloud Storage object to transcribe */
-// $uri = 'The Cloud Storage object to transcribe (gs://your-bucket-name/your-object-name)';
-
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 32000;
-$languageCode = 'en-US';
-$profanityFilter = true;
-
-// set string as audio content
-$audio = (new RecognitionAudio())
- ->setUri($audioFile);
-
-// set config
-$config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode)
- ->setProfanityFilter($profanityFilter);
-
-// create the speech client
-$client = new SpeechClient();
-
-# Detects speech in the audio file
-$response = $client->recognize($config, $audio);
-
-# Print most likely transcription
-foreach ($response->getResults() as $result) {
- $transcript = $result->getAlternatives()[0]->getTranscript();
- printf('Transcript: %s' . PHP_EOL, $transcript);
+/**
+ * @param string $uri The Cloud Storage object to transcribe (gs://your-bucket-name/your-object-name)
+ */
+function profanity_filter_gcs(string $uri)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 32000;
+ $languageCode = 'en-US';
+ $profanityFilter = true;
+
+ // set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setUri($uri);
+
+ // set config
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode)
+ ->setProfanityFilter($profanityFilter);
+
+ // create the speech client
+ $client = new SpeechClient();
+
+ # Detects speech in the audio file
+ $response = $client->recognize($config, $audio);
+
+ # Print most likely transcription
+ foreach ($response->getResults() as $result) {
+ $transcript = $result->getAlternatives()[0]->getTranscript();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ }
+
+ $client->close();
}
-
-$client->close();
-
# [END speech_profanity_filter_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/streaming_recognize.php b/speech/src/streaming_recognize.php
index 5207b8218a..2465de4aee 100644
--- a/speech/src/streaming_recognize.php
+++ b/speech/src/streaming_recognize.php
@@ -18,16 +18,10 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/speech/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return print("Usage: php streaming_recognize.php AUDIO_FILE\n");
-}
-list($_, $audioFile) = $argv;
+namespace Google\Cloud\Samples\Speech;
# [START speech_transcribe_streaming]
use Google\Cloud\Speech\V1\SpeechClient;
@@ -36,43 +30,50 @@
use Google\Cloud\Speech\V1\StreamingRecognizeRequest;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** Uncomment and populate these variables in your code */
-// $audioFile = 'path to an audio file';
-
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 32000;
-$languageCode = 'en-US';
+/**
+ * @param string $audioFile path to an audio file
+ */
+function streaming_recognize(string $audioFile)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 32000;
+ $languageCode = 'en-US';
-$speechClient = new SpeechClient();
-try {
- $config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode);
+ $speechClient = new SpeechClient();
+ try {
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode);
- $strmConfig = new StreamingRecognitionConfig();
- $strmConfig->setConfig($config);
+ $strmConfig = new StreamingRecognitionConfig();
+ $strmConfig->setConfig($config);
- $strmReq = new StreamingRecognizeRequest();
- $strmReq->setStreamingConfig($strmConfig);
+ $strmReq = new StreamingRecognizeRequest();
+ $strmReq->setStreamingConfig($strmConfig);
- $strm = $speechClient->streamingRecognize();
- $strm->write($strmReq);
+ $strm = $speechClient->streamingRecognize();
+ $strm->write($strmReq);
- $strmReq = new StreamingRecognizeRequest();
- $content = file_get_contents($audioFile);
- $strmReq->setAudioContent($content);
- $strm->write($strmReq);
+ $strmReq = new StreamingRecognizeRequest();
+ $content = file_get_contents($audioFile);
+ $strmReq->setAudioContent($content);
+ $strm->write($strmReq);
- foreach ($strm->closeWriteAndReadAll() as $response) {
- foreach ($response->getResults() as $result) {
- foreach ($result->getAlternatives() as $alt) {
- printf("Transcription: %s\n", $alt->getTranscript());
+ foreach ($strm->closeWriteAndReadAll() as $response) {
+ foreach ($response->getResults() as $result) {
+ foreach ($result->getAlternatives() as $alt) {
+ printf("Transcription: %s\n", $alt->getTranscript());
+ }
}
}
+ } finally {
+ $speechClient->close();
}
-} finally {
- $speechClient->close();
}
# [END speech_transcribe_streaming]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/transcribe_async.php b/speech/src/transcribe_async.php
index 50b93cae83..99fe72157c 100644
--- a/speech/src/transcribe_async.php
+++ b/speech/src/transcribe_async.php
@@ -18,16 +18,10 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/speech/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return print("Usage: php transcribe_async.php AUDIO_FILE\n");
-}
-list($_, $audioFile) = $argv;
+namespace Google\Cloud\Samples\Speech;
# [START speech_transcribe_async]
use Google\Cloud\Speech\V1\SpeechClient;
@@ -35,50 +29,57 @@
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** Uncomment and populate these variables in your code */
-// $audioFile = 'path to an audio file';
-
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 32000;
-$languageCode = 'en-US';
+/**
+ * @param string $audioFile path to an audio file
+ */
+function transcribe_async(string $audioFile)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 32000;
+ $languageCode = 'en-US';
-// get contents of a file into a string
-$content = file_get_contents($audioFile);
+ // get contents of a file into a string
+ $content = file_get_contents($audioFile);
-// set string as audio content
-$audio = (new RecognitionAudio())
- ->setContent($content);
+ // set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setContent($content);
-// set config
-$config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode);
+ // set config
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode);
-// create the speech client
-$client = new SpeechClient();
+ // create the speech client
+ $client = new SpeechClient();
-// create the asyncronous recognize operation
-$operation = $client->longRunningRecognize($config, $audio);
-$operation->pollUntilComplete();
+ // create the asyncronous recognize operation
+ $operation = $client->longRunningRecognize($config, $audio);
+ $operation->pollUntilComplete();
-if ($operation->operationSucceeded()) {
- $response = $operation->getResult();
+ if ($operation->operationSucceeded()) {
+ $response = $operation->getResult();
- // each result is for a consecutive portion of the audio. iterate
- // through them to get the transcripts for the entire audio file.
- foreach ($response->getResults() as $result) {
- $alternatives = $result->getAlternatives();
- $mostLikely = $alternatives[0];
- $transcript = $mostLikely->getTranscript();
- $confidence = $mostLikely->getConfidence();
- printf('Transcript: %s' . PHP_EOL, $transcript);
- printf('Confidence: %s' . PHP_EOL, $confidence);
+ // each result is for a consecutive portion of the audio. iterate
+ // through them to get the transcripts for the entire audio file.
+ foreach ($response->getResults() as $result) {
+ $alternatives = $result->getAlternatives();
+ $mostLikely = $alternatives[0];
+ $transcript = $mostLikely->getTranscript();
+ $confidence = $mostLikely->getConfidence();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ printf('Confidence: %s' . PHP_EOL, $confidence);
+ }
+ } else {
+ print_r($operation->getError());
}
-} else {
- print_r($operation->getError());
-}
-$client->close();
+ $client->close();
+}
# [END speech_transcribe_async]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/transcribe_async_gcs.php b/speech/src/transcribe_async_gcs.php
index 0c9f33db36..75d050091f 100644
--- a/speech/src/transcribe_async_gcs.php
+++ b/speech/src/transcribe_async_gcs.php
@@ -18,16 +18,10 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/speech/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return print("Usage: php transcribe_async_gcs.php URI\n");
-}
-list($_, $uri) = $argv;
+namespace Google\Cloud\Samples\Speech;
# [START speech_transcribe_async_gcs]
use Google\Cloud\Speech\V1\SpeechClient;
@@ -35,47 +29,54 @@
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** Uncomment and populate these variables in your code */
-// $uri = 'The Cloud Storage object to transcribe (gs://your-bucket-name/your-object-name)';
-
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 32000;
-$languageCode = 'en-US';
+/**
+ * @param string $uri The Cloud Storage object to transcribe (gs://your-bucket-name/your-object-name)
+ */
+function transcribe_async_gcs(string $uri)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 32000;
+ $languageCode = 'en-US';
-// set string as audio content
-$audio = (new RecognitionAudio())
- ->setUri($uri);
+ // set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setUri($uri);
-// set config
-$config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode);
+ // set config
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode);
-// create the speech client
-$client = new SpeechClient();
+ // create the speech client
+ $client = new SpeechClient();
-// create the asyncronous recognize operation
-$operation = $client->longRunningRecognize($config, $audio);
-$operation->pollUntilComplete();
+ // create the asyncronous recognize operation
+ $operation = $client->longRunningRecognize($config, $audio);
+ $operation->pollUntilComplete();
-if ($operation->operationSucceeded()) {
- $response = $operation->getResult();
+ if ($operation->operationSucceeded()) {
+ $response = $operation->getResult();
- // each result is for a consecutive portion of the audio. iterate
- // through them to get the transcripts for the entire audio file.
- foreach ($response->getResults() as $result) {
- $alternatives = $result->getAlternatives();
- $mostLikely = $alternatives[0];
- $transcript = $mostLikely->getTranscript();
- $confidence = $mostLikely->getConfidence();
- printf('Transcript: %s' . PHP_EOL, $transcript);
- printf('Confidence: %s' . PHP_EOL, $confidence);
+ // each result is for a consecutive portion of the audio. iterate
+ // through them to get the transcripts for the entire audio file.
+ foreach ($response->getResults() as $result) {
+ $alternatives = $result->getAlternatives();
+ $mostLikely = $alternatives[0];
+ $transcript = $mostLikely->getTranscript();
+ $confidence = $mostLikely->getConfidence();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ printf('Confidence: %s' . PHP_EOL, $confidence);
+ }
+ } else {
+ print_r($operation->getError());
}
-} else {
- print_r($operation->getError());
-}
-$client->close();
+ $client->close();
+}
# [END speech_transcribe_async_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/transcribe_async_words.php b/speech/src/transcribe_async_words.php
index 7ecb1e3dc1..0e7f12c0d3 100644
--- a/speech/src/transcribe_async_words.php
+++ b/speech/src/transcribe_async_words.php
@@ -18,16 +18,10 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/speech/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return print("Usage: php transcribe_asyc_words.php AUDIO_FILE\n");
-}
-list($_, $audioFile) = $argv;
+namespace Google\Cloud\Samples\Speech;
# [START speech_transcribe_async_word_time_offsets_gcs]
use Google\Cloud\Speech\V1\SpeechClient;
@@ -35,62 +29,69 @@
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** Uncomment and populate these variables in your code */
-// $audioFile = 'path to an audio file';
-
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 32000;
-$languageCode = 'en-US';
+/**
+ * @param string $audioFile path to an audio file
+ */
+function transcribe_async_words(string $audioFile)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 32000;
+ $languageCode = 'en-US';
-// When true, time offsets for every word will be included in the response.
-$enableWordTimeOffsets = true;
+ // When true, time offsets for every word will be included in the response.
+ $enableWordTimeOffsets = true;
-// get contents of a file into a string
-$content = file_get_contents($audioFile);
+ // get contents of a file into a string
+ $content = file_get_contents($audioFile);
-// set string as audio content
-$audio = (new RecognitionAudio())
- ->setContent($content);
+ // set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setContent($content);
-// set config
-$config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode)
- ->setEnableWordTimeOffsets($enableWordTimeOffsets);
+ // set config
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode)
+ ->setEnableWordTimeOffsets($enableWordTimeOffsets);
-// create the speech client
-$client = new SpeechClient();
+ // create the speech client
+ $client = new SpeechClient();
-// create the asyncronous recognize operation
-$operation = $client->longRunningRecognize($config, $audio);
-$operation->pollUntilComplete();
+ // create the asyncronous recognize operation
+ $operation = $client->longRunningRecognize($config, $audio);
+ $operation->pollUntilComplete();
-if ($operation->operationSucceeded()) {
- $response = $operation->getResult();
+ if ($operation->operationSucceeded()) {
+ $response = $operation->getResult();
- // each result is for a consecutive portion of the audio. iterate
- // through them to get the transcripts for the entire audio file.
- foreach ($response->getResults() as $result) {
- $alternatives = $result->getAlternatives();
- $mostLikely = $alternatives[0];
- $transcript = $mostLikely->getTranscript();
- $confidence = $mostLikely->getConfidence();
- printf('Transcript: %s' . PHP_EOL, $transcript);
- printf('Confidence: %s' . PHP_EOL, $confidence);
- foreach ($mostLikely->getWords() as $wordInfo) {
- $startTime = $wordInfo->getStartTime();
- $endTime = $wordInfo->getEndTime();
- printf(' Word: %s (start: %s, end: %s)' . PHP_EOL,
- $wordInfo->getWord(),
- $startTime->serializeToJsonString(),
- $endTime->serializeToJsonString());
+ // each result is for a consecutive portion of the audio. iterate
+ // through them to get the transcripts for the entire audio file.
+ foreach ($response->getResults() as $result) {
+ $alternatives = $result->getAlternatives();
+ $mostLikely = $alternatives[0];
+ $transcript = $mostLikely->getTranscript();
+ $confidence = $mostLikely->getConfidence();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ printf('Confidence: %s' . PHP_EOL, $confidence);
+ foreach ($mostLikely->getWords() as $wordInfo) {
+ $startTime = $wordInfo->getStartTime();
+ $endTime = $wordInfo->getEndTime();
+ printf(' Word: %s (start: %s, end: %s)' . PHP_EOL,
+ $wordInfo->getWord(),
+ $startTime->serializeToJsonString(),
+ $endTime->serializeToJsonString());
+ }
}
+ } else {
+ print_r($operation->getError());
}
-} else {
- print_r($operation->getError());
-}
-$client->close();
+ $client->close();
+}
# [END speech_transcribe_async_word_time_offsets_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/transcribe_auto_punctuation.php b/speech/src/transcribe_auto_punctuation.php
index 058e801fa5..2eb1808f05 100644
--- a/speech/src/transcribe_auto_punctuation.php
+++ b/speech/src/transcribe_auto_punctuation.php
@@ -18,16 +18,10 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/speech/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return print("Usage: php transcribe_auto_punctiation.php AUDIO_FILE\n");
-}
-list($_, $audioFile) = $argv;
+namespace Google\Cloud\Samples\Speech;
# [START speech_transcribe_auto_punctuation]
use Google\Cloud\Speech\V1\SpeechClient;
@@ -35,44 +29,51 @@
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** Uncomment and populate these variables in your code */
-// $audioFile = 'path to an audio file';
+/**
+ * @param string $audioFile path to an audio file
+ */
+function transcribe_auto_punctuation(string $audioFile)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 32000;
+ $languageCode = 'en-US';
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 32000;
-$languageCode = 'en-US';
+ // get contents of a file into a string
+ $content = file_get_contents($audioFile);
-// get contents of a file into a string
-$content = file_get_contents($audioFile);
+ // set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setContent($content);
-// set string as audio content
-$audio = (new RecognitionAudio())
- ->setContent($content);
+ // set config
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode)
+ ->setEnableAutomaticPunctuation(true);
-// set config
-$config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode)
- ->setEnableAutomaticPunctuation(true);
+ // create the speech client
+ $client = new SpeechClient();
-// create the speech client
-$client = new SpeechClient();
+ // make the API call
+ $response = $client->recognize($config, $audio);
+ $results = $response->getResults();
-// make the API call
-$response = $client->recognize($config, $audio);
-$results = $response->getResults();
+ // print results
+ foreach ($results as $result) {
+ $alternatives = $result->getAlternatives();
+ $mostLikely = $alternatives[0];
+ $transcript = $mostLikely->getTranscript();
+ $confidence = $mostLikely->getConfidence();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ printf('Confidence: %s' . PHP_EOL, $confidence);
+ }
-// print results
-foreach ($results as $result) {
- $alternatives = $result->getAlternatives();
- $mostLikely = $alternatives[0];
- $transcript = $mostLikely->getTranscript();
- $confidence = $mostLikely->getConfidence();
- printf('Transcript: %s' . PHP_EOL, $transcript);
- printf('Confidence: %s' . PHP_EOL, $confidence);
+ $client->close();
}
-
-$client->close();
# [END speech_transcribe_auto_punctuation]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/transcribe_enhanced_model.php b/speech/src/transcribe_enhanced_model.php
index 5fdd6ee3e9..8341552523 100644
--- a/speech/src/transcribe_enhanced_model.php
+++ b/speech/src/transcribe_enhanced_model.php
@@ -18,16 +18,10 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/speech/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return print("Usage: php transcribe_enhanced_model.php AUDIO_FILE\n");
-}
-list($_, $audioFile) = $argv;
+namespace Google\Cloud\Samples\Speech;
# [START speech_transcribe_enhanced_model]
use Google\Cloud\Speech\V1\SpeechClient;
@@ -35,45 +29,52 @@
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** Uncomment and populate these variables in your code */
-// $audioFile = 'path to an audio file';
+/**
+ * @param string $audioFile path to an audio file
+ */
+function transcribe_enhanced_model(string $audioFile)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 8000;
+ $languageCode = 'en-US';
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 8000;
-$languageCode = 'en-US';
+ // get contents of a file into a string
+ $content = file_get_contents($audioFile);
-// get contents of a file into a string
-$content = file_get_contents($audioFile);
+ // set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setContent($content);
-// set string as audio content
-$audio = (new RecognitionAudio())
- ->setContent($content);
+ // set config
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode)
+ ->setUseEnhanced(true)
+ ->setModel('phone_call');
-// set config
-$config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode)
- ->setUseEnhanced(true)
- ->setModel('phone_call');
+ // create the speech client
+ $client = new SpeechClient();
-// create the speech client
-$client = new SpeechClient();
+ // make the API call
+ $response = $client->recognize($config, $audio);
+ $results = $response->getResults();
-// make the API call
-$response = $client->recognize($config, $audio);
-$results = $response->getResults();
+ // print results
+ foreach ($results as $result) {
+ $alternatives = $result->getAlternatives();
+ $mostLikely = $alternatives[0];
+ $transcript = $mostLikely->getTranscript();
+ $confidence = $mostLikely->getConfidence();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ printf('Confidence: %s' . PHP_EOL, $confidence);
+ }
-// print results
-foreach ($results as $result) {
- $alternatives = $result->getAlternatives();
- $mostLikely = $alternatives[0];
- $transcript = $mostLikely->getTranscript();
- $confidence = $mostLikely->getConfidence();
- printf('Transcript: %s' . PHP_EOL, $transcript);
- printf('Confidence: %s' . PHP_EOL, $confidence);
+ $client->close();
}
-
-$client->close();
# [END speech_transcribe_enhanced_model]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/transcribe_model_selection.php b/speech/src/transcribe_model_selection.php
index 39d1401855..3d5a97385f 100644
--- a/speech/src/transcribe_model_selection.php
+++ b/speech/src/transcribe_model_selection.php
@@ -18,16 +18,10 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/speech/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 3) {
- return print("Usage: php transcribe_model_selection.php AUDIO_FILE MODEL\n");
-}
-list($_, $audioFile, $model) = $argv;
+namespace Google\Cloud\Samples\Speech;
# [START speech_transcribe_model_selection]
use Google\Cloud\Speech\V1\SpeechClient;
@@ -35,45 +29,52 @@
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** Uncomment and populate these variables in your code */
-// $audioFile = 'path to an audio file';
-// $model = 'video';
+/**
+ * @param string $audioFile path to an audio file
+ * @param string $model video
+ */
+function transcribe_model_selection(string $audioFile, string $model)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 32000;
+ $languageCode = 'en-US';
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 32000;
-$languageCode = 'en-US';
+ // get contents of a file into a string
+ $content = file_get_contents($audioFile);
-// get contents of a file into a string
-$content = file_get_contents($audioFile);
+ // set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setContent($content);
-// set string as audio content
-$audio = (new RecognitionAudio())
- ->setContent($content);
+ // set config
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode)
+ ->setModel($model);
-// set config
-$config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode)
- ->setModel($model);
+ // create the speech client
+ $client = new SpeechClient();
-// create the speech client
-$client = new SpeechClient();
+ // make the API call
+ $response = $client->recognize($config, $audio);
+ $results = $response->getResults();
-// make the API call
-$response = $client->recognize($config, $audio);
-$results = $response->getResults();
+ // print results
+ foreach ($results as $result) {
+ $alternatives = $result->getAlternatives();
+ $mostLikely = $alternatives[0];
+ $transcript = $mostLikely->getTranscript();
+ $confidence = $mostLikely->getConfidence();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ printf('Confidence: %s' . PHP_EOL, $confidence);
+ }
-// print results
-foreach ($results as $result) {
- $alternatives = $result->getAlternatives();
- $mostLikely = $alternatives[0];
- $transcript = $mostLikely->getTranscript();
- $confidence = $mostLikely->getConfidence();
- printf('Transcript: %s' . PHP_EOL, $transcript);
- printf('Confidence: %s' . PHP_EOL, $confidence);
+ $client->close();
}
-
-$client->close();
# [END speech_transcribe_model_selection]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/transcribe_sync.php b/speech/src/transcribe_sync.php
index 0e01cbbe00..82defef734 100644
--- a/speech/src/transcribe_sync.php
+++ b/speech/src/transcribe_sync.php
@@ -18,16 +18,10 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/speech/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return print("Usage: php transcribe_sync.php AUDIO_FILE\n");
-}
-list($_, $audioFile) = $argv;
+namespace Google\Cloud\Samples\Speech;
# [START speech_transcribe_sync]
use Google\Cloud\Speech\V1\SpeechClient;
@@ -35,41 +29,48 @@
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** Uncomment and populate these variables in your code */
-// $audioFile = 'path to an audio file';
-
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 32000;
-$languageCode = 'en-US';
+/**
+ * @param string $audioFile path to an audio file
+ */
+function transcribe_sync(string $audioFile)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 32000;
+ $languageCode = 'en-US';
-// get contents of a file into a string
-$content = file_get_contents($audioFile);
+ // get contents of a file into a string
+ $content = file_get_contents($audioFile);
-// set string as audio content
-$audio = (new RecognitionAudio())
- ->setContent($content);
+ // set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setContent($content);
-// set config
-$config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode);
+ // set config
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode);
-// create the speech client
-$client = new SpeechClient();
+ // create the speech client
+ $client = new SpeechClient();
-try {
- $response = $client->recognize($config, $audio);
- foreach ($response->getResults() as $result) {
- $alternatives = $result->getAlternatives();
- $mostLikely = $alternatives[0];
- $transcript = $mostLikely->getTranscript();
- $confidence = $mostLikely->getConfidence();
- printf('Transcript: %s' . PHP_EOL, $transcript);
- printf('Confidence: %s' . PHP_EOL, $confidence);
+ try {
+ $response = $client->recognize($config, $audio);
+ foreach ($response->getResults() as $result) {
+ $alternatives = $result->getAlternatives();
+ $mostLikely = $alternatives[0];
+ $transcript = $mostLikely->getTranscript();
+ $confidence = $mostLikely->getConfidence();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ printf('Confidence: %s' . PHP_EOL, $confidence);
+ }
+ } finally {
+ $client->close();
}
-} finally {
- $client->close();
}
# [END speech_transcribe_sync]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/src/transcribe_sync_gcs.php b/speech/src/transcribe_sync_gcs.php
index 809661913e..542f7c0e0f 100644
--- a/speech/src/transcribe_sync_gcs.php
+++ b/speech/src/transcribe_sync_gcs.php
@@ -18,16 +18,10 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/speech/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return print("Usage: php transcribe_sync_gcs.php URI\n");
-}
-list($_, $uri) = $argv;
+namespace Google\Cloud\Samples\Speech;
# [START speech_transcribe_sync_gcs]
use Google\Cloud\Speech\V1\SpeechClient;
@@ -35,38 +29,45 @@
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
-/** Uncomment and populate these variables in your code */
-// $uri = 'The Cloud Storage object to transcribe (gs://your-bucket-name/your-object-name)';
-
-// change these variables if necessary
-$encoding = AudioEncoding::LINEAR16;
-$sampleRateHertz = 32000;
-$languageCode = 'en-US';
+/**
+ * @param string $uri The Cloud Storage object to transcribe (gs://your-bucket-name/your-object-name)
+ */
+function transcribe_sync_gcs(string $uri)
+{
+ // change these variables if necessary
+ $encoding = AudioEncoding::LINEAR16;
+ $sampleRateHertz = 32000;
+ $languageCode = 'en-US';
-// set string as audio content
-$audio = (new RecognitionAudio())
- ->setUri($uri);
+ // set string as audio content
+ $audio = (new RecognitionAudio())
+ ->setUri($uri);
-// set config
-$config = (new RecognitionConfig())
- ->setEncoding($encoding)
- ->setSampleRateHertz($sampleRateHertz)
- ->setLanguageCode($languageCode);
+ // set config
+ $config = (new RecognitionConfig())
+ ->setEncoding($encoding)
+ ->setSampleRateHertz($sampleRateHertz)
+ ->setLanguageCode($languageCode);
-// create the speech client
-$client = new SpeechClient();
+ // create the speech client
+ $client = new SpeechClient();
-try {
- $response = $client->recognize($config, $audio);
- foreach ($response->getResults() as $result) {
- $alternatives = $result->getAlternatives();
- $mostLikely = $alternatives[0];
- $transcript = $mostLikely->getTranscript();
- $confidence = $mostLikely->getConfidence();
- printf('Transcript: %s' . PHP_EOL, $transcript);
- printf('Confidence: %s' . PHP_EOL, $confidence);
+ try {
+ $response = $client->recognize($config, $audio);
+ foreach ($response->getResults() as $result) {
+ $alternatives = $result->getAlternatives();
+ $mostLikely = $alternatives[0];
+ $transcript = $mostLikely->getTranscript();
+ $confidence = $mostLikely->getConfidence();
+ printf('Transcript: %s' . PHP_EOL, $transcript);
+ printf('Confidence: %s' . PHP_EOL, $confidence);
+ }
+ } finally {
+ $client->close();
}
-} finally {
- $client->close();
}
# [END speech_transcribe_sync_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/speech/test/speechTest.php b/speech/test/speechTest.php
index 62caf28ab7..d6f4fff16e 100644
--- a/speech/test/speechTest.php
+++ b/speech/test/speechTest.php
@@ -30,7 +30,7 @@ public function testBase64Audio()
{
$audioFile = __DIR__ . '/data/audio32KHz.raw';
- $output = $this->runSnippet('base64_encode_audio', [$audioFile]);
+ $output = $this->runFunctionSnippet('base64_encode_audio', [$audioFile]);
$audioFileResource = fopen($audioFile, 'r');
$this->assertEquals(
@@ -42,14 +42,14 @@ public function testBase64Audio()
public function testTranscribeEnhanced()
{
$path = __DIR__ . '/data/commercial_mono.wav';
- $output = $this->runSnippet('transcribe_enhanced_model', [$path]);
+ $output = $this->runFunctionSnippet('transcribe_enhanced_model', [$path]);
$this->assertStringContainsString('Chrome', $output);
}
public function testTranscribeModel()
{
$path = __DIR__ . '/data/audio32KHz.raw';
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'transcribe_model_selection',
[$path, 'video']
);
@@ -63,7 +63,7 @@ public function testTranscribeModel()
public function testTranscribePunctuation()
{
$path = __DIR__ . '/data/audio32KHz.raw';
- $output = $this->runSnippet('transcribe_auto_punctuation', [$path]);
+ $output = $this->runFunctionSnippet('transcribe_auto_punctuation', [$path]);
$this->assertStringContainsStringIgnoringCase(
'How old is the Brooklyn Bridge',
$output
@@ -79,12 +79,12 @@ public function testTranscribe($command, $audioFile, $requireGrpc = false)
if (!self::$bucketName && '_gcs' == substr($command, -4)) {
$this->requireEnv('GOOGLE_STORAGE_BUCKET');
}
- $output = $this->runSnippet($command, [$audioFile]);
+ $output = $this->runFunctionSnippet($command, [$audioFile]);
$this->assertStringContainsString('how old is the Brooklyn Bridge', $output);
// Check for the word time offsets
- if (in_array($command, ['transcribe_async-words'])) {
+ if (in_array($command, ['transcribe_async_words'])) {
$this->assertRegexp('/start: "*.*s", end: "*.*s/', $output);
}
}
@@ -99,7 +99,7 @@ public function provideTranscribe()
['transcribe_async_gcs', 'gs://' . self::$bucketName . '/speech/audio32KHz.raw'],
['transcribe_async_words', __DIR__ . '/data/audio32KHz.raw'],
['profanity_filter_gcs', 'gs://' . self::$bucketName . '/speech/audio32KHz.raw'],
- ['multi_region_gcs', 'gs://' . self::$bucketName . '/speech/audio32KHz.raw'],
+ ['multi_region_gcs', 'gs://cloud-samples-data/speech/brooklyn_bridge.raw' ],
['profanity_filter', __DIR__ . '/data/audio32KHz.raw'],
['streaming_recognize', __DIR__ . '/data/audio32KHz.raw', true],
];
diff --git a/storage/src/activate_hmac_key.php b/storage/src/activate_hmac_key.php
index bd283f99bf..59266732ea 100644
--- a/storage/src/activate_hmac_key.php
+++ b/storage/src/activate_hmac_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Activate an HMAC key.
*
* @param string $projectId The ID of your Google Cloud Platform project.
+ * (e.g. 'my-project-id')
* @param string $accessId Access ID for an inactive HMAC key.
+ * (e.g. 'GOOG0234230X00')
*/
-function activate_hmac_key($projectId, $accessId)
+function activate_hmac_key(string $projectId, string $accessId): void
{
- // $projectId = 'my-project-id';
- // $accessId = 'GOOG0234230X00';
-
$storage = new StorageClient();
// By default hmacKey will use the projectId used by StorageClient().
$hmacKey = $storage->hmacKey($accessId, $projectId);
diff --git a/storage/src/add_bucket_acl.php b/storage/src/add_bucket_acl.php
index 63555de5eb..99e7df90ab 100644
--- a/storage/src/add_bucket_acl.php
+++ b/storage/src/add_bucket_acl.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Add an entity and role to a bucket's ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $entity The entity for which to update access controls.
+ * (e.g. 'user-example@domain.com')
* @param string $role The permissions to add for the specified entity.
+ * (e.g. 'OWNER')
*/
-function add_bucket_acl($bucketName, $entity, $role)
+function add_bucket_acl(string $bucketName, string $entity, string $role): void
{
- // $bucketName = 'my-bucket';
- // $entity = 'user-example@domain.com';
- // $role = 'OWNER';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$acl = $bucket->acl();
diff --git a/storage/src/add_bucket_conditional_iam_binding.php b/storage/src/add_bucket_conditional_iam_binding.php
index 41097f6e1f..30429e6131 100644
--- a/storage/src/add_bucket_conditional_iam_binding.php
+++ b/storage/src/add_bucket_conditional_iam_binding.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,24 +30,22 @@
* Adds a conditional IAM binding to a bucket's IAM policy.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $role The role that will be given to members in this binding.
+ * (e.g. 'roles/storage.objectViewer')
* @param string[] $members The member(s) associated with this binding.
- * @param string $title The title of the condition.
+ * (e.g. ['group:example@google.com'])
+ * @param string $title The title of the condition. (e.g. 'Title')
* @param string $description The description of the condition.
+ * (e.g. 'Condition Description')
* @param string $expression The condition specified in CEL expression language.
+ * (e.g. 'resource.name.startsWith("projects/_/buckets/bucket-name/objects/prefix-a-")')
*
* To see how to express a condition in CEL, visit:
* @see https://cloud.google.com/storage/docs/access-control/iam#conditions.
*/
-function add_bucket_conditional_iam_binding($bucketName, $role, array $members, $title, $description, $expression)
+function add_bucket_conditional_iam_binding(string $bucketName, string $role, array $members, string $title, string $description, string $expression): void
{
- // $bucketName = 'my-bucket';
- // $role = 'roles/storage.objectViewer';
- // $members = ['group:example@google.com'];
- // $title = 'Title';
- // $description = 'Condition Description';
- // $expression = 'resource.name.startsWith("projects/_/buckets/bucket-name/objects/prefix-a-")';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/add_bucket_default_acl.php b/storage/src/add_bucket_default_acl.php
index 51730d9a9c..f06a0cb4e2 100644
--- a/storage/src/add_bucket_default_acl.php
+++ b/storage/src/add_bucket_default_acl.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Add an entity and role to a bucket's default ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $entity The entity for which to update access controls.
+ * (e.g. 'user-example@domain.com')
* @param string $role The permissions to add for the specified entity.
+ * (e.g. 'OWNER')
*/
-function add_bucket_default_acl($bucketName, $entity, $role)
+function add_bucket_default_acl(string $bucketName, string $entity, string $role): void
{
- // $bucketName = 'my-bucket';
- // $entity = 'user-example@domain.com';
- // $role = 'OWNER';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$acl = $bucket->defaultAcl();
diff --git a/storage/src/add_bucket_iam_member.php b/storage/src/add_bucket_iam_member.php
index 5bd1217882..f15349cf0e 100644
--- a/storage/src/add_bucket_iam_member.php
+++ b/storage/src/add_bucket_iam_member.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Adds a new member / role IAM pair to a given Cloud Storage bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $role The role to which the given member should be added.
+ * (e.g. 'roles/storage.objectViewer')
* @param string[] $members The member(s) to be added to the role.
+ * (e.g. ['group:example@google.com'])
*/
-function add_bucket_iam_member($bucketName, $role, array $members)
+function add_bucket_iam_member(string $bucketName, string $role, array $members): void
{
- // $bucketName = 'my-bucket';
- // $role = 'roles/storage.objectViewer';
- // $members = ['group:example@google.com'];
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/add_bucket_label.php b/storage/src/add_bucket_label.php
index 2e213df282..615d390980 100644
--- a/storage/src/add_bucket_label.php
+++ b/storage/src/add_bucket_label.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Adds or updates a bucket label.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $labelName The name of the label to add.
+ * (e.g. 'label-key-to-add')
* @param string $labelValue The value of the label to add.
+ * (e.g. 'label-value-to-add')
*/
-function add_bucket_label($bucketName, $labelName, $labelValue)
+function add_bucket_label(string $bucketName, string $labelName, string $labelValue): void
{
- // $bucketName = 'my-bucket';
- // $labelName = 'label-key-to-add';
- // $labelValue = 'label-value-to-add';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$newLabels = [$labelName => $labelValue];
diff --git a/storage/src/add_object_acl.php b/storage/src/add_object_acl.php
index e13275db1a..e2bb7e9355 100644
--- a/storage/src/add_object_acl.php
+++ b/storage/src/add_object_acl.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,17 +30,16 @@
* Add an entity and role to an object's ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $entity The entity for which to update access controls.
+ * (e.g. 'user-example@domain.com')
* @param string $role The permissions to add for the specified entity.
+ * (e.g. 'OWNER')
*/
-function add_object_acl($bucketName, $objectName, $entity, $role)
+function add_object_acl(string $bucketName, string $objectName, string $entity, string $role): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $entity = 'user-example@domain.com';
- // $role = 'OWNER';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/bucket_delete_default_kms_key.php b/storage/src/bucket_delete_default_kms_key.php
index 7c9a7203d0..5033f7cf8e 100644
--- a/storage/src/bucket_delete_default_kms_key.php
+++ b/storage/src/bucket_delete_default_kms_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Delete the default KMS key on the given bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function bucket_delete_default_kms_key($bucketName)
+function bucket_delete_default_kms_key(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/change_default_storage_class.php b/storage/src/change_default_storage_class.php
index 97f64cec1a..7a5c9b0b9b 100644
--- a/storage/src/change_default_storage_class.php
+++ b/storage/src/change_default_storage_class.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Change the default storage class for the given bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function change_default_storage_class($bucketName)
+function change_default_storage_class(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/change_file_storage_class.php b/storage/src/change_file_storage_class.php
index 6a62096757..05783df011 100644
--- a/storage/src/change_file_storage_class.php
+++ b/storage/src/change_file_storage_class.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Change the storage class of the given file.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $storageClass The storage class of the new object.
+ * (e.g. 'COLDLINE')
*/
-function change_file_storage_class($bucketName, $objectName, $storageClass)
+function change_file_storage_class(string $bucketName, string $objectName, string $storageClass): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $storageClass = 'COLDLINE';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/compose_file.php b/storage/src/compose_file.php
index 180cf4a46b..c355f2d584 100644
--- a/storage/src/compose_file.php
+++ b/storage/src/compose_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,17 +30,16 @@
* Compose two objects into a single target object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $firstObjectName The name of the first GCS object to compose.
+ * (e.g. 'my-object-1')
* @param string $secondObjectName The name of the second GCS object to compose.
+ * (e.g. 'my-object-2')
* @param string $targetObjectName The name of the object to be created.
+ * (e.g. 'composed-my-object-1-my-object-2')
*/
-function compose_file($bucketName, $firstObjectName, $secondObjectName, $targetObjectName)
+function compose_file(string $bucketName, string $firstObjectName, string $secondObjectName, string $targetObjectName): void
{
- // $bucketName = 'my-bucket';
- // $firstObjectName = 'my-object-1';
- // $secondObjectName = 'my-object-2';
- // $targetObjectName = 'composed-my-object-1-my-object-2';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/copy_file_archived_generation.php b/storage/src/copy_file_archived_generation.php
index 0551d0db4b..8cac77f420 100644
--- a/storage/src/copy_file_archived_generation.php
+++ b/storage/src/copy_file_archived_generation.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,17 +30,16 @@
* Copy archived generation of a given object to a new object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectToCopy The name of the object to copy.
+ * (e.g. 'my-object')
* @param string $generationToCopy The generation of the object to copy.
+ * (e.g. 1579287380533984)
* @param string $newObjectName The name of the target object.
+ * (e.g. 'my-object-1579287380533984')
*/
-function copy_file_archived_generation($bucketName, $objectToCopy, $generationToCopy, $newObjectName)
+function copy_file_archived_generation(string $bucketName, string $objectToCopy, string $generationToCopy, string $newObjectName): void
{
- // $bucketName = 'my-bucket';
- // $objectToCopy = 'my-object';
- // $generationToCopy = 1579287380533984;
- // $newObjectName = 'my-object-1579287380533984';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/copy_object.php b/storage/src/copy_object.php
index eb58a44a9d..d4baf7e852 100644
--- a/storage/src/copy_object.php
+++ b/storage/src/copy_object.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,17 +30,16 @@
* Copy an object to a new name and/or bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $newBucketName The destination bucket name.
+ * (e.g. 'my-other-bucket')
* @param string $newObjectName The destination object name.
+ * (e.g. 'my-other-object')
*/
-function copy_object($bucketName, $objectName, $newBucketName, $newObjectName)
+function copy_object(string $bucketName, string $objectName, string $newBucketName, string $newObjectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $newBucketName = 'my-other-bucket';
- // $newObjectName = 'my-other-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/cors_configuration.php b/storage/src/cors_configuration.php
index 6c66754051..008c90d99e 100644
--- a/storage/src/cors_configuration.php
+++ b/storage/src/cors_configuration.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,20 +30,18 @@
* Update the CORS configuration of a bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
- * @param string $method The HTTP method for the CORS config.
+ * (e.g. 'my-bucket')
+ * @param string $method The HTTP method for the CORS config. (e.g. 'GET')
* @param string $origin The origin from which the CORS config will allow requests.
+ * (e.g. 'http://example.appspot.com/')
* @param string $responseHeader The response header to share across origins.
+ * (e.g. 'Content-Type')
* @param int $maxAgeSeconds The maximum amount of time the browser can make
+ * (e.g. 3600)
* requests before it must repeat preflighted requests.
*/
-function cors_configuration($bucketName, $method, $origin, $responseHeader, $maxAgeSeconds)
+function cors_configuration(string $bucketName, string $method, string $origin, string $responseHeader, int $maxAgeSeconds): void
{
- // $bucketName = 'my-bucket';
- // $method = 'GET';
- // $origin = 'http://example.appspot.com/';
- // $responseHeader = 'Content-Type';
- // $maxAgeSeconds = 3600;
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/create_bucket.php b/storage/src/create_bucket.php
index 234162b3c3..f67bb2fca8 100644
--- a/storage/src/create_bucket.php
+++ b/storage/src/create_bucket.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Create a Cloud Storage Bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function create_bucket($bucketName)
+function create_bucket(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->createBucket($bucketName);
diff --git a/storage/src/create_bucket_class_location.php b/storage/src/create_bucket_class_location.php
index 46eebfe9f4..e7c501ad42 100644
--- a/storage/src/create_bucket_class_location.php
+++ b/storage/src/create_bucket_class_location.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Create a new bucket with a custom default storage class and location.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function create_bucket_class_location($bucketName)
+function create_bucket_class_location(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$storageClass = 'COLDLINE';
$location = 'ASIA';
diff --git a/storage/src/create_bucket_dual_region.php b/storage/src/create_bucket_dual_region.php
index e516c6c597..ceb270cdb1 100644
--- a/storage/src/create_bucket_dual_region.php
+++ b/storage/src/create_bucket_dual_region.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,17 +30,16 @@
* Create a new bucket with a custom default storage class and location.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $location Location for the bucket's regions. Case-insensitive.
+ * (e.g. 'US')
* @param string $region1 First region for the bucket's regions. Case-insensitive.
+ * (e.g. 'US-EAST1')
* @param string $region2 Second region for the bucket's regions. Case-insensitive.
+ * (e.g. 'US-WEST1')
*/
-function create_bucket_dual_region($bucketName, $location, $region1, $region2)
+function create_bucket_dual_region(string $bucketName, string $location, string $region1, string $region2): void
{
- // $bucketName = 'my-bucket';
- // $location = 'US';
- // $region1 = 'US-EAST1';
- // $region2 = 'US-WEST1';
-
$storage = new StorageClient();
$bucket = $storage->createBucket($bucketName, [
'location' => $location,
diff --git a/storage/src/create_bucket_notifications.php b/storage/src/create_bucket_notifications.php
index 1e8fa81df6..fb24fb688b 100644
--- a/storage/src/create_bucket_notifications.php
+++ b/storage/src/create_bucket_notifications.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -32,15 +32,14 @@
* https://cloud.google.com/storage/docs/reporting-changes
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $topicName The name of the topic you would like to create a notification.
+ * (e.g. 'my-topic')
*/
function create_bucket_notifications(
string $bucketName,
string $topicName
): void {
- // $bucketName = 'my-bucket';
- // $topicName = 'my-topic';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$notification = $bucket->createNotification($topicName);
diff --git a/storage/src/create_bucket_turbo_replication.php b/storage/src/create_bucket_turbo_replication.php
index 57744cd810..21e4a855cd 100644
--- a/storage/src/create_bucket_turbo_replication.php
+++ b/storage/src/create_bucket_turbo_replication.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -31,13 +31,12 @@
* The bucket must be a dual-region bucket for this setting to take effect.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $location The Dual-Region location where you want your bucket to reside (e.g. "US-CENTRAL1+US-WEST1").
Read more at https://cloud.google.com/storage/docs/locations#location-dr
*/
-function create_bucket_turbo_replication($bucketName, $location = 'nam4')
+function create_bucket_turbo_replication(string $bucketName, string $location = 'nam4'): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$rpo = 'ASYNC_TURBO';
diff --git a/storage/src/create_hmac_key.php b/storage/src/create_hmac_key.php
index 15c7b406dd..fe0e9d428d 100644
--- a/storage/src/create_hmac_key.php
+++ b/storage/src/create_hmac_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Create a new HMAC key.
*
* @param string $projectId The ID of your Google Cloud Platform project.
+ * (e.g. 'my-project-id')
* @param string $serviceAccountEmail Service account email to associate with the new HMAC key.
+ * (e.g. 'service-account@iam.gserviceaccount.com')
*/
-function create_hmac_key($projectId, $serviceAccountEmail)
+function create_hmac_key(string $projectId, string $serviceAccountEmail): void
{
- // $projectId = 'my-project-id';
- // $serviceAccountEmail = 'service-account@iam.gserviceaccount.com';
-
$storage = new StorageClient();
// By default createHmacKey will use the projectId used by StorageClient().
$hmacKeyCreated = $storage->createHmacKey($serviceAccountEmail, ['projectId' => $projectId]);
diff --git a/storage/src/deactivate_hmac_key.php b/storage/src/deactivate_hmac_key.php
index 1c875216b3..9970372c80 100644
--- a/storage/src/deactivate_hmac_key.php
+++ b/storage/src/deactivate_hmac_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Deactivate an HMAC key.
*
* @param string $projectId The ID of your Google Cloud Platform project.
+ * (e.g. 'my-project-id')
* @param string $accessId Access ID for an inactive HMAC key.
+ * (e.g. 'GOOG0234230X00')
*/
-function deactivate_hmac_key($projectId, $accessId)
+function deactivate_hmac_key(string $projectId, string $accessId): void
{
- // $projectId = 'my-project-id';
- // $accessId = 'GOOG0234230X00';
-
$storage = new StorageClient();
// By default hmacKey will use the projectId used by StorageClient().
$hmacKey = $storage->hmacKey($accessId, $projectId);
diff --git a/storage/src/define_bucket_website_configuration.php b/storage/src/define_bucket_website_configuration.php
index 95a399af70..781fa96966 100644
--- a/storage/src/define_bucket_website_configuration.php
+++ b/storage/src/define_bucket_website_configuration.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,17 +30,16 @@
* Update the given bucket's website configuration.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $indexPageObject the name of an object in the bucket to use as
+ * (e.g. 'index.html')
* an index page for a static website bucket.
* @param string $notFoundPageObject the name of an object in the bucket to use
+ * (e.g. '404.html')
* as the 404 Not Found page.
*/
-function define_bucket_website_configuration($bucketName, $indexPageObject, $notFoundPageObject)
+function define_bucket_website_configuration(string $bucketName, string $indexPageObject, string $notFoundPageObject): void
{
- // $bucketName = 'my-bucket';
- // $indexPageObject = 'index.html';
- // $notFoundPageObject = '404.html';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/delete_bucket.php b/storage/src/delete_bucket.php
index c54a84e8db..2c87436215 100644
--- a/storage/src/delete_bucket.php
+++ b/storage/src/delete_bucket.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Delete a Cloud Storage Bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function delete_bucket($bucketName)
+function delete_bucket(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->delete();
diff --git a/storage/src/delete_bucket_acl.php b/storage/src/delete_bucket_acl.php
index cffe59ebfa..9372cf8968 100644
--- a/storage/src/delete_bucket_acl.php
+++ b/storage/src/delete_bucket_acl.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Delete an entity from a bucket's default ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $entity The entity for which to update access controls.
+ * (e.g. 'user-example@domain.com')
*/
-function delete_bucket_acl($bucketName, $entity)
+function delete_bucket_acl(string $bucketName, string $entity): void
{
- // $bucketName = 'my-bucket';
- // $entity = 'user-example@domain.com';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$acl = $bucket->acl();
diff --git a/storage/src/delete_bucket_default_acl.php b/storage/src/delete_bucket_default_acl.php
index 223e49dc44..23728d7b82 100644
--- a/storage/src/delete_bucket_default_acl.php
+++ b/storage/src/delete_bucket_default_acl.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Delete an entity from a bucket's default ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $entity The entity for which to update access controls.
+ * (e.g. 'user-example@domain.com')
*/
-function delete_bucket_default_acl($bucketName, $entity)
+function delete_bucket_default_acl(string $bucketName, string $entity): void
{
- // $bucketName = 'my-bucket';
- // $entity = 'user-example@domain.com';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$acl = $bucket->defaultAcl();
diff --git a/storage/src/delete_bucket_notifications.php b/storage/src/delete_bucket_notifications.php
index 0ee7373c30..e3a86d60c1 100644
--- a/storage/src/delete_bucket_notifications.php
+++ b/storage/src/delete_bucket_notifications.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -32,15 +32,14 @@
* https://cloud.google.com/storage/docs/reporting-changes
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'your-bucket')
* @param string $notificationId The ID of the notification.
+ * (e.g. 'your-notification-id')
*/
function delete_bucket_notifications(
string $bucketName,
string $notificationId
): void {
- // $bucketName = 'your-bucket';
- // $notificationId = 'your-notification-id';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$notification = $bucket->notification($notificationId);
diff --git a/storage/src/delete_file_archived_generation.php b/storage/src/delete_file_archived_generation.php
index 3460de08e6..6fff5a4bcd 100644
--- a/storage/src/delete_file_archived_generation.php
+++ b/storage/src/delete_file_archived_generation.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Delete an archived generation of the given object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $generationToDelete the generation of the object to delete.
+ * (e.g. 1579287380533984)
*/
-function delete_file_archived_generation($bucketName, $objectName, $generationToDelete)
+function delete_file_archived_generation(string $bucketName, string $objectName, string $generationToDelete): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $generationToDelete = 1579287380533984;
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/delete_hmac_key.php b/storage/src/delete_hmac_key.php
index 4a79868672..c9deea3935 100644
--- a/storage/src/delete_hmac_key.php
+++ b/storage/src/delete_hmac_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,11 @@
* Delete an HMAC key.
*
* @param string $projectId The ID of your Google Cloud Platform project.
- * @param string $accessId Access ID for an HMAC key.
+ * (e.g. 'my-project-id')
+ * @param string $accessId Access ID for an HMAC key. (e.g. 'GOOG0234230X00')
*/
-function delete_hmac_key($projectId, $accessId)
+function delete_hmac_key(string $projectId, string $accessId): void
{
- // $projectId = 'my-project-id';
- // $accessId = 'GOOG0234230X00';
-
$storage = new StorageClient();
// By default hmacKey will use the projectId used by StorageClient().
$hmacKey = $storage->hmacKey($accessId, $projectId);
diff --git a/storage/src/delete_object.php b/storage/src/delete_object.php
index fb277a0517..5107d394a8 100644
--- a/storage/src/delete_object.php
+++ b/storage/src/delete_object.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Delete an object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function delete_object($bucketName, $objectName)
+function delete_object(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/delete_object_acl.php b/storage/src/delete_object_acl.php
index 3c13a15ac0..baa91f9a96 100644
--- a/storage/src/delete_object_acl.php
+++ b/storage/src/delete_object_acl.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Delete an entity from an object's ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $entity The entity for which to update access controls.
+ * (e.g. 'user-example@domain.com')
*/
-function delete_object_acl($bucketName, $objectName, $entity)
+function delete_object_acl(string $bucketName, string $objectName, string $entity): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $entity = 'user-example@domain.com';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/disable_bucket_lifecycle_management.php b/storage/src/disable_bucket_lifecycle_management.php
index 2711aba819..8e921c46cd 100644
--- a/storage/src/disable_bucket_lifecycle_management.php
+++ b/storage/src/disable_bucket_lifecycle_management.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Disable bucket lifecycle management.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function disable_bucket_lifecycle_management($bucketName)
+function disable_bucket_lifecycle_management(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/disable_default_event_based_hold.php b/storage/src/disable_default_event_based_hold.php
index 989e30b63f..d0d91268f7 100644
--- a/storage/src/disable_default_event_based_hold.php
+++ b/storage/src/disable_default_event_based_hold.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Disables a default event-based hold for a bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function disable_default_event_based_hold($bucketName)
+function disable_default_event_based_hold(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->update(['defaultEventBasedHold' => false]);
diff --git a/storage/src/disable_requester_pays.php b/storage/src/disable_requester_pays.php
index a7938b3259..9ba62b1a8b 100644
--- a/storage/src/disable_requester_pays.php
+++ b/storage/src/disable_requester_pays.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Disable a bucket's requesterpays metadata.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function disable_requester_pays($bucketName)
+function disable_requester_pays(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->update([
diff --git a/storage/src/disable_uniform_bucket_level_access.php b/storage/src/disable_uniform_bucket_level_access.php
index d7b497f608..a3534ff676 100644
--- a/storage/src/disable_uniform_bucket_level_access.php
+++ b/storage/src/disable_uniform_bucket_level_access.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Enable uniform bucket-level access.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function disable_uniform_bucket_level_access($bucketName)
+function disable_uniform_bucket_level_access(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->update([
diff --git a/storage/src/disable_versioning.php b/storage/src/disable_versioning.php
index 66c0f175cc..9c24ed4c2f 100644
--- a/storage/src/disable_versioning.php
+++ b/storage/src/disable_versioning.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Disable versioning of the given bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function disable_versioning($bucketName)
+function disable_versioning(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->update([
diff --git a/storage/src/download_byte_range.php b/storage/src/download_byte_range.php
index 8a679b781f..bfde167228 100644
--- a/storage/src/download_byte_range.php
+++ b/storage/src/download_byte_range.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,10 +30,14 @@
* Download a byte range from Cloud Storage and save it as a local file.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param int $startByte The starting byte at which to begin the download.
- * @param int $endByte The ending byte at which to end the download.
+ * (e.g. 1)
+ * @param int $endByte The ending byte at which to end the download. (e.g. 5)
* @param string $destination The local destination to save the object.
+ * (e.g. '/path/to/your/file')
*/
function download_byte_range(
string $bucketName,
@@ -42,12 +46,6 @@ function download_byte_range(
int $endByte,
string $destination
): void {
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $startByte = 1;
- // $endByte = 5;
- // $destination = '/path/to/your/file';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/download_encrypted_object.php b/storage/src/download_encrypted_object.php
index a77b628c93..56f8056024 100644
--- a/storage/src/download_encrypted_object.php
+++ b/storage/src/download_encrypted_object.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,18 +30,17 @@
* Download an encrypted file
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $destination The local destination to save the encrypted file.
+ * (e.g. '/path/to/your/file')
* @param string $base64EncryptionKey The base64 encoded encryption key. Should
+ * (e.g. 'TIbv/fjexq+VmtXzAlc63J4z5kFmWJ6NdAPQulQBT7g=')
* be the same key originally used to encrypt the object.
*/
-function download_encrypted_object($bucketName, $objectName, $destination, $base64EncryptionKey)
+function download_encrypted_object(string $bucketName, string $objectName, string $destination, string $base64EncryptionKey): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $destination = '/path/to/your/file';
- // $base64EncryptionKey = 'TIbv/fjexq+VmtXzAlc63J4z5kFmWJ6NdAPQulQBT7g=';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/download_file_requester_pays.php b/storage/src/download_file_requester_pays.php
index 670b7da18a..e55c93f11e 100644
--- a/storage/src/download_file_requester_pays.php
+++ b/storage/src/download_file_requester_pays.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,17 +30,16 @@
* Download file using specified project as requester
*
* @param string $projectId The ID of your Google Cloud Platform project.
+ * (e.g. 'my-project-id')
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $destination The local destination to save the object.
+ * (e.g. '/path/to/your/file')
*/
-function download_file_requester_pays($projectId, $bucketName, $objectName, $destination)
+function download_file_requester_pays(string $projectId, string $bucketName, string $objectName, string $destination): void
{
- // $projectId = 'my-project-id';
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $destination = '/path/to/your/file';
-
$storage = new StorageClient([
'projectId' => $projectId
]);
diff --git a/storage/src/download_object.php b/storage/src/download_object.php
index 0d7f4b43a8..35d6dd56f8 100644
--- a/storage/src/download_object.php
+++ b/storage/src/download_object.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -31,15 +31,14 @@
* Download an object from Cloud Storage and save it as a local file.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $destination The local destination to save the object.
+ * (e.g. '/path/to/your/file')
*/
-function download_object($bucketName, $objectName, $destination)
+function download_object(string $bucketName, string $objectName, string $destination): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $destination = '/path/to/your/file';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/download_object_into_memory.php b/storage/src/download_object_into_memory.php
index 87b46d1b7b..2d2692f873 100644
--- a/storage/src/download_object_into_memory.php
+++ b/storage/src/download_object_into_memory.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Download an object from Cloud Storage and save into a buffer in memory.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
function download_object_into_memory(
string $bucketName,
string $objectName
): void {
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/download_public_file.php b/storage/src/download_public_file.php
index 543b219ea6..f6492ba7bd 100644
--- a/storage/src/download_public_file.php
+++ b/storage/src/download_public_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Download a public file using anonymous credentials.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $destination The local destination to save the object.
+ * (e.g. '/home/admin/downloads/my-object')
*/
-function download_public_file($bucketName, $objectName, $destination)
+function download_public_file(string $bucketName, string $objectName, string $destination): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $destination = '/home/admin/downloads/my-object';
-
// create a storage client without authentication
$storage = new StorageClient([
]);
diff --git a/storage/src/enable_bucket_lifecycle_management.php b/storage/src/enable_bucket_lifecycle_management.php
index f5d1f26055..c8f191f3f0 100644
--- a/storage/src/enable_bucket_lifecycle_management.php
+++ b/storage/src/enable_bucket_lifecycle_management.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -31,11 +31,10 @@
* Enable bucket lifecycle management.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function enable_bucket_lifecycle_management($bucketName)
+function enable_bucket_lifecycle_management(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/enable_default_event_based_hold.php b/storage/src/enable_default_event_based_hold.php
index 2d4a8d70b9..b35eb65f23 100644
--- a/storage/src/enable_default_event_based_hold.php
+++ b/storage/src/enable_default_event_based_hold.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Enables a default event-based hold for a bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function enable_default_event_based_hold($bucketName)
+function enable_default_event_based_hold(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->update(['defaultEventBasedHold' => true]);
diff --git a/storage/src/enable_default_kms_key.php b/storage/src/enable_default_kms_key.php
index cff7f7ff05..6af686ab39 100644
--- a/storage/src/enable_default_kms_key.php
+++ b/storage/src/enable_default_kms_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,13 @@
* Enable a bucket's requesterpays metadata.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $kmsKeyName The KMS key to use as the default KMS key.
* Key names are provided in the following format:
* `projects//locations//keyRings//cryptoKeys/`.
*/
-function enable_default_kms_key($bucketName, $kmsKeyName)
+function enable_default_kms_key(string $bucketName, string $kmsKeyName): void
{
- // $bucketName = 'my-bucket';
- // $kmsKeyName = "";
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->update([
diff --git a/storage/src/enable_requester_pays.php b/storage/src/enable_requester_pays.php
index 086d83154a..59c0b1c433 100644
--- a/storage/src/enable_requester_pays.php
+++ b/storage/src/enable_requester_pays.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Enable a bucket's requesterpays metadata.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function enable_requester_pays($bucketName)
+function enable_requester_pays(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->update([
diff --git a/storage/src/enable_uniform_bucket_level_access.php b/storage/src/enable_uniform_bucket_level_access.php
index 95a6e9ca62..3989b3f29f 100644
--- a/storage/src/enable_uniform_bucket_level_access.php
+++ b/storage/src/enable_uniform_bucket_level_access.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Enable uniform bucket-level access.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function enable_uniform_bucket_level_access($bucketName)
+function enable_uniform_bucket_level_access(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->update([
diff --git a/storage/src/enable_versioning.php b/storage/src/enable_versioning.php
index de64a7afc3..dfee2b4d0b 100644
--- a/storage/src/enable_versioning.php
+++ b/storage/src/enable_versioning.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Enable versioning on the specified bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function enable_versioning($bucketName)
+function enable_versioning(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->update([
diff --git a/storage/src/generate_encryption_key.php b/storage/src/generate_encryption_key.php
index 61dea81f07..7463d39c1f 100644
--- a/storage/src/generate_encryption_key.php
+++ b/storage/src/generate_encryption_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -28,7 +28,7 @@
/**
* Generate a base64 encoded encryption key for Google Cloud Storage.
*/
-function generate_encryption_key()
+function generate_encryption_key(): void
{
$key = random_bytes(32);
$encodedKey = base64_encode($key);
diff --git a/storage/src/generate_signed_post_policy_v4.php b/storage/src/generate_signed_post_policy_v4.php
index a59bd3e5b5..aa4bca84fa 100644
--- a/storage/src/generate_signed_post_policy_v4.php
+++ b/storage/src/generate_signed_post_policy_v4.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Generates a v4 POST Policy to be used in an HTML form and echo's form.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function generate_signed_post_policy_v4($bucketName, $objectName)
+function generate_signed_post_policy_v4(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/generate_v4_post_policy.php b/storage/src/generate_v4_post_policy.php
index ea85e732cd..cc34e0160f 100644
--- a/storage/src/generate_v4_post_policy.php
+++ b/storage/src/generate_v4_post_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Generates a v4 POST Policy to be used in an HTML form and echo's form.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function generate_v4_post_policy($bucketName, $objectName)
+function generate_v4_post_policy(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/get_bucket_acl.php b/storage/src/get_bucket_acl.php
index 9ce11e2bdb..fe97e1246e 100644
--- a/storage/src/get_bucket_acl.php
+++ b/storage/src/get_bucket_acl.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Print all entities and roles for a bucket's ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function get_bucket_acl($bucketName)
+function get_bucket_acl(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$acl = $bucket->acl();
diff --git a/storage/src/get_bucket_acl_for_entity.php b/storage/src/get_bucket_acl_for_entity.php
index 346fb216ec..a6f6295065 100644
--- a/storage/src/get_bucket_acl_for_entity.php
+++ b/storage/src/get_bucket_acl_for_entity.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Print an entity's role for a bucket's ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $entity The entity for which to update access controls.
+ * (e.g. 'user-example@domain.com')
*/
-function get_bucket_acl_for_entity($bucketName, $entity)
+function get_bucket_acl_for_entity(string $bucketName, string $entity): void
{
- // $bucketName = 'my-bucket';
- // $entity = 'user-example@domain.com';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$acl = $bucket->acl();
diff --git a/storage/src/get_bucket_autoclass.php b/storage/src/get_bucket_autoclass.php
new file mode 100644
index 0000000000..277653d537
--- /dev/null
+++ b/storage/src/get_bucket_autoclass.php
@@ -0,0 +1,56 @@
+bucket($bucketName);
+
+ $info = $bucket->info();
+
+ if (isset($info['autoclass'])) {
+ printf('Bucket %s has autoclass enabled: %s' . PHP_EOL,
+ $bucketName,
+ $info['autoclass']['enabled']
+ );
+ printf('Bucket %s has autoclass toggle time: %s' . PHP_EOL,
+ $bucketName,
+ $info['autoclass']['toggleTime']
+ );
+ }
+}
+# [END storage_get_autoclass]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/storage/src/get_bucket_class_and_location.php b/storage/src/get_bucket_class_and_location.php
new file mode 100644
index 0000000000..f4d88572d9
--- /dev/null
+++ b/storage/src/get_bucket_class_and_location.php
@@ -0,0 +1,51 @@
+bucket($bucketName);
+
+ $info = $bucket->info();
+ printf(
+ 'Bucket: %s, storage class: %s, location: %s' . PHP_EOL,
+ $info['name'],
+ $info['storageClass'],
+ $info['location'],
+ );
+}
+# [END storage_get_bucket_class_and_location]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/storage/src/get_bucket_default_acl.php b/storage/src/get_bucket_default_acl.php
index 01ef1ed1b6..6165ef4ab2 100644
--- a/storage/src/get_bucket_default_acl.php
+++ b/storage/src/get_bucket_default_acl.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Print all entities and roles for a bucket's default ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function get_bucket_default_acl($bucketName)
+function get_bucket_default_acl(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$acl = $bucket->defaultAcl();
diff --git a/storage/src/get_bucket_default_acl_for_entity.php b/storage/src/get_bucket_default_acl_for_entity.php
index caa6aecf0e..8a4dc4e149 100644
--- a/storage/src/get_bucket_default_acl_for_entity.php
+++ b/storage/src/get_bucket_default_acl_for_entity.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Print an entity's role for a bucket's default ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $entity The entity for which to update access controls.
+ * (e.g. 'user-example@domain.com')
*/
-function get_bucket_default_acl_for_entity($bucketName, $entity)
+function get_bucket_default_acl_for_entity(string $bucketName, string $entity): void
{
- // $bucketName = 'my-bucket';
- // $entity = 'user-example@domain.com';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$acl = $bucket->defaultAcl();
diff --git a/storage/src/get_bucket_labels.php b/storage/src/get_bucket_labels.php
index 0592525dab..9a51b485c2 100644
--- a/storage/src/get_bucket_labels.php
+++ b/storage/src/get_bucket_labels.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Prints a list of a bucket's lables.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function get_bucket_labels($bucketName)
+function get_bucket_labels(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$info = $bucket->info();
diff --git a/storage/src/get_bucket_metadata.php b/storage/src/get_bucket_metadata.php
index 0d8d3daba7..e6e1aeb0c4 100644
--- a/storage/src/get_bucket_metadata.php
+++ b/storage/src/get_bucket_metadata.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Get bucket metadata.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function get_bucket_metadata($bucketName)
+function get_bucket_metadata(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$info = $bucket->info();
diff --git a/storage/src/get_default_event_based_hold.php b/storage/src/get_default_event_based_hold.php
index 4b41a06192..d9969ed8a0 100644
--- a/storage/src/get_default_event_based_hold.php
+++ b/storage/src/get_default_event_based_hold.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Enables a default event-based hold for a bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function get_default_event_based_hold($bucketName)
+function get_default_event_based_hold(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/get_hmac_key.php b/storage/src/get_hmac_key.php
index ffa6e40bd9..74d858f8eb 100644
--- a/storage/src/get_hmac_key.php
+++ b/storage/src/get_hmac_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,11 @@
* Get an HMAC key.
*
* @param string $projectId The ID of your Google Cloud Platform project.
- * @param string $accessId Access ID for an HMAC key.
+ * (e.g. 'my-project-id')
+ * @param string $accessId Access ID for an HMAC key. (e.g. 'GOOG0234230X00')
*/
-function get_hmac_key($projectId, $accessId)
+function get_hmac_key(string $projectId, string $accessId): void
{
- // $projectId = 'my-project-id';
- // $accessId = 'GOOG0234230X00';
-
$storage = new StorageClient();
$hmacKey = $storage->hmacKey($accessId, $projectId);
diff --git a/storage/src/get_object_acl.php b/storage/src/get_object_acl.php
index f03477b711..76faabe423 100644
--- a/storage/src/get_object_acl.php
+++ b/storage/src/get_object_acl.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Print all entities and roles for an object's ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function get_object_acl($bucketName, $objectName)
+function get_object_acl(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/get_object_acl_for_entity.php b/storage/src/get_object_acl_for_entity.php
index c198ac4502..007062ea3e 100644
--- a/storage/src/get_object_acl_for_entity.php
+++ b/storage/src/get_object_acl_for_entity.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Print an entity's role for an object's ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $entity The entity for which to update access controls.
+ * (e.g. 'user-example@domain.com')
*/
-function get_object_acl_for_entity($bucketName, $objectName, $entity)
+function get_object_acl_for_entity(string $bucketName, string $objectName, string $entity): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $entity = 'user-example@domain.com';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/get_object_v2_signed_url.php b/storage/src/get_object_v2_signed_url.php
index e96cb75654..33ba2ce7ff 100644
--- a/storage/src/get_object_v2_signed_url.php
+++ b/storage/src/get_object_v2_signed_url.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Generate a v2 signed URL for downloading an object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function get_object_v2_signed_url(http://github.com/$bucketName,%20$objectName)
+function get_object_v2_signed_url(http://github.com/string%20$bucketName,%20string%20$objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/get_object_v4_signed_url.php b/storage/src/get_object_v4_signed_url.php
index 70e9a44fd9..1bfbde8593 100644
--- a/storage/src/get_object_v4_signed_url.php
+++ b/storage/src/get_object_v4_signed_url.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Generate a v4 signed URL for downloading an object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function get_object_v4_signed_url(http://github.com/$bucketName,%20$objectName)
+function get_object_v4_signed_url(http://github.com/string%20$bucketName,%20string%20$objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/get_public_access_prevention.php b/storage/src/get_public_access_prevention.php
index 0b56935bdd..2d67e96a09 100644
--- a/storage/src/get_public_access_prevention.php
+++ b/storage/src/get_public_access_prevention.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Get the Public Access Prevention setting for a bucket
*
* @param string $bucketName the name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function get_public_access_prevention($bucketName)
+function get_public_access_prevention(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/get_requester_pays_status.php b/storage/src/get_requester_pays_status.php
index 4613a8cbaf..8cf97b2c44 100644
--- a/storage/src/get_requester_pays_status.php
+++ b/storage/src/get_requester_pays_status.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Get a bucket's requesterpays metadata.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function get_requester_pays_status($bucketName)
+function get_requester_pays_status(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucketInformation = $bucket->info();
diff --git a/storage/src/get_retention_policy.php b/storage/src/get_retention_policy.php
index e03a3dda0e..c8345bbc55 100644
--- a/storage/src/get_retention_policy.php
+++ b/storage/src/get_retention_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Gets a bucket's retention policy.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function get_retention_policy($bucketName)
+function get_retention_policy(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->reload();
diff --git a/storage/src/get_rpo.php b/storage/src/get_rpo.php
index 7fc5f7164f..8d46795d26 100644
--- a/storage/src/get_rpo.php
+++ b/storage/src/get_rpo.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Get the bucket's recovery point objective (RPO) setting.
*
* @param string $bucketName the name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function get_rpo($bucketName)
+function get_rpo(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/get_service_account.php b/storage/src/get_service_account.php
index 9b3f00969d..71bf8f26fd 100644
--- a/storage/src/get_service_account.php
+++ b/storage/src/get_service_account.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Get the current service account email.
*
* @param string $projectId The ID of your Google Cloud Platform project.
+ * (e.g. 'my-project-id')
*/
-function get_service_account($projectId)
+function get_service_account(string $projectId): void
{
- // $projectId = 'my-project-id';
-
$storage = new StorageClient([
'projectId' => $projectId,
]);
diff --git a/storage/src/get_uniform_bucket_level_access.php b/storage/src/get_uniform_bucket_level_access.php
index 474f40abea..0d169906ae 100644
--- a/storage/src/get_uniform_bucket_level_access.php
+++ b/storage/src/get_uniform_bucket_level_access.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Enable uniform bucket-level access.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function get_uniform_bucket_level_access($bucketName)
+function get_uniform_bucket_level_access(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucketInformation = $bucket->info();
diff --git a/storage/src/list_bucket_notifications.php b/storage/src/list_bucket_notifications.php
index 9657b94e16..b16d0fd680 100644
--- a/storage/src/list_bucket_notifications.php
+++ b/storage/src/list_bucket_notifications.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -32,12 +32,11 @@
* https://cloud.google.com/storage/docs/reporting-changes
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'your-bucket')
*/
function list_bucket_notifications(
string $bucketName
): void {
- // $bucketName = 'your-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$notifications = $bucket->notifications();
diff --git a/storage/src/list_buckets.php b/storage/src/list_buckets.php
index 9f6bb7c74c..38ccbc0877 100644
--- a/storage/src/list_buckets.php
+++ b/storage/src/list_buckets.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -29,7 +29,7 @@
/**
* List all Cloud Storage buckets for the current project.
*/
-function list_buckets()
+function list_buckets(): void
{
$storage = new StorageClient();
foreach ($storage->buckets() as $bucket) {
diff --git a/storage/src/list_file_archived_generations.php b/storage/src/list_file_archived_generations.php
index 19de55cf17..4e531f1b05 100644
--- a/storage/src/list_file_archived_generations.php
+++ b/storage/src/list_file_archived_generations.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* List objects in a specified bucket with all archived generations.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function list_file_archived_generations($bucketName)
+function list_file_archived_generations(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/list_hmac_keys.php b/storage/src/list_hmac_keys.php
index b6d0aa71df..aea3660bc8 100644
--- a/storage/src/list_hmac_keys.php
+++ b/storage/src/list_hmac_keys.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* List HMAC keys.
*
* @param string $projectId The ID of your Google Cloud Platform project.
+ * (e.g. 'my-project-id')
*/
-function list_hmac_keys($projectId)
+function list_hmac_keys(string $projectId): void
{
- // $projectId = 'my-project-id';
-
$storage = new StorageClient();
// By default hmacKeys will use the projectId used by StorageClient() to list HMAC Keys.
$hmacKeys = $storage->hmacKeys(['projectId' => $projectId]);
diff --git a/storage/src/list_objects.php b/storage/src/list_objects.php
index 8eb1a2a5ed..2b20b9dbd3 100644
--- a/storage/src/list_objects.php
+++ b/storage/src/list_objects.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* List Cloud Storage bucket objects.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function list_objects($bucketName)
+function list_objects(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
foreach ($bucket->objects() as $object) {
diff --git a/storage/src/list_objects_with_prefix.php b/storage/src/list_objects_with_prefix.php
index 6c2d0a432e..8a7f6489cd 100644
--- a/storage/src/list_objects_with_prefix.php
+++ b/storage/src/list_objects_with_prefix.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* List Cloud Storage bucket objects with specified prefix.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $directoryPrefix the prefix to use in the list objects API call.
+ * (e.g. 'myDirectory/')
*/
-function list_objects_with_prefix($bucketName, $directoryPrefix)
+function list_objects_with_prefix(string $bucketName, string $directoryPrefix): void
{
- // $bucketName = 'my-bucket';
- // $directoryPrefix = 'myDirectory/';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$options = ['prefix' => $directoryPrefix];
diff --git a/storage/src/lock_retention_policy.php b/storage/src/lock_retention_policy.php
index 32f6d19afc..265486f5b9 100644
--- a/storage/src/lock_retention_policy.php
+++ b/storage/src/lock_retention_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Locks a bucket's retention policy.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function lock_retention_policy($bucketName)
+function lock_retention_policy(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->reload();
diff --git a/storage/src/make_public.php b/storage/src/make_public.php
index c6c5130fe9..9e47d17cbd 100644
--- a/storage/src/make_public.php
+++ b/storage/src/make_public.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Make an object publically accessible.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function make_public($bucketName, $objectName)
+function make_public(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/move_object.php b/storage/src/move_object.php
index fde4271bc5..0145a4849a 100644
--- a/storage/src/move_object.php
+++ b/storage/src/move_object.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,17 +30,16 @@
* Move an object to a new name and/or bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $newBucketName the destination bucket name.
+ * (e.g. 'my-other-bucket')
* @param string $newObjectName the destination object name.
+ * (e.g. 'my-other-object')
*/
-function move_object($bucketName, $objectName, $newBucketName, $newObjectName)
+function move_object(string $bucketName, string $objectName, string $newBucketName, string $newObjectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $newBucketName = 'my-other-bucket';
- // $newObjectName = 'my-other-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/object_csek_to_cmek.php b/storage/src/object_csek_to_cmek.php
index fb6d9aa6ed..37ade36772 100644
--- a/storage/src/object_csek_to_cmek.php
+++ b/storage/src/object_csek_to_cmek.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -31,20 +31,18 @@
* Encryption Key.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $decryptionKey The Base64 encoded decryption key, which should
+ * (e.g. 'TIbv/fjexq+VmtXzAlc63J4z5kFmWJ6NdAPQulQBT7g=')
* be the same key originally used to encrypt the object.
* @param string $kmsKeyName The name of the KMS key to manage this object.
* Key names are provided in the following format:
* `projects//locations//keyRings//cryptoKeys/`.
*/
-function object_csek_to_cmek($bucketName, $objectName, $decryptionKey, $kmsKeyName)
+function object_csek_to_cmek(string $bucketName, string $objectName, string $decryptionKey, string $kmsKeyName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $decryptionKey = 'TIbv/fjexq+VmtXzAlc63J4z5kFmWJ6NdAPQulQBT7g=';
- // $kmsKeyName = "";
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/object_get_kms_key.php b/storage/src/object_get_kms_key.php
new file mode 100644
index 0000000000..b8b13c5368
--- /dev/null
+++ b/storage/src/object_get_kms_key.php
@@ -0,0 +1,53 @@
+bucket($bucketName);
+ $object = $bucket->object($objectName);
+ $info = $object->info();
+
+ printf(
+ 'The KMS key of the object is %s' . PHP_EOL,
+ $info['kmsKeyName'],
+ );
+}
+# [END storage_object_get_kms_key]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/storage/src/object_metadata.php b/storage/src/object_metadata.php
index 8bc2cf53ed..075a3e911a 100644
--- a/storage/src/object_metadata.php
+++ b/storage/src/object_metadata.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* List object metadata.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function object_metadata($bucketName, $objectName)
+function object_metadata(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/print_bucket_acl_for_user.php b/storage/src/print_bucket_acl_for_user.php
index 7732409cff..82fa38b3d4 100644
--- a/storage/src/print_bucket_acl_for_user.php
+++ b/storage/src/print_bucket_acl_for_user.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Print an entity role for a bucket ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $entity The entity for which to query access controls.
+ * (e.g. 'user-example@domain.com')
*/
function print_bucket_acl_for_user(
string $bucketName,
string $entity
): void {
- // $bucketName = 'my-bucket';
- // $entity = 'user-example@domain.com';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$acl = $bucket->acl();
diff --git a/storage/src/print_bucket_default_acl.php b/storage/src/print_bucket_default_acl.php
new file mode 100644
index 0000000000..5d298ba57d
--- /dev/null
+++ b/storage/src/print_bucket_default_acl.php
@@ -0,0 +1,48 @@
+bucket($bucketName);
+ $defaultAcl = $bucket->defaultAcl()->get();
+
+ foreach ($defaultAcl as $item) {
+ printf('%s: %s' . PHP_EOL, $item['entity'], $item['role']);
+ }
+}
+# [END storage_print_bucket_default_acl]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/storage/src/print_bucket_website_configuration.php b/storage/src/print_bucket_website_configuration.php
new file mode 100644
index 0000000000..823de6c542
--- /dev/null
+++ b/storage/src/print_bucket_website_configuration.php
@@ -0,0 +1,54 @@
+bucket($bucketName);
+ $info = $bucket->info();
+
+ if (!array_key_exists('website', $info)) {
+ printf('Bucket website configuration not set' . PHP_EOL);
+ } else {
+ printf(
+ 'Index page: %s' . PHP_EOL . '404 page: %s' . PHP_EOL,
+ $info['website']['mainPageSuffix'],
+ $info['website']['notFoundPage'],
+ );
+ }
+}
+# [END storage_print_bucket_website_configuration]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/storage/src/print_file_acl_for_user.php b/storage/src/print_file_acl_for_user.php
index 6defb8506f..8414eff396 100644
--- a/storage/src/print_file_acl_for_user.php
+++ b/storage/src/print_file_acl_for_user.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,18 +30,17 @@
* Print an entity role for a file ACL.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $entity The entity for which to query access controls.
+ * (e.g. 'user-example@domain.com')
*/
function print_file_acl_for_user(
string $bucketName,
string $objectName,
string $entity
): void {
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $entity = 'user-example@domain.com';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/print_pubsub_bucket_notification.php b/storage/src/print_pubsub_bucket_notification.php
index d52ea107c6..def11387be 100644
--- a/storage/src/print_pubsub_bucket_notification.php
+++ b/storage/src/print_pubsub_bucket_notification.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -33,15 +33,14 @@
* https://cloud.google.com/storage/docs/reporting-changes
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'your-bucket')
* @param string $notificationId The ID of the notification.
+ * (e.g. 'your-notification-id')
*/
function print_pubsub_bucket_notification(
string $bucketName,
string $notificationId
): void {
- // $bucketName = 'your-bucket';
- // $notificationId = 'your-notification-id';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$notification = $bucket->notification($notificationId);
diff --git a/storage/src/release_event_based_hold.php b/storage/src/release_event_based_hold.php
index fad14a1f22..48903c4f94 100644
--- a/storage/src/release_event_based_hold.php
+++ b/storage/src/release_event_based_hold.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Releases an event-based hold for an object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function release_event_based_hold($bucketName, $objectName)
+function release_event_based_hold(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/release_temporary_hold.php b/storage/src/release_temporary_hold.php
index 6ec57af64c..d1d73893e6 100644
--- a/storage/src/release_temporary_hold.php
+++ b/storage/src/release_temporary_hold.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Releases a temporary hold for an object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function release_temporary_hold($bucketName, $objectName)
+function release_temporary_hold(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/remove_bucket_conditional_iam_binding.php b/storage/src/remove_bucket_conditional_iam_binding.php
index fa531a3533..3df5e932e4 100644
--- a/storage/src/remove_bucket_conditional_iam_binding.php
+++ b/storage/src/remove_bucket_conditional_iam_binding.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -33,19 +33,17 @@
* @see https://cloud.google.com/storage/docs/access-control/iam#conditions.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $role the role that will be given to members in this binding.
- * @param string $title The title of the condition.
+ * (e.g. 'roles/storage.objectViewer')
+ * @param string $title The title of the condition. (e.g. 'Title')
* @param string $description The description of the condition.
+ * (e.g. 'Condition Description')
* @param string $expression Te condition specified in CEL expression language.
+ * (e.g. 'resource.name.startsWith("projects/_/buckets/bucket-name/objects/prefix-a-")')
*/
-function remove_bucket_conditional_iam_binding($bucketName, $role, $title, $description, $expression)
+function remove_bucket_conditional_iam_binding(string $bucketName, string $role, string $title, string $description, string $expression): void
{
- // $bucketName = 'my-bucket';
- // $role = 'roles/storage.objectViewer';
- // $title = 'Title';
- // $description = 'Condition Description';
- // $expression = 'resource.name.startsWith("projects/_/buckets/bucket-name/objects/prefix-a-")';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/remove_bucket_iam_member.php b/storage/src/remove_bucket_iam_member.php
index 5c451bd574..45fedf3f19 100644
--- a/storage/src/remove_bucket_iam_member.php
+++ b/storage/src/remove_bucket_iam_member.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Removes a member / role IAM pair from a given Cloud Storage bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $role The role from which the specified member should be removed.
+ * (e.g. 'roles/storage.objectViewer')
* @param string $member The member to be removed from the specified role.
+ * (e.g. 'group:example@google.com')
*/
-function remove_bucket_iam_member($bucketName, $role, $member)
+function remove_bucket_iam_member(string $bucketName, string $role, string $member): void
{
- // $bucketName = 'my-bucket';
- // $role = 'roles/storage.objectViewer';
- // $member = 'group:example@google.com';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$iam = $bucket->iam();
diff --git a/storage/src/remove_bucket_label.php b/storage/src/remove_bucket_label.php
index 436d50f02e..f465bdecc1 100644
--- a/storage/src/remove_bucket_label.php
+++ b/storage/src/remove_bucket_label.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Removes a label from a bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $labelName The name of the label to remove.
+ * (e.g. 'label-key-to-remove')
*/
-function remove_bucket_label($bucketName, $labelName)
+function remove_bucket_label(string $bucketName, string $labelName): void
{
- // $bucketName = 'my-bucket';
- // $labelName = 'label-key-to-remove';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$labels = [$labelName => null];
diff --git a/storage/src/remove_cors_configuration.php b/storage/src/remove_cors_configuration.php
index 6e4d8edfd8..29e8873506 100644
--- a/storage/src/remove_cors_configuration.php
+++ b/storage/src/remove_cors_configuration.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Remove the CORS configuration from the specified bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function remove_cors_configuration($bucketName)
+function remove_cors_configuration(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/remove_retention_policy.php b/storage/src/remove_retention_policy.php
index 621f2dd507..3ee7b945cc 100644
--- a/storage/src/remove_retention_policy.php
+++ b/storage/src/remove_retention_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Removes a bucket's retention policy.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function remove_retention_policy($bucketName)
+function remove_retention_policy(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->reload();
diff --git a/storage/src/rotate_encryption_key.php b/storage/src/rotate_encryption_key.php
index cee8d0b825..dc0c7d252d 100644
--- a/storage/src/rotate_encryption_key.php
+++ b/storage/src/rotate_encryption_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,24 +30,23 @@
* Change the encryption key used to store an existing object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $oldBase64EncryptionKey The Base64 encoded AES-256 encryption
* key originally used to encrypt the object. See the documentation on
* Customer-Supplied Encryption keys for more info:
* https://cloud.google.com/storage/docs/encryption/using-customer-supplied-keys
+ * (e.g. 'TIbv/fjexq+VmtXzAlc63J4z5kFmWJ6NdAPQulQBT7g=')
* @param string $newBase64EncryptionKey The new base64 encoded encryption key.
+ * (e.g. '0mMWhFvQOdS4AmxRpo8SJxXn5MjFhbz7DkKBUdUIef8=')
*/
function rotate_encryption_key(
- $bucketName,
- $objectName,
- $oldBase64EncryptionKey,
- $newBase64EncryptionKey
-) {
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $oldbase64EncryptionKey = 'TIbv/fjexq+VmtXzAlc63J4z5kFmWJ6NdAPQulQBT7g=';
- // $newBase64EncryptionKey = '0mMWhFvQOdS4AmxRpo8SJxXn5MjFhbz7DkKBUdUIef8=';
-
+ string $bucketName,
+ string $objectName,
+ string $oldBase64EncryptionKey,
+ string $newBase64EncryptionKey
+): void {
$storage = new StorageClient();
$object = $storage->bucket($bucketName)->object($objectName);
diff --git a/storage/src/set_bucket_autoclass.php b/storage/src/set_bucket_autoclass.php
new file mode 100644
index 0000000000..0a57c86c89
--- /dev/null
+++ b/storage/src/set_bucket_autoclass.php
@@ -0,0 +1,59 @@
+bucket($bucketName);
+
+ $bucket->update([
+ 'autoclass' => [
+ 'enabled' => $autoclassStatus,
+ ],
+ ]);
+
+ printf(
+ 'Updated bucket %s with autoclass set to %s.' . PHP_EOL,
+ $bucketName,
+ $autoclassStatus ? 'true' : 'false'
+ );
+}
+# [END storage_set_autoclass]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/storage/src/set_bucket_public_iam.php b/storage/src/set_bucket_public_iam.php
index d2336a63b8..6487c3b05b 100644
--- a/storage/src/set_bucket_public_iam.php
+++ b/storage/src/set_bucket_public_iam.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Update the specified bucket's IAM configuration to make it publicly accessible.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function set_bucket_public_iam($bucketName)
+function set_bucket_public_iam(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/set_client_endpoint.php b/storage/src/set_client_endpoint.php
index 9001b8192b..508c01ec21 100644
--- a/storage/src/set_client_endpoint.php
+++ b/storage/src/set_client_endpoint.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Sets a custom endpoint for storage client.
*
* @param string $projectId The ID of your Google Cloud Platform project.
+ * (e.g. 'my-project-id')
* @param string $endpoint The endpoint for storage client to target.
+ * (e.g. 'https://storage.googleapis.com/')
*/
function set_client_endpoint(
string $projectId,
string $endpoint
): void {
- // $projectId = 'my-project-id';
- // $endpoint = 'https://storage.googleapis.com/';
-
$storage = new StorageClient([
'projectId' => $projectId,
'apiEndpoint' => $endpoint,
diff --git a/storage/src/set_event_based_hold.php b/storage/src/set_event_based_hold.php
index b6a7657208..9ff383893d 100644
--- a/storage/src/set_event_based_hold.php
+++ b/storage/src/set_event_based_hold.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Sets an event-based hold for an object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function set_event_based_hold($bucketName, $objectName)
+function set_event_based_hold(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/set_metadata.php b/storage/src/set_metadata.php
index 5c04005b83..5951cf310b 100644
--- a/storage/src/set_metadata.php
+++ b/storage/src/set_metadata.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Set a metadata key and value on the specified object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function set_metadata($bucketName, $objectName)
+function set_metadata(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/set_public_access_prevention_enforced.php b/storage/src/set_public_access_prevention_enforced.php
index 7ee50da30f..24d1ecfcaf 100644
--- a/storage/src/set_public_access_prevention_enforced.php
+++ b/storage/src/set_public_access_prevention_enforced.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Set the bucket Public Access Prevention to enforced.
*
* @param string $bucketName the name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function set_public_access_prevention_enforced($bucketName)
+function set_public_access_prevention_enforced(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/set_public_access_prevention_inherited.php b/storage/src/set_public_access_prevention_inherited.php
index 35caa5c5a5..9f30fbbcd8 100644
--- a/storage/src/set_public_access_prevention_inherited.php
+++ b/storage/src/set_public_access_prevention_inherited.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Set the bucket Public Access Prevention to inherited.
*
* @param string $bucketName the name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function set_public_access_prevention_inherited($bucketName)
+function set_public_access_prevention_inherited(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/set_public_access_prevention_unspecified.php b/storage/src/set_public_access_prevention_unspecified.php
index de8779c739..212ea76b15 100644
--- a/storage/src/set_public_access_prevention_unspecified.php
+++ b/storage/src/set_public_access_prevention_unspecified.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Set the bucket Public Access Prevention to unspecified.
*
* @param string $bucketName the name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function set_public_access_prevention_unspecified($bucketName)
+function set_public_access_prevention_unspecified(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/set_retention_policy.php b/storage/src/set_retention_policy.php
index 34e39b447f..86bc80c23f 100644
--- a/storage/src/set_retention_policy.php
+++ b/storage/src/set_retention_policy.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Sets a bucket's retention policy.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param int $retentionPeriod The retention period for objects in bucket, in seconds.
+ * (e.g. 3600)
*/
-function set_retention_policy($bucketName, $retentionPeriod)
+function set_retention_policy(string $bucketName, int $retentionPeriod): void
{
- // $bucketName = 'my-bucket';
- // $retentionPeriod = 3600;
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$bucket->update([
diff --git a/storage/src/set_rpo_async_turbo.php b/storage/src/set_rpo_async_turbo.php
index 713f96224a..89b6bcde94 100644
--- a/storage/src/set_rpo_async_turbo.php
+++ b/storage/src/set_rpo_async_turbo.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -31,11 +31,10 @@
* The bucket must be a dual-region bucket.
*
* @param string $bucketName the name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function set_rpo_async_turbo($bucketName)
+function set_rpo_async_turbo(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$rpo = 'ASYNC_TURBO';
diff --git a/storage/src/set_rpo_default.php b/storage/src/set_rpo_default.php
index f1283b99c7..6765e5c011 100644
--- a/storage/src/set_rpo_default.php
+++ b/storage/src/set_rpo_default.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* Set the bucket's replication behavior or recovery point objective (RPO) to `DEFAULT`.
*
* @param string $bucketName the name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function set_rpo_default($bucketName)
+function set_rpo_default(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$rpo = 'DEFAULT';
diff --git a/storage/src/set_temporary_hold.php b/storage/src/set_temporary_hold.php
index 4fc057751a..e5da7ff9f5 100644
--- a/storage/src/set_temporary_hold.php
+++ b/storage/src/set_temporary_hold.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Sets a temporary hold for an object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function set_temporary_hold($bucketName, $objectName)
+function set_temporary_hold(string $bucketName, string $objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/upload_encrypted_object.php b/storage/src/upload_encrypted_object.php
index 344892a550..cccc6f8fc3 100644
--- a/storage/src/upload_encrypted_object.php
+++ b/storage/src/upload_encrypted_object.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,17 +30,16 @@
* Upload an encrypted file.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $source The path to the file to upload.
+ * (e.g. '/path/to/your/file')
* @param string $base64EncryptionKey The base64 encoded encryption key.
+ * (e.g. 'TIbv/fjexq+VmtXzAlc63J4z5kFmWJ6NdAPQulQBT7g=')
*/
-function upload_encrypted_object($bucketName, $objectName, $source, $base64EncryptionKey)
+function upload_encrypted_object(string $bucketName, string $objectName, string $source, string $base64EncryptionKey): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $source = '/path/to/your/file';
- // $base64EncryptionKey = 'TIbv/fjexq+VmtXzAlc63J4z5kFmWJ6NdAPQulQBT7g=';
-
$storage = new StorageClient();
$file = fopen($source, 'r');
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/upload_object.php b/storage/src/upload_object.php
index 5735cc5ebc..ce1b4d46fb 100644
--- a/storage/src/upload_object.php
+++ b/storage/src/upload_object.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,15 +30,14 @@
* Upload a file.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $source The path to the file to upload.
+ * (e.g. '/path/to/your/file')
*/
-function upload_object($bucketName, $objectName, $source)
+function upload_object(string $bucketName, string $objectName, string $source): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $source = '/path/to/your/file';
-
$storage = new StorageClient();
$file = fopen($source, 'r');
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/upload_object_from_memory.php b/storage/src/upload_object_from_memory.php
index b9d5953647..ecd885dda5 100644
--- a/storage/src/upload_object_from_memory.php
+++ b/storage/src/upload_object_from_memory.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,18 +30,17 @@
* Upload an object from memory buffer.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $contents The contents to upload to the file.
+ * (e.g. 'these are my contents')
*/
function upload_object_from_memory(
string $bucketName,
string $objectName,
string $contents
): void {
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $contents = 'these are my contents';
-
$storage = new StorageClient();
$stream = fopen('data://text/plain,' . $contents, 'r');
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/upload_object_stream.php b/storage/src/upload_object_stream.php
index e65dfdbab1..5fff68accd 100644
--- a/storage/src/upload_object_stream.php
+++ b/storage/src/upload_object_stream.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -31,15 +31,14 @@
* Upload a chunked file stream.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $contents The contents to upload via stream chunks.
+ * (e.g. 'these are my contents')
*/
function upload_object_stream(string $bucketName, string $objectName, string $contents): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $contents = 'these are my contents';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$writeStream = new WriteStream(null, [
diff --git a/storage/src/upload_object_v4_signed_url.php b/storage/src/upload_object_v4_signed_url.php
index 14c967e17f..8a2533365d 100644
--- a/storage/src/upload_object_v4_signed_url.php
+++ b/storage/src/upload_object_v4_signed_url.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,13 +30,12 @@
* Generate a v4 signed URL for uploading an object.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
*/
-function upload_object_v4_signed_url(http://github.com/$bucketName,%20$objectName)
+function upload_object_v4_signed_url(http://github.com/string%20$bucketName,%20string%20$objectName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
diff --git a/storage/src/upload_with_kms_key.php b/storage/src/upload_with_kms_key.php
index f24d6d9141..11b43746b9 100644
--- a/storage/src/upload_with_kms_key.php
+++ b/storage/src/upload_with_kms_key.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,19 +30,17 @@
* Upload a file using KMS encryption.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
* @param string $objectName The name of your Cloud Storage object.
+ * (e.g. 'my-object')
* @param string $source The path to the file to upload.
+ * (e.g. '/path/to/your/file')
* @param string $kmsKeyName The KMS key used to encrypt objects server side.
* Key names are provided in the following format:
* `projects//locations//keyRings//cryptoKeys/`.
*/
-function upload_with_kms_key($bucketName, $objectName, $source, $kmsKeyName)
+function upload_with_kms_key(string $bucketName, string $objectName, string $source, string $kmsKeyName): void
{
- // $bucketName = 'my-bucket';
- // $objectName = 'my-object';
- // $source = '/path/to/your/file';
- // $kmsKeyName = "";
-
$storage = new StorageClient();
$file = fopen($source, 'r');
$bucket = $storage->bucket($bucketName);
diff --git a/storage/src/view_bucket_iam_members.php b/storage/src/view_bucket_iam_members.php
index 00e902fc73..895a1b9d46 100644
--- a/storage/src/view_bucket_iam_members.php
+++ b/storage/src/view_bucket_iam_members.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storage/README.md
*/
namespace Google\Cloud\Samples\Storage;
@@ -30,11 +30,10 @@
* View Bucket IAM members for a given Cloud Storage bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
+ * (e.g. 'my-bucket')
*/
-function view_bucket_iam_members($bucketName)
+function view_bucket_iam_members(string $bucketName): void
{
- // $bucketName = 'my-bucket';
-
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
diff --git a/storage/test/storageTest.php b/storage/test/storageTest.php
index 43521ad56b..e824641ad5 100644
--- a/storage/test/storageTest.php
+++ b/storage/test/storageTest.php
@@ -62,6 +62,21 @@ public function testBucketAcl()
$this->assertRegExp('/: OWNER/', $output);
}
+ public function testPrintDefaultBucketAcl()
+ {
+ $output = $this->runFunctionSnippet('print_bucket_default_acl', [
+ self::$tempBucket->name(),
+ ]);
+
+ $defaultAcl = self::$tempBucket->defaultAcl()->get();
+ foreach ($defaultAcl as $item) {
+ $this->assertStringContainsString(
+ sprintf('%s: %s' . PHP_EOL, $item['entity'], $item['role']),
+ $output,
+ );
+ }
+ }
+
/**
* @return void
*/
@@ -112,7 +127,6 @@ public function testManageBucketAcl()
public function testListBuckets()
{
$output = $this->runFunctionSnippet('list_buckets');
-
$this->assertStringContainsString('Bucket:', $output);
}
@@ -139,6 +153,23 @@ public function testCreateGetDeleteBuckets()
$this->assertStringContainsString("Bucket deleted: $bucketName", $output);
}
+ public function testGetBucketClassAndLocation()
+ {
+ $output = $this->runFunctionSnippet(
+ 'get_bucket_class_and_location',
+ [self::$tempBucket->name()],
+ );
+
+ $bucketInfo = self::$tempBucket->info();
+
+ $this->assertStringContainsString(sprintf(
+ 'Bucket: %s, storage class: %s, location: %s' . PHP_EOL,
+ $bucketInfo['name'],
+ $bucketInfo['storageClass'],
+ $bucketInfo['location'],
+ ), $output);
+ }
+
public function testBucketDefaultAcl()
{
$output = $this->runFunctionSnippet('get_bucket_default_acl', [
@@ -444,8 +475,30 @@ public function testUploadWithKmsKey()
$objectName,
$this->keyName()
));
+
+ return $objectName;
}
+ /** @depends testUploadWithKmsKey */
+ public function testObjectGetKmsKey(string $objectName)
+ {
+ $kmsEncryptedBucketName = self::$bucketName . '-kms-encrypted';
+ $bucket = self::$storage->bucket($kmsEncryptedBucketName);
+ $objectInfo = $bucket->object($objectName)->info();
+
+ $output = $this->runFunctionSnippet('object_get_kms_key', [
+ $kmsEncryptedBucketName,
+ $objectName,
+ ]);
+
+ $this->assertEquals(
+ sprintf(
+ 'The KMS key of the object is %s' . PHP_EOL,
+ $objectInfo['kmsKeyName'],
+ ),
+ $output,
+ );
+ }
public function testBucketVersioning()
{
$output = self::runFunctionSnippet('enable_versioning', [
@@ -474,16 +527,21 @@ public function testBucketWebsiteConfiguration()
'name' => 'test.html'
]);
+ $output = self::runFunctionSnippet('print_bucket_website_configuration', [
+ $bucket->name(),
+ ]);
+
+ $this->assertEquals(
+ sprintf('Bucket website configuration not set' . PHP_EOL),
+ $output,
+ );
+
$output = self::runFunctionSnippet('define_bucket_website_configuration', [
$bucket->name(),
$obj->name(),
$obj->name(),
]);
- $info = $bucket->reload();
- $obj->delete();
- $bucket->delete();
-
$this->assertEquals(
sprintf(
'Static website bucket %s is set up to use %s as the index page and %s as the 404 page.',
@@ -494,8 +552,23 @@ public function testBucketWebsiteConfiguration()
$output
);
- $this->assertEquals($obj->name(), $info['website']['mainPageSuffix']);
- $this->assertEquals($obj->name(), $info['website']['notFoundPage']);
+ $info = $bucket->reload();
+
+ $output = self::runFunctionSnippet('print_bucket_website_configuration', [
+ $bucket->name(),
+ ]);
+
+ $this->assertEquals(
+ sprintf(
+ 'Index page: %s' . PHP_EOL . '404 page: %s' . PHP_EOL,
+ $info['website']['mainPageSuffix'],
+ $info['website']['notFoundPage'],
+ ),
+ $output,
+ );
+
+ $obj->delete();
+ $bucket->delete();
}
public function testGetServiceAccount()
@@ -757,6 +830,54 @@ public function testChangeDefaultStorageClass()
);
}
+ public function testGetBucketWithAutoclass()
+ {
+ $bucketName = uniqid('samples-get-autoclass-');
+ $bucket = self::$storage->createBucket($bucketName, [
+ 'autoclass' => [
+ 'enabled' => true,
+ ],
+ 'location' => 'US',
+ ]);
+
+ $output = self::runFunctionSnippet('get_bucket_autoclass', [
+ $bucketName,
+ ]);
+ $bucket->delete();
+
+ $this->assertStringContainsString(
+ sprintf('Bucket %s has autoclass enabled: %s', $bucketName, true),
+ $output
+ );
+ }
+
+ public function testSetBucketWithAutoclass()
+ {
+ $bucket = self::$storage->createBucket(uniqid('samples-set-autoclass-'), [
+ 'autoclass' => [
+ 'enabled' => true,
+ ],
+ 'location' => 'US',
+ ]);
+ $info = $bucket->reload();
+ $this->assertArrayHasKey('autoclass', $info);
+ $this->assertTrue($info['autoclass']['enabled']);
+
+ $output = self::runFunctionSnippet('set_bucket_autoclass', [
+ $bucket->name(),
+ false
+ ]);
+ $bucket->delete();
+
+ $this->assertStringContainsString(
+ sprintf(
+ 'Updated bucket %s with autoclass set to false.',
+ $bucket->name(),
+ ),
+ $output
+ );
+ }
+
public function testDeleteFileArchivedGeneration()
{
$bucket = self::$storage->createBucket(uniqid('samples-delete-file-archived-generation-'), [
diff --git a/tasks/src/create_http_task.php b/tasks/src/create_http_task.php
index c1a5c4198a..f5cd7d9454 100644
--- a/tasks/src/create_http_task.php
+++ b/tasks/src/create_http_task.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/tasks/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/tasks/README.md
*/
// Include Google Cloud dependendencies using Composer
diff --git a/testing/run_test_suite.sh b/testing/run_test_suite.sh
index d4cc5a4852..d633b974ad 100755
--- a/testing/run_test_suite.sh
+++ b/testing/run_test_suite.sh
@@ -85,14 +85,21 @@ FILES_CHANGED=$(git diff --name-only HEAD $(git merge-base HEAD master))
if [ -z "$PULL_REQUEST_NUMBER" ]; then
RUN_ALL_TESTS=1
else
+ labels=$(curl "https://api.github.com/repos/GoogleCloudPlatform/php-docs-samples/issues/$PULL_REQUEST_NUMBER/labels")
+
# Check to see if the repo includes the "kokoro:run-all" label
- if curl "https://api.github.com/repos/GoogleCloudPlatform/php-docs-samples/issues/$PULL_REQUEST_NUMBER/labels" \
- | grep -q "kokoro:run-all"; then
+ if grep -q "kokoro:run-all" <<< $labels; then
RUN_ALL_TESTS=1
else
RUN_ALL_TESTS=0
fi
+ # Check to see if the repo includes the "spanner:run-backup-tests" label
+ # If we intend to run the backup tests in Spanner, we set the env variable
+ if grep -q "spanner:run-backup-tests" <<< $labels; then
+ export GOOGLE_SPANNER_RUN_BACKUP_TESTS=true
+ fi
+
fi
if [ "${TEST_DIRECTORIES}" = "" ]; then
diff --git a/texttospeech/src/list_voices.php b/texttospeech/src/list_voices.php
index ee70220934..8f2f014ecd 100644
--- a/texttospeech/src/list_voices.php
+++ b/texttospeech/src/list_voices.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/texttospeech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/texttospeech/README.md
*/
namespace Google\Cloud\Samples\TextToSpeech;
diff --git a/texttospeech/src/synthesize_ssml.php b/texttospeech/src/synthesize_ssml.php
index bf4ecdaabb..7a0fe4469f 100644
--- a/texttospeech/src/synthesize_ssml.php
+++ b/texttospeech/src/synthesize_ssml.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/texttospeech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/texttospeech/README.md
*/
namespace Google\Cloud\Samples\TextToSpeech;
diff --git a/texttospeech/src/synthesize_ssml_file.php b/texttospeech/src/synthesize_ssml_file.php
index b426372036..7ccd1e1290 100644
--- a/texttospeech/src/synthesize_ssml_file.php
+++ b/texttospeech/src/synthesize_ssml_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/texttospeech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/texttospeech/README.md
*/
namespace Google\Cloud\Samples\TextToSpeech;
diff --git a/texttospeech/src/synthesize_text.php b/texttospeech/src/synthesize_text.php
index f0f948f6c0..ff441cf9f2 100644
--- a/texttospeech/src/synthesize_text.php
+++ b/texttospeech/src/synthesize_text.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/texttospeech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/texttospeech/README.md
*/
namespace Google\Cloud\Samples\TextToSpeech;
diff --git a/texttospeech/src/synthesize_text_effects_profile.php b/texttospeech/src/synthesize_text_effects_profile.php
index fdb8e28a53..14acbf554c 100644
--- a/texttospeech/src/synthesize_text_effects_profile.php
+++ b/texttospeech/src/synthesize_text_effects_profile.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/texttospeech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/texttospeech/README.md
*/
namespace Google\Cloud\Samples\TextToSpeech;
diff --git a/texttospeech/src/synthesize_text_effects_profile_file.php b/texttospeech/src/synthesize_text_effects_profile_file.php
index 3bb5e5953a..80fe8033eb 100644
--- a/texttospeech/src/synthesize_text_effects_profile_file.php
+++ b/texttospeech/src/synthesize_text_effects_profile_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/texttospeech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/texttospeech/README.md
*/
namespace Google\Cloud\Samples\TextToSpeech;
diff --git a/texttospeech/src/synthesize_text_file.php b/texttospeech/src/synthesize_text_file.php
index 68094d9a0a..db7067f254 100644
--- a/texttospeech/src/synthesize_text_file.php
+++ b/texttospeech/src/synthesize_text_file.php
@@ -18,7 +18,7 @@
/**
* For instructions on how to run the samples:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/texttospeech/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/texttospeech/README.md
*/
namespace Google\Cloud\Samples\TextToSpeech;
diff --git a/translate/src/detect_language.php b/translate/src/detect_language.php
index 10b9a921cf..63a3d48728 100644
--- a/translate/src/detect_language.php
+++ b/translate/src/detect_language.php
@@ -18,25 +18,26 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/translate/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/translate/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 2) {
- return printf("Usage: php %s TEXT\n", __FILE__);
-}
-list($_, $text) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_detect_language]
use Google\Cloud\Translate\TranslateClient;
-/** Uncomment and populate these variables in your code */
-// $text = 'The text whose language to detect. This will be detected as en.';
-
-$translate = new TranslateClient();
-$result = $translate->detectLanguage($text);
-print("Language code: $result[languageCode]\n");
-print("Confidence: $result[confidence]\n");
+/**
+ * @param string $text The text whose language to detect. This will be detected as en.
+ */
+function detect_language(string $text): void
+{
+ $translate = new TranslateClient();
+ $result = $translate->detectLanguage($text);
+ print("Language code: $result[languageCode]\n");
+ print("Confidence: $result[confidence]\n");
+}
// [END translate_detect_language]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/list_codes.php b/translate/src/list_codes.php
index 04143ea6ca..2eb77eadf2 100644
--- a/translate/src/list_codes.php
+++ b/translate/src/list_codes.php
@@ -18,21 +18,23 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/translate/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/translate/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) != 1) {
- return printf("Usage: php %s\n", __FILE__);
-}
+namespace Google\Cloud\Samples\Translate;
// [START translate_list_codes]
use Google\Cloud\Translate\TranslateClient;
-$translate = new TranslateClient();
-foreach ($translate->languages() as $code) {
- print("$code\n");
+function list_codes(): void
+{
+ $translate = new TranslateClient();
+ foreach ($translate->languages() as $code) {
+ print("$code\n");
+ }
}
// [END translate_list_codes]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/list_languages.php b/translate/src/list_languages.php
index d04a90bd55..afd1b615a7 100644
--- a/translate/src/list_languages.php
+++ b/translate/src/list_languages.php
@@ -18,28 +18,29 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/translate/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/translate/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) > 2) {
- return printf("Usage: php %s [TARGET_LANGUAGE]\n", __FILE__);
-}
-$targetLanguage = isset($argv[1]) ? $argv[1] : 'en';
+namespace Google\Cloud\Samples\Translate;
// [START translate_list_language_names]
use Google\Cloud\Translate\TranslateClient;
-/** Uncomment and populate these variables in your code */
-// $targetLanguage = 'en'; // Language to print the language names in
-
-$translate = new TranslateClient();
-$result = $translate->localizedLanguages([
- 'target' => $targetLanguage,
-]);
-foreach ($result as $lang) {
- printf('%s: %s' . PHP_EOL, $lang['code'], $lang['name']);
+/**
+ * @param string $targetLanguage Language to print the language names in
+ */
+function list_languages(string $targetLanguage = 'en'): void
+{
+ $translate = new TranslateClient();
+ $result = $translate->localizedLanguages([
+ 'target' => $targetLanguage,
+ ]);
+ foreach ($result as $lang) {
+ printf('%s: %s' . PHP_EOL, $lang['code'], $lang['name']);
+ }
}
// [END translate_list_language_names]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/translate.php b/translate/src/translate.php
index 58b4754259..89baf58de8 100644
--- a/translate/src/translate.php
+++ b/translate/src/translate.php
@@ -18,29 +18,33 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/translate/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/translate/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 2 || count($argv) > 3) {
- return printf("Usage: php %s TEXT [TARGET_LANGUAGE]\n", __FILE__);
-}
-list($_, $text) = $argv;
-$targetLanguage = isset($argv[2]) ? $argv[2] : 'en';
+namespace Google\Cloud\Samples\Translate;
// [START translate_translate_text]
use Google\Cloud\Translate\TranslateClient;
-/** Uncomment and populate these variables in your code */
-// $text = 'The text to translate.';
-// $targetLanguage = 'ja'; // Language to translate to
+/**
+ * @param string $text The text to translate.
+ * @param string $targetLanguage Language to translate to.
+ */
+function translate(string $text, string $targetLanguage): void
+{
+ /** Uncomment and populate these variables in your code */
+ // $text = 'The text to translate.';
+ // $targetLanguage = 'ja'; // Language to translate to
-$translate = new TranslateClient();
-$result = $translate->translate($text, [
- 'target' => $targetLanguage,
-]);
-print("Source language: $result[source]\n");
-print("Translation: $result[text]\n");
+ $translate = new TranslateClient();
+ $result = $translate->translate($text, [
+ 'target' => $targetLanguage,
+ ]);
+ print("Source language: $result[source]\n");
+ print("Translation: $result[text]\n");
+}
// [END translate_translate_text]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/translate_with_model.php b/translate/src/translate_with_model.php
index 5dd7ae289b..19b5bf7922 100644
--- a/translate/src/translate_with_model.php
+++ b/translate/src/translate_with_model.php
@@ -18,32 +18,32 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/translate/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/translate/README.md
*/
-// Include Google Cloud dependendencies using Composer
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 2 || count($argv) > 3) {
- return printf("Usage: php %s TEXT [TARGET_LANGUAGE]\n", __FILE__);
-}
-list($_, $text) = $argv;
-$targetLanguage = isset($argv[2]) ? $argv[2] : 'en';
+namespace Google\Cloud\Samples\Translate;
// [START translate_text_with_model]
use Google\Cloud\Translate\TranslateClient;
-/** Uncomment and populate these variables in your code */
-// $text = 'The text to translate.'
-// $targetLanguage = 'ja'; // Language to translate to
-
-$model = 'nmt'; // "base" for standard edition, "nmt" for premium
-$translate = new TranslateClient();
-$result = $translate->translate($text, [
- 'target' => $targetLanguage,
- 'model' => $model,
-]);
-print("Source language: $result[source]\n");
-print("Translation: $result[text]\n");
-print("Model: $result[model]\n");
+/**
+ * @param string $text The text to translate.
+ * @param string $targetLanguage Language to translate to.
+ */
+function translate_with_model(string $text, string $targetLanguage): void
+{
+ $model = 'nmt'; // "base" for standard edition, "nmt" for premium
+ $translate = new TranslateClient();
+ $result = $translate->translate($text, [
+ 'target' => $targetLanguage,
+ 'model' => $model,
+ ]);
+ print("Source language: $result[source]\n");
+ print("Translation: $result[text]\n");
+ print("Model: $result[model]\n");
+}
// [END translate_text_with_model]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_batch_translate_text.php b/translate/src/v3_batch_translate_text.php
index 3569c1d669..fec6e52a76 100644
--- a/translate/src/v3_batch_translate_text.php
+++ b/translate/src/v3_batch_translate_text.php
@@ -15,12 +15,7 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 7 || count($argv) > 7) {
- return printf("Usage: php %s INPUT_URI OUTPUT_URI PROJECT_ID LOCATION SOURCE_LANGUAGE TARGET_LANGUAGE\n", __FILE__);
-}
-list($_, $inputUri, $outputUri, $projectId, $location, $sourceLang, $targetLang) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_batch_translate_text]
use Google\Cloud\Translate\V3\GcsDestination;
@@ -29,49 +24,63 @@
use Google\Cloud\Translate\V3\OutputConfig;
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $inputUri Path to to source input (e.g. "gs://cloud-samples-data/text.txt").
+ * @param string $outputUri Path to store results (e.g. "gs://YOUR_BUCKET_ID/results/").
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $location Project location (e.g. us-central1)
+ * @param string $targetLanguage Language to translate to.
+ * @param string $sourceLanguage Language of the source.
+ */
+function v3_batch_translate_text(
+ string $inputUri,
+ string $outputUri,
+ string $projectId,
+ string $location,
+ string $targetLanguage,
+ string $sourceLanguage
+): void {
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $inputUri = 'gs://cloud-samples-data/text.txt';
-// $outputUri = 'gs://YOUR_BUCKET_ID/path_to_store_results/';
-// $projectId = '[Google Cloud Project ID]';
-// $location = 'us-central1';
-// $sourceLang = 'en';
-// $targetLang = 'ja';
-$targetLanguageCodes = [$targetLang];
-$gcsSource = (new GcsSource())
- ->setInputUri($inputUri);
+ $targetLanguageCodes = [$targetLanguage];
+ $gcsSource = (new GcsSource())
+ ->setInputUri($inputUri);
-// Optional. Can be "text/plain" or "text/html".
-$mimeType = 'text/plain';
-$inputConfigsElement = (new InputConfig())
- ->setGcsSource($gcsSource)
- ->setMimeType($mimeType);
-$inputConfigs = [$inputConfigsElement];
-$gcsDestination = (new GcsDestination())
- ->setOutputUriPrefix($outputUri);
-$outputConfig = (new OutputConfig())
- ->setGcsDestination($gcsDestination);
-$formattedParent = $translationServiceClient->locationName($projectId, $location);
+ // Optional. Can be "text/plain" or "text/html".
+ $mimeType = 'text/plain';
+ $inputConfigsElement = (new InputConfig())
+ ->setGcsSource($gcsSource)
+ ->setMimeType($mimeType);
+ $inputConfigs = [$inputConfigsElement];
+ $gcsDestination = (new GcsDestination())
+ ->setOutputUriPrefix($outputUri);
+ $outputConfig = (new OutputConfig())
+ ->setGcsDestination($gcsDestination);
+ $formattedParent = $translationServiceClient->locationName($projectId, $location);
-try {
- $operationResponse = $translationServiceClient->batchTranslateText(
- $formattedParent,
- $sourceLang,
- $targetLanguageCodes,
- $inputConfigs,
- $outputConfig
- );
- $operationResponse->pollUntilComplete();
- if ($operationResponse->operationSucceeded()) {
- $response = $operationResponse->getResult();
- printf('Total Characters: %s' . PHP_EOL, $response->getTotalCharacters());
- printf('Translated Characters: %s' . PHP_EOL, $response->getTranslatedCharacters());
- } else {
- $error = $operationResponse->getError();
- print($error->getMessage());
+ try {
+ $operationResponse = $translationServiceClient->batchTranslateText(
+ $formattedParent,
+ $sourceLanguage,
+ $targetLanguageCodes,
+ $inputConfigs,
+ $outputConfig
+ );
+ $operationResponse->pollUntilComplete();
+ if ($operationResponse->operationSucceeded()) {
+ $response = $operationResponse->getResult();
+ printf('Total Characters: %s' . PHP_EOL, $response->getTotalCharacters());
+ printf('Translated Characters: %s' . PHP_EOL, $response->getTranslatedCharacters());
+ } else {
+ $error = $operationResponse->getError();
+ print($error->getMessage());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_batch_translate_text]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_batch_translate_text_with_glossary.php b/translate/src/v3_batch_translate_text_with_glossary.php
index abd2271d57..3de535b732 100644
--- a/translate/src/v3_batch_translate_text_with_glossary.php
+++ b/translate/src/v3_batch_translate_text_with_glossary.php
@@ -15,12 +15,7 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 8 || count($argv) > 8) {
- return printf("Usage: php %s INPUT_URI OUTPUT_URI PROJECT_ID LOCATION GLOSSARY_ID TARGET_LANGUAGE SOURCE_LANGUAGE\n", __FILE__);
-}
-list($_, $inputUri, $outputUri, $projectId, $location, $glossaryId, $targetLanguage, $sourceLanguage) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_batch_translate_text_with_glossary]
use Google\Cloud\Translate\V3\GcsDestination;
@@ -30,63 +25,78 @@
use Google\Cloud\Translate\V3\TranslateTextGlossaryConfig;
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
-
-/** Uncomment and populate these variables in your code */
-// $inputUri = 'gs://cloud-samples-data/text.txt';
-// $outputUri = 'gs://YOUR_BUCKET_ID/path_to_store_results/';
-// $projectId = '[Google Cloud Project ID]';
-// $location = 'us-central1';
-// $glossaryId = '[YOUR_GLOSSARY_ID]';
-// $targetLanguage = 'en';
-// $sourceLanguage = 'de';
-$glossaryPath = $translationServiceClient->glossaryName(
- $projectId,
- $location,
- $glossaryId
-);
-$targetLanguageCodes = [$targetLanguage];
-$gcsSource = (new GcsSource())
- ->setInputUri($inputUri);
+/**
+ * @param string $inputUri Path to to source input (e.g. "gs://cloud-samples-data/text.txt").
+ * @param string $outputUri Path to store results (e.g. "gs://YOUR_BUCKET_ID/results/").
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $location Project location (e.g. us-central1)
+ * @param string $glossaryId Your glossary ID.
+ * @param string $targetLanguage Language to translate to.
+ * @param string $sourceLanguage Language of the source.
+ */
+function v3_batch_translate_text_with_glossary(
+ string $inputUri,
+ string $outputUri,
+ string $projectId,
+ string $location,
+ string $glossaryId,
+ string $targetLanguage,
+ string $sourceLanguage
+): void {
+ $translationServiceClient = new TranslationServiceClient();
-// Optional. Can be "text/plain" or "text/html".
-$mimeType = 'text/plain';
-$inputConfigsElement = (new InputConfig())
- ->setGcsSource($gcsSource)
- ->setMimeType($mimeType);
-$inputConfigs = [$inputConfigsElement];
-$gcsDestination = (new GcsDestination())
- ->setOutputUriPrefix($outputUri);
-$outputConfig = (new OutputConfig())
- ->setGcsDestination($gcsDestination);
-$formattedParent = $translationServiceClient->locationName(
- $projectId,
- $location
-);
-$glossariesItem = (new TranslateTextGlossaryConfig())
- ->setGlossary($glossaryPath);
-$glossaries = ['ja' => $glossariesItem];
+ $glossaryPath = $translationServiceClient->glossaryName(
+ $projectId,
+ $location,
+ $glossaryId
+ );
+ $targetLanguageCodes = [$targetLanguage];
+ $gcsSource = (new GcsSource())
+ ->setInputUri($inputUri);
-try {
- $operationResponse = $translationServiceClient->batchTranslateText(
- $formattedParent,
- $sourceLanguage,
- $targetLanguageCodes,
- $inputConfigs,
- $outputConfig,
- ['glossaries' => $glossaries]
+ // Optional. Can be "text/plain" or "text/html".
+ $mimeType = 'text/plain';
+ $inputConfigsElement = (new InputConfig())
+ ->setGcsSource($gcsSource)
+ ->setMimeType($mimeType);
+ $inputConfigs = [$inputConfigsElement];
+ $gcsDestination = (new GcsDestination())
+ ->setOutputUriPrefix($outputUri);
+ $outputConfig = (new OutputConfig())
+ ->setGcsDestination($gcsDestination);
+ $formattedParent = $translationServiceClient->locationName(
+ $projectId,
+ $location
);
- $operationResponse->pollUntilComplete();
- if ($operationResponse->operationSucceeded()) {
- $response = $operationResponse->getResult();
- // Display the translation for each input text provided
- printf('Total Characters: %s' . PHP_EOL, $response->getTotalCharacters());
- printf('Translated Characters: %s' . PHP_EOL, $response->getTranslatedCharacters());
- } else {
- $error = $operationResponse->getError();
- print($error->getMessage());
+ $glossariesItem = (new TranslateTextGlossaryConfig())
+ ->setGlossary($glossaryPath);
+ $glossaries = ['ja' => $glossariesItem];
+
+ try {
+ $operationResponse = $translationServiceClient->batchTranslateText(
+ $formattedParent,
+ $sourceLanguage,
+ $targetLanguageCodes,
+ $inputConfigs,
+ $outputConfig,
+ ['glossaries' => $glossaries]
+ );
+ $operationResponse->pollUntilComplete();
+ if ($operationResponse->operationSucceeded()) {
+ $response = $operationResponse->getResult();
+ // Display the translation for each input text provided
+ printf('Total Characters: %s' . PHP_EOL, $response->getTotalCharacters());
+ printf('Translated Characters: %s' . PHP_EOL, $response->getTranslatedCharacters());
+ } else {
+ $error = $operationResponse->getError();
+ print($error->getMessage());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_batch_translate_text_with_glossary]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_batch_translate_text_with_glossary_and_model.php b/translate/src/v3_batch_translate_text_with_glossary_and_model.php
index 75a3ccf07e..4bd547b911 100644
--- a/translate/src/v3_batch_translate_text_with_glossary_and_model.php
+++ b/translate/src/v3_batch_translate_text_with_glossary_and_model.php
@@ -15,12 +15,7 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 9 || count($argv) > 9) {
- return printf("Usage: php %s INPUT_URI OUTPUT_URI PROJECT_ID LOCATION TARGET_LANGUAGE SOURCE_LANGUAGE MODEL_ID GLOSSARY_ID\n", __FILE__);
-}
-list($_, $inputUri, $outputUri, $projectId, $location, $targetLanguage, $sourceLanguage, $modelId, $glossaryId) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_batch_translate_text_with_glossary_and_model]
use Google\Cloud\Translate\V3\GcsDestination;
@@ -30,71 +25,87 @@
use Google\Cloud\Translate\V3\TranslateTextGlossaryConfig;
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $inputUri Path to to source input (e.g. "gs://cloud-samples-data/text.txt").
+ * @param string $outputUri Path to store results (e.g. "gs://YOUR_BUCKET_ID/results/").
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $location Project location (e.g. us-central1)
+ * @param string $targetLanguage Language to translate to.
+ * @param string $sourceLanguage Language of the source.
+ * @param string $modelId Your model ID.
+ * @param string $glossaryId Your glossary ID.
+ */
+function v3_batch_translate_text_with_glossary_and_model(
+ string $inputUri,
+ string $outputUri,
+ string $projectId,
+ string $location,
+ string $targetLanguage,
+ string $sourceLanguage,
+ string $modelId,
+ string $glossaryId
+): void {
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $inputUri = 'gs://cloud-samples-data/text.txt';
-// $outputUri = 'gs://YOUR_BUCKET_ID/path_to_store_results/';
-// $projectId = '[Google Cloud Project ID]';
-// $location = 'us-central1';
-// $targetLanguage = 'en';
-// $sourceLanguage = 'de';
-// $modelId = '{your-model-id}';
-// $glossaryId = '[YOUR_GLOSSARY_ID]';
-$glossaryPath = $translationServiceClient->glossaryName(
- $projectId,
- $location,
- $glossaryId
-);
-$modelPath = sprintf(
- 'projects/%s/locations/%s/models/%s',
- $projectId,
- $location,
- $modelId
-);
-$targetLanguageCodes = [$targetLanguage];
-$gcsSource = (new GcsSource())
- ->setInputUri($inputUri);
+ $glossaryPath = $translationServiceClient->glossaryName(
+ $projectId,
+ $location,
+ $glossaryId
+ );
+ $modelPath = sprintf(
+ 'projects/%s/locations/%s/models/%s',
+ $projectId,
+ $location,
+ $modelId
+ );
+ $targetLanguageCodes = [$targetLanguage];
+ $gcsSource = (new GcsSource())
+ ->setInputUri($inputUri);
-// Optional. Can be "text/plain" or "text/html".
-$mimeType = 'text/plain';
-$inputConfigsElement = (new InputConfig())
- ->setGcsSource($gcsSource)
- ->setMimeType($mimeType);
-$inputConfigs = [$inputConfigsElement];
-$gcsDestination = (new GcsDestination())
- ->setOutputUriPrefix($outputUri);
-$outputConfig = (new OutputConfig())
- ->setGcsDestination($gcsDestination);
-$formattedParent = $translationServiceClient->locationName($projectId, $location);
-$models = ['ja' => $modelPath];
-$glossariesItem = (new TranslateTextGlossaryConfig())
- ->setGlossary($glossaryPath);
-$glossaries = ['ja' => $glossariesItem];
+ // Optional. Can be "text/plain" or "text/html".
+ $mimeType = 'text/plain';
+ $inputConfigsElement = (new InputConfig())
+ ->setGcsSource($gcsSource)
+ ->setMimeType($mimeType);
+ $inputConfigs = [$inputConfigsElement];
+ $gcsDestination = (new GcsDestination())
+ ->setOutputUriPrefix($outputUri);
+ $outputConfig = (new OutputConfig())
+ ->setGcsDestination($gcsDestination);
+ $formattedParent = $translationServiceClient->locationName($projectId, $location);
+ $models = ['ja' => $modelPath];
+ $glossariesItem = (new TranslateTextGlossaryConfig())
+ ->setGlossary($glossaryPath);
+ $glossaries = ['ja' => $glossariesItem];
-try {
- $operationResponse = $translationServiceClient->batchTranslateText(
- $formattedParent,
- $sourceLanguage,
- $targetLanguageCodes,
- $inputConfigs,
- $outputConfig,
- [
- 'models' => $models,
- 'glossaries' => $glossaries
- ]
- );
- $operationResponse->pollUntilComplete();
- if ($operationResponse->operationSucceeded()) {
- $response = $operationResponse->getResult();
- // Display the translation for each input text provided
- printf('Total Characters: %s' . PHP_EOL, $response->getTotalCharacters());
- printf('Translated Characters: %s' . PHP_EOL, $response->getTranslatedCharacters());
- } else {
- $error = $operationResponse->getError();
- print($error->getMessage());
+ try {
+ $operationResponse = $translationServiceClient->batchTranslateText(
+ $formattedParent,
+ $sourceLanguage,
+ $targetLanguageCodes,
+ $inputConfigs,
+ $outputConfig,
+ [
+ 'models' => $models,
+ 'glossaries' => $glossaries
+ ]
+ );
+ $operationResponse->pollUntilComplete();
+ if ($operationResponse->operationSucceeded()) {
+ $response = $operationResponse->getResult();
+ // Display the translation for each input text provided
+ printf('Total Characters: %s' . PHP_EOL, $response->getTotalCharacters());
+ printf('Translated Characters: %s' . PHP_EOL, $response->getTranslatedCharacters());
+ } else {
+ $error = $operationResponse->getError();
+ print($error->getMessage());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_batch_translate_text_with_glossary_and_model]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_batch_translate_text_with_model.php b/translate/src/v3_batch_translate_text_with_model.php
index fc8e78e33a..0512c66487 100644
--- a/translate/src/v3_batch_translate_text_with_model.php
+++ b/translate/src/v3_batch_translate_text_with_model.php
@@ -15,12 +15,7 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 8 || count($argv) > 8) {
- return printf("Usage: php %s INPUT_URI OUTPUT_URI PROJECT_ID LOCATION TARGET_LANGUAGE SOURCE_LANGUAGE MODEL_ID \n", __FILE__);
-}
-list($_, $inputUri, $outputUri, $projectId, $location, $targetLanguage, $sourceLanguage, $modelId) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_batch_translate_text_with_model]
use Google\Cloud\Translate\V3\GcsDestination;
@@ -29,59 +24,74 @@
use Google\Cloud\Translate\V3\OutputConfig;
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $inputUri Path to to source input (e.g. "gs://cloud-samples-data/text.txt").
+ * @param string $outputUri Path to store results (e.g. "gs://YOUR_BUCKET_ID/results/").
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $location Project location (e.g. us-central1)
+ * @param string $targetLanguage Language to translate to.
+ * @param string $sourceLanguage Language of the source.
+ * @param string $modelId Your model ID.
+ */
+function v3_batch_translate_text_with_model(
+ string $inputUri,
+ string $outputUri,
+ string $projectId,
+ string $location,
+ string $targetLanguage,
+ string $sourceLanguage,
+ string $modelId
+): void {
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $inputUri = 'gs://cloud-samples-data/text.txt';
-// $outputUri = 'gs://YOUR_BUCKET_ID/path_to_store_results/';
-// $projectId = '[Google Cloud Project ID]';
-// $location = 'us-central1';
-// $targetLanguage = 'en';
-// $sourceLanguage = 'de';
-// $modelId = '{your-model-id}';
-$modelPath = sprintf(
- 'projects/%s/locations/%s/models/%s',
- $projectId,
- $location,
- $modelId
-);
-$targetLanguageCodes = [$targetLanguage];
-$gcsSource = (new GcsSource())
- ->setInputUri($inputUri);
+ $modelPath = sprintf(
+ 'projects/%s/locations/%s/models/%s',
+ $projectId,
+ $location,
+ $modelId
+ );
+ $targetLanguageCodes = [$targetLanguage];
+ $gcsSource = (new GcsSource())
+ ->setInputUri($inputUri);
-// Optional. Can be "text/plain" or "text/html".
-$mimeType = 'text/plain';
-$inputConfigsElement = (new InputConfig())
- ->setGcsSource($gcsSource)
- ->setMimeType($mimeType);
-$inputConfigs = [$inputConfigsElement];
-$gcsDestination = (new GcsDestination())
- ->setOutputUriPrefix($outputUri);
-$outputConfig = (new OutputConfig())
- ->setGcsDestination($gcsDestination);
-$formattedParent = $translationServiceClient->locationName($projectId, $location);
-$models = ['ja' => $modelPath];
+ // Optional. Can be "text/plain" or "text/html".
+ $mimeType = 'text/plain';
+ $inputConfigsElement = (new InputConfig())
+ ->setGcsSource($gcsSource)
+ ->setMimeType($mimeType);
+ $inputConfigs = [$inputConfigsElement];
+ $gcsDestination = (new GcsDestination())
+ ->setOutputUriPrefix($outputUri);
+ $outputConfig = (new OutputConfig())
+ ->setGcsDestination($gcsDestination);
+ $formattedParent = $translationServiceClient->locationName($projectId, $location);
+ $models = ['ja' => $modelPath];
-try {
- $operationResponse = $translationServiceClient->batchTranslateText(
- $formattedParent,
- $sourceLanguage,
- $targetLanguageCodes,
- $inputConfigs,
- $outputConfig,
- ['models' => $models]
- );
- $operationResponse->pollUntilComplete();
- if ($operationResponse->operationSucceeded()) {
- $response = $operationResponse->getResult();
- // Display the translation for each input text provided
- printf('Total Characters: %s' . PHP_EOL, $response->getTotalCharacters());
- printf('Translated Characters: %s' . PHP_EOL, $response->getTranslatedCharacters());
- } else {
- $error = $operationResponse->getError();
- print($error->getMessage());
+ try {
+ $operationResponse = $translationServiceClient->batchTranslateText(
+ $formattedParent,
+ $sourceLanguage,
+ $targetLanguageCodes,
+ $inputConfigs,
+ $outputConfig,
+ ['models' => $models]
+ );
+ $operationResponse->pollUntilComplete();
+ if ($operationResponse->operationSucceeded()) {
+ $response = $operationResponse->getResult();
+ // Display the translation for each input text provided
+ printf('Total Characters: %s' . PHP_EOL, $response->getTotalCharacters());
+ printf('Translated Characters: %s' . PHP_EOL, $response->getTranslatedCharacters());
+ } else {
+ $error = $operationResponse->getError();
+ print($error->getMessage());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_batch_translate_text_with_model]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_create_glossary.php b/translate/src/v3_create_glossary.php
index b9421584d1..47c542e781 100644
--- a/translate/src/v3_create_glossary.php
+++ b/translate/src/v3_create_glossary.php
@@ -15,12 +15,7 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 4 || count($argv) > 4) {
- return printf("Usage: php %s PROJECT_ID GLOSSARY_ID INPUT_URI\n", __FILE__);
-}
-list($_, $projectId, $glossaryId, $inputUri) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_create_glossary]
use Google\Cloud\Translate\V3\GcsSource;
@@ -29,57 +24,68 @@
use Google\Cloud\Translate\V3\Glossary\LanguageCodesSet;
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
-
-/** Uncomment and populate these variables in your code */
-// $projectId = '[Google Cloud Project ID]';
-// $glossaryId = 'my_glossary_id_123';
-// $inputUri = 'gs://cloud-samples-data/translation/glossary.csv';
-$formattedParent = $translationServiceClient->locationName(
- $projectId,
- 'us-central1'
-);
-$formattedName = $translationServiceClient->glossaryName(
- $projectId,
- 'us-central1',
- $glossaryId
-);
-$languageCodesElement = 'en';
-$languageCodesElement2 = 'ja';
-$languageCodes = [$languageCodesElement, $languageCodesElement2];
-$languageCodesSet = new LanguageCodesSet();
-$languageCodesSet->setLanguageCodes($languageCodes);
-$gcsSource = (new GcsSource())
- ->setInputUri($inputUri);
-$inputConfig = (new GlossaryInputConfig())
- ->setGcsSource($gcsSource);
-$glossary = (new Glossary())
- ->setName($formattedName)
- ->setLanguageCodesSet($languageCodesSet)
- ->setInputConfig($inputConfig);
+/**
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $glossaryId Your glossary ID.
+ * @param string $inputUri Path to to source input (e.g. "gs://cloud-samples-data/translation/glossary.csv").
+ */
+function v3_create_glossary(
+ string $projectId,
+ string $glossaryId,
+ string $inputUri
+): void {
+ $translationServiceClient = new TranslationServiceClient();
-try {
- $operationResponse = $translationServiceClient->createGlossary(
- $formattedParent,
- $glossary
+ $formattedParent = $translationServiceClient->locationName(
+ $projectId,
+ 'us-central1'
);
- $operationResponse->pollUntilComplete();
- if ($operationResponse->operationSucceeded()) {
- $response = $operationResponse->getResult();
- printf('Created Glossary.' . PHP_EOL);
- printf('Glossary name: %s' . PHP_EOL, $response->getName());
- printf('Entry count: %s' . PHP_EOL, $response->getEntryCount());
- printf(
- 'Input URI: %s' . PHP_EOL,
- $response->getInputConfig()
- ->getGcsSource()
- ->getInputUri()
+ $formattedName = $translationServiceClient->glossaryName(
+ $projectId,
+ 'us-central1',
+ $glossaryId
+ );
+ $languageCodesElement = 'en';
+ $languageCodesElement2 = 'ja';
+ $languageCodes = [$languageCodesElement, $languageCodesElement2];
+ $languageCodesSet = new LanguageCodesSet();
+ $languageCodesSet->setLanguageCodes($languageCodes);
+ $gcsSource = (new GcsSource())
+ ->setInputUri($inputUri);
+ $inputConfig = (new GlossaryInputConfig())
+ ->setGcsSource($gcsSource);
+ $glossary = (new Glossary())
+ ->setName($formattedName)
+ ->setLanguageCodesSet($languageCodesSet)
+ ->setInputConfig($inputConfig);
+
+ try {
+ $operationResponse = $translationServiceClient->createGlossary(
+ $formattedParent,
+ $glossary
);
- } else {
- $error = $operationResponse->getError();
- // handleError($error)
+ $operationResponse->pollUntilComplete();
+ if ($operationResponse->operationSucceeded()) {
+ $response = $operationResponse->getResult();
+ printf('Created Glossary.' . PHP_EOL);
+ printf('Glossary name: %s' . PHP_EOL, $response->getName());
+ printf('Entry count: %s' . PHP_EOL, $response->getEntryCount());
+ printf(
+ 'Input URI: %s' . PHP_EOL,
+ $response->getInputConfig()
+ ->getGcsSource()
+ ->getInputUri()
+ );
+ } else {
+ $error = $operationResponse->getError();
+ // handleError($error)
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_create_glossary]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_delete_glossary.php b/translate/src/v3_delete_glossary.php
index 591a30b51a..c64e8e2ab0 100644
--- a/translate/src/v3_delete_glossary.php
+++ b/translate/src/v3_delete_glossary.php
@@ -15,38 +15,41 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 3 || count($argv) > 3) {
- return printf("Usage: php %s PROJECT_ID GLOSSARY_ID\n", __FILE__);
-}
-list($_, $projectId, $glossaryId) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_delete_glossary]
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $glossaryId Your glossary ID.
+ */
+function v3_delete_glossary(string $projectId, string $glossaryId): void
+{
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $projectId = '[Google Cloud Project ID]';
-// $glossaryId = '[Glossary ID]';
-$formattedName = $translationServiceClient->glossaryName(
- $projectId,
- 'us-central1',
- $glossaryId
-);
+ $formattedName = $translationServiceClient->glossaryName(
+ $projectId,
+ 'us-central1',
+ $glossaryId
+ );
-try {
- $operationResponse = $translationServiceClient->deleteGlossary($formattedName);
- $operationResponse->pollUntilComplete();
- if ($operationResponse->operationSucceeded()) {
- $response = $operationResponse->getResult();
- printf('Deleted Glossary.' . PHP_EOL);
- } else {
- $error = $operationResponse->getError();
- // handleError($error)
+ try {
+ $operationResponse = $translationServiceClient->deleteGlossary($formattedName);
+ $operationResponse->pollUntilComplete();
+ if ($operationResponse->operationSucceeded()) {
+ $response = $operationResponse->getResult();
+ printf('Deleted Glossary.' . PHP_EOL);
+ } else {
+ $error = $operationResponse->getError();
+ // handleError($error)
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_delete_glossary]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_detect_language.php b/translate/src/v3_detect_language.php
index 7c318af7d6..13cbdddfa7 100644
--- a/translate/src/v3_detect_language.php
+++ b/translate/src/v3_detect_language.php
@@ -15,43 +15,49 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 3 || count($argv) > 3) {
- return printf("Usage: php %s TEXT PROJECT_ID\n", __FILE__);
-}
-list($_, $text, $projectId) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_detect_language]
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $text The text whose language to detect. This will be detected as en.
+ * @param string $projectId Your Google Cloud project ID.
+ */
+function v3_detect_language(string $text, string $projectId): void
+{
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $text = 'Hello, world!';
-// $projectId = '[Google Cloud Project ID]';
-$formattedParent = $translationServiceClient->locationName($projectId, 'global');
+ /** Uncomment and populate these variables in your code */
+ // $text = 'Hello, world!';
+ // $projectId = '[Google Cloud Project ID]';
+ $formattedParent = $translationServiceClient->locationName($projectId, 'global');
-// Optional. Can be "text/plain" or "text/html".
-$mimeType = 'text/plain';
+ // Optional. Can be "text/plain" or "text/html".
+ $mimeType = 'text/plain';
-try {
- $response = $translationServiceClient->detectLanguage(
- $formattedParent,
- [
- 'content' => $text,
- 'mimeType' => $mimeType
- ]
- );
- // Display list of detected languages sorted by detection confidence.
- // The most probable language is first.
- foreach ($response->getLanguages() as $language) {
- // The language detected
- printf('Language code: %s' . PHP_EOL, $language->getLanguageCode());
- // Confidence of detection result for this language
- printf('Confidence: %s' . PHP_EOL, $language->getConfidence());
+ try {
+ $response = $translationServiceClient->detectLanguage(
+ $formattedParent,
+ [
+ 'content' => $text,
+ 'mimeType' => $mimeType
+ ]
+ );
+ // Display list of detected languages sorted by detection confidence.
+ // The most probable language is first.
+ foreach ($response->getLanguages() as $language) {
+ // The language detected
+ printf('Language code: %s' . PHP_EOL, $language->getLanguageCode());
+ // Confidence of detection result for this language
+ printf('Confidence: %s' . PHP_EOL, $language->getConfidence());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_detect_language]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_get_glossary.php b/translate/src/v3_get_glossary.php
index 88e6fbb2b2..63a9b58de4 100644
--- a/translate/src/v3_get_glossary.php
+++ b/translate/src/v3_get_glossary.php
@@ -15,38 +15,41 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 3 || count($argv) > 3) {
- return printf("Usage: php %s PROJECT_ID GLOSSARY_ID\n", __FILE__);
-}
-list($_, $projectId, $glossaryId) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_get_glossary]
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
-
-/** Uncomment and populate these variables in your code */
-// $projectId = '[Google Cloud Project ID]';
-// $glossaryId = '[Glossary ID]';
-$formattedName = $translationServiceClient->glossaryName(
- $projectId,
- 'us-central1',
- $glossaryId
-);
+/**
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $glossaryId Your glossary ID.
+ */
+function v3_get_glossary(string $projectId, string $glossaryId): void
+{
+ $translationServiceClient = new TranslationServiceClient();
-try {
- $response = $translationServiceClient->getGlossary($formattedName);
- printf('Glossary name: %s' . PHP_EOL, $response->getName());
- printf('Entry count: %s' . PHP_EOL, $response->getEntryCount());
- printf(
- 'Input URI: %s' . PHP_EOL,
- $response->getInputConfig()
- ->getGcsSource()
- ->getInputUri()
+ $formattedName = $translationServiceClient->glossaryName(
+ $projectId,
+ 'us-central1',
+ $glossaryId
);
-} finally {
- $translationServiceClient->close();
+
+ try {
+ $response = $translationServiceClient->getGlossary($formattedName);
+ printf('Glossary name: %s' . PHP_EOL, $response->getName());
+ printf('Entry count: %s' . PHP_EOL, $response->getEntryCount());
+ printf(
+ 'Input URI: %s' . PHP_EOL,
+ $response->getInputConfig()
+ ->getGcsSource()
+ ->getInputUri()
+ );
+ } finally {
+ $translationServiceClient->close();
+ }
}
// [END translate_v3_get_glossary]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_get_supported_languages.php b/translate/src/v3_get_supported_languages.php
index 45629632c8..cc5ba28267 100644
--- a/translate/src/v3_get_supported_languages.php
+++ b/translate/src/v3_get_supported_languages.php
@@ -15,29 +15,32 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 2 || count($argv) > 2) {
- return printf("Usage: php %s PROJECT_ID\n", __FILE__);
-}
-list($_, $projectId) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_get_supported_languages]
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $projectId Your Google Cloud project ID.
+ */
+function v3_get_supported_languages(string $projectId): void
+{
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $projectId = '[Google Cloud Project ID]';
-$formattedParent = $translationServiceClient->locationName($projectId, 'global');
+ $formattedParent = $translationServiceClient->locationName($projectId, 'global');
-try {
- $response = $translationServiceClient->getSupportedLanguages($formattedParent);
- // List language codes of supported languages
- foreach ($response->getLanguages() as $language) {
- printf('Language Code: %s' . PHP_EOL, $language->getLanguageCode());
+ try {
+ $response = $translationServiceClient->getSupportedLanguages($formattedParent);
+ // List language codes of supported languages
+ foreach ($response->getLanguages() as $language) {
+ printf('Language Code: %s' . PHP_EOL, $language->getLanguageCode());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_get_supported_languages]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_get_supported_languages_for_target.php b/translate/src/v3_get_supported_languages_for_target.php
index 41498cffbe..c889d3f82a 100644
--- a/translate/src/v3_get_supported_languages_for_target.php
+++ b/translate/src/v3_get_supported_languages_for_target.php
@@ -15,34 +15,37 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 3 || count($argv) > 3) {
- return printf("Usage: php %s LANGUAGE_CODE PROJECT_ID\n", __FILE__);
-}
-list($_, $languageCode, $projectId) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_get_supported_languages_for_target]
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $languageCode Languages to list that are supported by this language code.
+ */
+function v3_get_supported_languages_for_target(string $languageCode, string $projectId): void
+{
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $languageCode = 'en';
-// $projectId = '[Google Cloud Project ID]';
-$formattedParent = $translationServiceClient->locationName($projectId, 'global');
+ $formattedParent = $translationServiceClient->locationName($projectId, 'global');
-try {
- $response = $translationServiceClient->getSupportedLanguages(
- $formattedParent,
- ['displayLanguageCode' => $languageCode]
- );
- // List language codes of supported languages
- foreach ($response->getLanguages() as $language) {
- printf('Language Code: %s' . PHP_EOL, $language->getLanguageCode());
- printf('Display Name: %s' . PHP_EOL, $language->getDisplayName());
+ try {
+ $response = $translationServiceClient->getSupportedLanguages(
+ $formattedParent,
+ ['displayLanguageCode' => $languageCode]
+ );
+ // List language codes of supported languages
+ foreach ($response->getLanguages() as $language) {
+ printf('Language Code: %s' . PHP_EOL, $language->getLanguageCode());
+ printf('Display Name: %s' . PHP_EOL, $language->getDisplayName());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_get_supported_languages_for_target]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_list_glossary.php b/translate/src/v3_list_glossary.php
index 1428b66fb6..3f7c232566 100644
--- a/translate/src/v3_list_glossary.php
+++ b/translate/src/v3_list_glossary.php
@@ -15,39 +15,42 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 2 || count($argv) > 2) {
- return printf("Usage: php %s PROJECT_ID \n", __FILE__);
-}
-list($_, $projectId) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_list_glossary]
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $projectId Your Google Cloud project ID.
+ */
+function v3_list_glossary(string $projectId): void
+{
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $projectId = '[Google Cloud Project ID]';
-$formattedParent = $translationServiceClient->locationName(
- $projectId,
- 'us-central1'
-);
+ $formattedParent = $translationServiceClient->locationName(
+ $projectId,
+ 'us-central1'
+ );
-try {
- // Iterate through all elements
- $pagedResponse = $translationServiceClient->listGlossaries($formattedParent);
- foreach ($pagedResponse->iterateAllElements() as $responseItem) {
- printf('Glossary name: %s' . PHP_EOL, $responseItem->getName());
- printf('Entry count: %s' . PHP_EOL, $responseItem->getEntryCount());
- printf(
- 'Input URI: %s' . PHP_EOL,
- $responseItem->getInputConfig()
- ->getGcsSource()
- ->getInputUri()
- );
+ try {
+ // Iterate through all elements
+ $pagedResponse = $translationServiceClient->listGlossaries($formattedParent);
+ foreach ($pagedResponse->iterateAllElements() as $responseItem) {
+ printf('Glossary name: %s' . PHP_EOL, $responseItem->getName());
+ printf('Entry count: %s' . PHP_EOL, $responseItem->getEntryCount());
+ printf(
+ 'Input URI: %s' . PHP_EOL,
+ $responseItem->getInputConfig()
+ ->getGcsSource()
+ ->getInputUri()
+ );
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_list_glossary]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_translate_text.php b/translate/src/v3_translate_text.php
index 00f7ee4ce1..0a610cd20f 100644
--- a/translate/src/v3_translate_text.php
+++ b/translate/src/v3_translate_text.php
@@ -15,37 +15,42 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 4 || count($argv) > 4) {
- return printf("Usage: php %s TEXT TARGET_LANGUAGE PROJECT_ID\n", __FILE__);
-}
-list($_, $text, $targetLanguage, $projectId) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_translate_text]
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $text The text to translate.
+ * @param string $targetLanguage Language to translate to.
+ * @param string $projectId Your Google Cloud project ID.
+ */
+function v3_translate_text(
+ string $text,
+ string $targetLanguage,
+ string $projectId
+): void {
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $text = 'Hello, world!';
-// $targetLanguage = 'fr';
-// $projectId = '[Google Cloud Project ID]';
-$contents = [$text];
-$formattedParent = $translationServiceClient->locationName($projectId, 'global');
+ $contents = [$text];
+ $formattedParent = $translationServiceClient->locationName($projectId, 'global');
-try {
- $response = $translationServiceClient->translateText(
- $contents,
- $targetLanguage,
- $formattedParent
- );
- // Display the translation for each input text provided
- foreach ($response->getTranslations() as $translation) {
- printf('Translated text: %s' . PHP_EOL, $translation->getTranslatedText());
+ try {
+ $response = $translationServiceClient->translateText(
+ $contents,
+ $targetLanguage,
+ $formattedParent
+ );
+ // Display the translation for each input text provided
+ foreach ($response->getTranslations() as $translation) {
+ printf('Translated text: %s' . PHP_EOL, $translation->getTranslatedText());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
-
// [END translate_v3_translate_text]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_translate_text_with_glossary.php b/translate/src/v3_translate_text_with_glossary.php
index be8f78a4b4..26c75e4be9 100644
--- a/translate/src/v3_translate_text_with_glossary.php
+++ b/translate/src/v3_translate_text_with_glossary.php
@@ -15,57 +15,65 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 6 || count($argv) > 6) {
- return printf("Usage: php %s TEXT SOURCE_LANGUAGE TARGET_LANGUAGE PROJECT_ID GLOSSARY_ID\n", __FILE__);
-}
-list($_, $text, $sourceLanguage, $targetLanguage, $projectId, $glossaryId) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_translate_text_with_glossary]
use Google\Cloud\Translate\V3\TranslateTextGlossaryConfig;
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $text The text to translate.
+ * @param string $targetLanguage Language to translate to.
+ * @param string $sourceLanguage Language of the source.
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $glossaryId Your glossary ID.
+ */
+function v3_translate_text_with_glossary(
+ string $text,
+ string $targetLanguage,
+ string $sourceLanguage,
+ string $projectId,
+ string $glossaryId
+): void {
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $text = 'Hello, world!';
-// $sourceLanguage = 'en';
-// $targetLanguage = 'fr';
-// $projectId = '[Google Cloud Project ID]';
-// $glossaryId = '[YOUR_GLOSSARY_ID]';
-$glossaryPath = $translationServiceClient->glossaryName(
- $projectId,
- 'us-central1',
- $glossaryId
-);
-$contents = [$text];
-$formattedParent = $translationServiceClient->locationName(
- $projectId,
- 'us-central1'
-);
-$glossaryConfig = new TranslateTextGlossaryConfig();
-$glossaryConfig->setGlossary($glossaryPath);
+ $glossaryPath = $translationServiceClient->glossaryName(
+ $projectId,
+ 'us-central1',
+ $glossaryId
+ );
+ $contents = [$text];
+ $formattedParent = $translationServiceClient->locationName(
+ $projectId,
+ 'us-central1'
+ );
+ $glossaryConfig = new TranslateTextGlossaryConfig();
+ $glossaryConfig->setGlossary($glossaryPath);
-// Optional. Can be "text/plain" or "text/html".
-$mimeType = 'text/plain';
+ // Optional. Can be "text/plain" or "text/html".
+ $mimeType = 'text/plain';
-try {
- $response = $translationServiceClient->translateText(
- $contents,
- $targetLanguage,
- $formattedParent,
- [
- 'sourceLanguageCode' => $sourceLanguage,
- 'glossaryConfig' => $glossaryConfig,
- 'mimeType' => $mimeType
- ]
- );
- // Display the translation for each input text provided
- foreach ($response->getGlossaryTranslations() as $translation) {
- printf('Translated text: %s' . PHP_EOL, $translation->getTranslatedText());
+ try {
+ $response = $translationServiceClient->translateText(
+ $contents,
+ $targetLanguage,
+ $formattedParent,
+ [
+ 'sourceLanguageCode' => $sourceLanguage,
+ 'glossaryConfig' => $glossaryConfig,
+ 'mimeType' => $mimeType
+ ]
+ );
+ // Display the translation for each input text provided
+ foreach ($response->getGlossaryTranslations() as $translation) {
+ printf('Translated text: %s' . PHP_EOL, $translation->getTranslatedText());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_translate_text_with_glossary]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_translate_text_with_glossary_and_model.php b/translate/src/v3_translate_text_with_glossary_and_model.php
index 7916a9afb5..8243c5b68a 100644
--- a/translate/src/v3_translate_text_with_glossary_and_model.php
+++ b/translate/src/v3_translate_text_with_glossary_and_model.php
@@ -15,66 +15,84 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 8 || count($argv) > 8) {
- return printf("Usage: php %s MODEL_ID GLOSSARY_ID TEXT TARGET_LANGUAGE SOURCE_LANGUAGE PROJECT_ID LOCATION\n", __FILE__);
-}
-list($_, $modelId, $glossaryId, $text, $targetLanguage, $sourceLanguage, $projectId, $location) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_translate_text_with_glossary_and_model]
use Google\Cloud\Translate\V3\TranslateTextGlossaryConfig;
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $modelId Your model ID.
+ * @param string $glossaryId Your glossary ID.
+ * @param string $text The text to translate.
+ * @param string $targetLanguage Language to translate to.
+ * @param string $sourceLanguage Language of the source.
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $location Project location (e.g. us-central1)
+ */
+function v3_translate_text_with_glossary_and_model(
+ string $modelId,
+ string $glossaryId,
+ string $text,
+ string $targetLanguage,
+ string $sourceLanguage,
+ string $projectId,
+ string $location
+): void {
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $modelId = '[MODEL ID]';
-// $glossaryId = '[YOUR_GLOSSARY_ID]';
-// $text = 'Hello, world!';
-// $targetLanguage = 'fr';
-// $sourceLanguage = 'en';
-// $projectId = '[Google Cloud Project ID]';
-// $location = 'global';
-$glossaryPath = $translationServiceClient->glossaryName(
- $projectId,
- $location,
- $glossaryId
-);
-$modelPath = sprintf(
- 'projects/%s/locations/%s/models/%s',
- $projectId,
- $location,
- $modelId
-);
-$contents = [$text];
-$glossaryConfig = new TranslateTextGlossaryConfig();
-$glossaryConfig->setGlossary($glossaryPath);
-$formattedParent = $translationServiceClient->locationName(
- $projectId,
- $location
-);
+ /** Uncomment and populate these variables in your code */
+ // $modelId = '[MODEL ID]';
+ // $glossaryId = '[YOUR_GLOSSARY_ID]';
+ // $text = 'Hello, world!';
+ // $targetLanguage = 'fr';
+ // $sourceLanguage = 'en';
+ // $projectId = '[Google Cloud Project ID]';
+ // $location = 'global';
+ $glossaryPath = $translationServiceClient->glossaryName(
+ $projectId,
+ $location,
+ $glossaryId
+ );
+ $modelPath = sprintf(
+ 'projects/%s/locations/%s/models/%s',
+ $projectId,
+ $location,
+ $modelId
+ );
+ $contents = [$text];
+ $glossaryConfig = new TranslateTextGlossaryConfig();
+ $glossaryConfig->setGlossary($glossaryPath);
+ $formattedParent = $translationServiceClient->locationName(
+ $projectId,
+ $location
+ );
-// Optional. Can be "text/plain" or "text/html".
-$mimeType = 'text/plain';
+ // Optional. Can be "text/plain" or "text/html".
+ $mimeType = 'text/plain';
-try {
- $response = $translationServiceClient->translateText(
- $contents,
- $targetLanguage,
- $formattedParent,
- [
- 'model' => $modelPath,
- 'glossaryConfig' => $glossaryConfig,
- 'sourceLanguageCode' => $sourceLanguage,
- 'mimeType' => $mimeType
- ]
- );
- // Display the translation for each input text provided
- foreach ($response->getGlossaryTranslations() as $translation) {
- printf('Translated text: %s' . PHP_EOL, $translation->getTranslatedText());
+ try {
+ $response = $translationServiceClient->translateText(
+ $contents,
+ $targetLanguage,
+ $formattedParent,
+ [
+ 'model' => $modelPath,
+ 'glossaryConfig' => $glossaryConfig,
+ 'sourceLanguageCode' => $sourceLanguage,
+ 'mimeType' => $mimeType
+ ]
+ );
+ // Display the translation for each input text provided
+ foreach ($response->getGlossaryTranslations() as $translation) {
+ printf('Translated text: %s' . PHP_EOL, $translation->getTranslatedText());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_translate_text_with_glossary_and_model]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/src/v3_translate_text_with_model.php b/translate/src/v3_translate_text_with_model.php
index c18aab2396..ee0642f877 100644
--- a/translate/src/v3_translate_text_with_model.php
+++ b/translate/src/v3_translate_text_with_model.php
@@ -15,56 +15,65 @@
* limitations under the License.
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (count($argv) < 7 || count($argv) > 7) {
- return printf("Usage: php %s MODEL_ID TEXT TARGET_LANGUAGE SOURCE_LANGUAGE PROJECT_ID LOCATION\n", __FILE__);
-}
-list($_, $modelId, $text, $targetLanguage, $sourceLanguage, $projectId, $location) = $argv;
+namespace Google\Cloud\Samples\Translate;
// [START translate_v3_translate_text_with_model]
use Google\Cloud\Translate\V3\TranslationServiceClient;
-$translationServiceClient = new TranslationServiceClient();
+/**
+ * @param string $modelId Your model ID.
+ * @param string $text The text to translate.
+ * @param string $targetLanguage Language to translate to.
+ * @param string $sourceLanguage Language of the source.
+ * @param string $projectId Your Google Cloud project ID.
+ * @param string $location Project location (e.g. us-central1)
+ */
+function v3_translate_text_with_model(
+ string $modelId,
+ string $text,
+ string $targetLanguage,
+ string $sourceLanguage,
+ string $projectId,
+ string $location
+): void {
+ $translationServiceClient = new TranslationServiceClient();
-/** Uncomment and populate these variables in your code */
-// $modelId = '[MODEL ID]';
-// $text = 'Hello, world!';
-// $targetLanguage = 'fr';
-// $sourceLanguage = 'en';
-// $projectId = '[Google Cloud Project ID]';
-// $location = 'global';
-$modelPath = sprintf(
- 'projects/%s/locations/%s/models/%s',
- $projectId,
- $location,
- $modelId
-);
-$contents = [$text];
-$formattedParent = $translationServiceClient->locationName(
- $projectId,
- $location
-);
+ $modelPath = sprintf(
+ 'projects/%s/locations/%s/models/%s',
+ $projectId,
+ $location,
+ $modelId
+ );
+ $contents = [$text];
+ $formattedParent = $translationServiceClient->locationName(
+ $projectId,
+ $location
+ );
-// Optional. Can be "text/plain" or "text/html".
-$mimeType = 'text/plain';
+ // Optional. Can be "text/plain" or "text/html".
+ $mimeType = 'text/plain';
-try {
- $response = $translationServiceClient->translateText(
- $contents,
- $targetLanguage,
- $formattedParent,
- [
- 'model' => $modelPath,
- 'sourceLanguageCode' => $sourceLanguage,
- 'mimeType' => $mimeType
- ]
- );
- // Display the translation for each input text provided
- foreach ($response->getTranslations() as $translation) {
- printf('Translated text: %s' . PHP_EOL, $translation->getTranslatedText());
+ try {
+ $response = $translationServiceClient->translateText(
+ $contents,
+ $targetLanguage,
+ $formattedParent,
+ [
+ 'model' => $modelPath,
+ 'sourceLanguageCode' => $sourceLanguage,
+ 'mimeType' => $mimeType
+ ]
+ );
+ // Display the translation for each input text provided
+ foreach ($response->getTranslations() as $translation) {
+ printf('Translated text: %s' . PHP_EOL, $translation->getTranslatedText());
+ }
+ } finally {
+ $translationServiceClient->close();
}
-} finally {
- $translationServiceClient->close();
}
// [END translate_v3_translate_text_with_model]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/translate/test/translateTest.php b/translate/test/translateTest.php
index dbe268d4c9..414d7e5db6 100644
--- a/translate/test/translateTest.php
+++ b/translate/test/translateTest.php
@@ -49,7 +49,7 @@ public static function tearDownAfterClass(): void
public function testTranslate()
{
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'translate',
['Hello.', 'ja']
);
@@ -61,12 +61,12 @@ public function testTranslateBadLanguage()
{
$this->expectException('Google\Cloud\Core\Exception\BadRequestException');
- $this->runSnippet('translate', ['Hello.', 'jp']);
+ $this->runFunctionSnippet('translate', ['Hello.', 'jp']);
}
public function testTranslateWithModel()
{
- $output = $this->runSnippet('translate_with_model', ['Hello.', 'ja']);
+ $output = $this->runFunctionSnippet('translate_with_model', ['Hello.', 'ja']);
$this->assertStringContainsString('Source language: en', $output);
$this->assertStringContainsString('Translation:', $output);
$this->assertStringContainsString('Model: nmt', $output);
@@ -74,33 +74,33 @@ public function testTranslateWithModel()
public function testDetectLanguage()
{
- $output = $this->runSnippet('detect_language', ['Hello.']);
+ $output = $this->runFunctionSnippet('detect_language', ['Hello.']);
$this->assertStringContainsString('Language code: en', $output);
$this->assertStringContainsString('Confidence:', $output);
}
public function testListCodes()
{
- $output = $this->runSnippet('list_codes');
+ $output = $this->runFunctionSnippet('list_codes');
$this->assertStringContainsString("\nen\n", $output);
$this->assertStringContainsString("\nja\n", $output);
}
public function testListLanguagesInEnglish()
{
- $output = $this->runSnippet('list_languages', ['en']);
+ $output = $this->runFunctionSnippet('list_languages', ['en']);
$this->assertStringContainsString('ja: Japanese', $output);
}
public function testListLanguagesInJapanese()
{
- $output = $this->runSnippet('list_languages', ['ja']);
+ $output = $this->runFunctionSnippet('list_languages', ['ja']);
$this->assertStringContainsString('en: 英語', $output);
}
public function testV3TranslateText()
{
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_translate_text',
[
'Hello world',
@@ -111,11 +111,13 @@ public function testV3TranslateText()
$option1 = 'Zdravo svet';
$option2 = 'Pozdrav svijetu';
$option3 = 'Zdravo svijete';
+ $option4 = 'Здраво Свете';
$this->assertThat($output,
$this->logicalOr(
$this->stringContains($option1),
$this->stringContains($option2),
- $this->stringContains($option3)
+ $this->stringContains($option3),
+ $this->stringContains($option4),
)
);
}
@@ -123,7 +125,7 @@ public function testV3TranslateText()
public function testV3TranslateTextWithGlossaryAndModel()
{
$glossaryId = sprintf('please-delete-me-%d', rand());
- $this->runSnippet(
+ $this->runFunctionSnippet(
'v3_create_glossary',
[
self::$projectId,
@@ -131,7 +133,7 @@ public function testV3TranslateTextWithGlossaryAndModel()
'gs://cloud-samples-data/translation/glossary_ja.csv'
]
);
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_translate_text_with_glossary_and_model',
[
'TRL3089491334608715776',
@@ -145,7 +147,7 @@ public function testV3TranslateTextWithGlossaryAndModel()
);
$this->assertStringContainsString('欺く', $output);
$this->assertStringContainsString('やる', $output);
- $this->runSnippet(
+ $this->runFunctionSnippet(
'v3_delete_glossary',
[
self::$projectId,
@@ -157,7 +159,7 @@ public function testV3TranslateTextWithGlossaryAndModel()
public function testV3TranslateTextWithGlossary()
{
$glossaryId = sprintf('please-delete-me-%d', rand());
- $this->runSnippet(
+ $this->runFunctionSnippet(
'v3_create_glossary',
[
self::$projectId,
@@ -165,12 +167,12 @@ public function testV3TranslateTextWithGlossary()
'gs://cloud-samples-data/translation/glossary_ja.csv'
]
);
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_translate_text_with_glossary',
[
'account',
- 'en',
'ja',
+ 'en',
self::$projectId,
$glossaryId
]
@@ -183,7 +185,7 @@ public function testV3TranslateTextWithGlossary()
$this->stringContains($option2)
)
);
- $this->runSnippet(
+ $this->runFunctionSnippet(
'v3_delete_glossary',
[
self::$projectId,
@@ -194,7 +196,7 @@ public function testV3TranslateTextWithGlossary()
public function testV3TranslateTextWithModel()
{
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_translate_text_with_model',
[
'TRL3089491334608715776',
@@ -211,7 +213,7 @@ public function testV3TranslateTextWithModel()
public function testV3CreateListGetDeleteGlossary()
{
$glossaryId = sprintf('please-delete-me-%d', rand());
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_create_glossary',
[
self::$projectId,
@@ -225,7 +227,7 @@ public function testV3CreateListGetDeleteGlossary()
'gs://cloud-samples-data/translation/glossary_ja.csv',
$output
);
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_list_glossary',
[self::$projectId]
);
@@ -234,7 +236,7 @@ public function testV3CreateListGetDeleteGlossary()
'gs://cloud-samples-data/translation/glossary_ja.csv',
$output
);
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_get_glossary',
[
self::$projectId,
@@ -246,7 +248,7 @@ public function testV3CreateListGetDeleteGlossary()
'gs://cloud-samples-data/translation/glossary_ja.csv',
$output
);
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_delete_glossary',
[
self::$projectId,
@@ -258,7 +260,7 @@ public function testV3CreateListGetDeleteGlossary()
public function testV3ListLanguagesWithTarget()
{
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_get_supported_languages_for_target',
[
'is',
@@ -271,16 +273,16 @@ public function testV3ListLanguagesWithTarget()
public function testV3ListLanguages()
{
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_get_supported_languages',
[self::$projectId]
);
- $this->assertStringContainsString('zh-CN', $output);
+ $this->assertStringContainsString('zh', $output);
}
public function testV3DetectLanguage()
{
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_detect_language',
[
'Hæ sæta',
@@ -297,15 +299,15 @@ public function testV3BatchTranslateText()
self::$bucket->name(),
rand()
);
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_batch_translate_text',
[
'gs://cloud-samples-data/translation/text.txt',
$outputUri,
self::$projectId,
'us-central1',
- 'en',
- 'es'
+ 'es',
+ 'en'
]
);
$this->assertStringContainsString('Total Characters: 13', $output);
@@ -319,7 +321,7 @@ public function testV3BatchTranslateTextWithGlossaryAndModel()
rand()
);
$glossaryId = sprintf('please-delete-me-%d', rand());
- $this->runSnippet(
+ $this->runFunctionSnippet(
'v3_create_glossary',
[
self::$projectId,
@@ -327,7 +329,7 @@ public function testV3BatchTranslateTextWithGlossaryAndModel()
'gs://cloud-samples-data/translation/glossary_ja.csv'
]
);
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_batch_translate_text_with_glossary_and_model',
[
'gs://cloud-samples-data/translation/text_with_custom_model_and_glossary.txt',
@@ -340,7 +342,7 @@ public function testV3BatchTranslateTextWithGlossaryAndModel()
$glossaryId
]
);
- $this->runSnippet(
+ $this->runFunctionSnippet(
'v3_delete_glossary',
[
self::$projectId,
@@ -358,7 +360,7 @@ public function testV3BatchTranslateTextWithGlossary()
rand()
);
$glossaryId = sprintf('please-delete-me-%d', rand());
- $this->runSnippet(
+ $this->runFunctionSnippet(
'v3_create_glossary',
[
self::$projectId,
@@ -366,7 +368,7 @@ public function testV3BatchTranslateTextWithGlossary()
'gs://cloud-samples-data/translation/glossary_ja.csv'
]
);
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_batch_translate_text_with_glossary',
[
'gs://cloud-samples-data/translation/text_with_glossary.txt',
@@ -375,10 +377,10 @@ public function testV3BatchTranslateTextWithGlossary()
'us-central1',
$glossaryId,
'ja',
- 'en'
+ 'en',
]
);
- $this->runSnippet(
+ $this->runFunctionSnippet(
'v3_delete_glossary',
[
self::$projectId,
@@ -395,7 +397,7 @@ public function testV3BatchTranslateTextWithModel()
self::$bucket->name(),
rand()
);
- $output = $this->runSnippet(
+ $output = $this->runFunctionSnippet(
'v3_batch_translate_text_with_model',
[
'gs://cloud-samples-data/translation/custom_model_text.txt',
diff --git a/video/src/analyze_explicit_content.php b/video/src/analyze_explicit_content.php
index 1378453c58..4612798b65 100644
--- a/video/src/analyze_explicit_content.php
+++ b/video/src/analyze_explicit_content.php
@@ -19,7 +19,7 @@
/**
* For instructions on how to run the full sample:
*
- * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/video/README.md
+ * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/video/README.md
*/
namespace Google\Cloud\Samples\VideoIntelligence;
diff --git a/vision/README.md b/vision/README.md
index a85d8e6547..3722577feb 100644
--- a/vision/README.md
+++ b/vision/README.md
@@ -28,52 +28,15 @@ This simple command-line application demonstrates how to invoke
Run `php composer.phar install` (if composer is installed locally) or `composer install`
(if composer is installed globally).
5. For a basic demonstration of the Cloud Vision API, run `php quickstart.php`.
-6. Run `php vision.php` or `php product_search.php`. For `vision.php`, the following commands are available:
-```
- face Detect faces in an image using Google Cloud Vision API
- help Displays help for a command
- label Detect labels in an image using Google Cloud Vision API
- landmark Detect landmarks in an image using Google Cloud Vision API
- list Lists commands
- localize-object Detect objects in an image using Google Cloud Vision API
- logo Detect logos in an image using Google Cloud Vision API
- property Detect image properties in an image using Google Cloud Vision API
- safe-search Detect adult content in an image using Google Cloud Vision API
- text Detect text in an image using Google Cloud Vision API
- crop-hints Detect crop hints in an image using Google Cloud Vision API
- document-text Detect document text in an image using Google Cloud Vision API
- pdf Detect text in a PDF/TIFF using Google Cloud Vision API
- web Detect web entities in an image using Google Cloud Vision API
- web-geo Detect web entities in an image with geo metadata using
- Google Cloud Vision API
-```
- For `product_search.php`, the following commands are available:
-```
- product-create Create a product
- product-delete Delete a product
- product-get Get information of a product
- product-list List information for all products
- product-update Update information for a product
- product-image-create Create reference image
- product-image-delete Delete reference image
- product-image-get Get reference image information for a product
- product-image-list List all reference image information for a product
- product-search-similar Search for similar products to local image
- product-search-similar-gcs Search for similar products to GCS image
- product-set-create Create a product set
- product-set-delete Delete a product set
- product-set-get Get information for a product set
- product-set-import Import a product set
- product-set-list List information for all product sets
- product-set-add-product Add product to a product set
- product-set-list-products List products in a product set
- product-set-remove-product Remove product from a product set
- product-purge-orphan Delete all products not in any product sets
- product-purge-products-in-product-set Delete all products not in any product set
-```
-
-7. Run `php vision.php COMMAND --help` or `php product_search.php COMMAND --help` to print information about the usage of each command.
-
+6. Execute the snippets in the [src/](src/) directory by running
+ `php src/SNIPPET_NAME.php`. The usage will print for each if no arguments
+ are provided:
+ ```sh
+ $ php src/detext_face.php
+ Usage: php src/detext_face.php
+
+ $ php src/detect_face.php 'path/to/your/image.jpg'
+ ```
## The client library
This sample uses the [Google Cloud Client Library for PHP][google-cloud-php].
diff --git a/vision/composer.json b/vision/composer.json
index 2da0fc27c9..5d79fa2baf 100644
--- a/vision/composer.json
+++ b/vision/composer.json
@@ -3,37 +3,6 @@
"type": "project",
"require": {
"google/cloud-vision": "^1.0.0",
- "google/cloud-storage": "^1.20.1",
- "symfony/console": "^5.0"
- },
- "autoload": {
- "psr-4": {
- "Google\\Cloud\\Samples\\Vision\\": "src/"
- },
- "files": [
- "src/detect_label.php",
- "src/detect_label_gcs.php",
- "src/detect_text.php",
- "src/detect_text_gcs.php",
- "src/detect_face.php",
- "src/detect_face_gcs.php",
- "src/detect_landmark.php",
- "src/detect_landmark_gcs.php",
- "src/detect_logo.php",
- "src/detect_logo_gcs.php",
- "src/detect_safe_search.php",
- "src/detect_safe_search_gcs.php",
- "src/detect_image_property.php",
- "src/detect_image_property_gcs.php",
- "src/detect_document_text.php",
- "src/detect_document_text_gcs.php",
- "src/detect_web.php",
- "src/detect_web_gcs.php",
- "src/detect_object.php",
- "src/detect_object_gcs.php",
- "src/detect_web_with_geo_metadata.php",
- "src/detect_web_with_geo_metadata_gcs.php",
- "src/detect_pdf_gcs.php"
- ]
+ "google/cloud-storage": "^1.20.1"
}
}
diff --git a/vision/src/detect_document_text.php b/vision/src/detect_document_text.php
index 5049f46609..e6f9e51c14 100644
--- a/vision/src/detect_document_text.php
+++ b/vision/src/detect_document_text.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'path/to/your/image.jpg'
-
-function detect_document_text($path)
+/**
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
+ */
+function detect_document_text(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -67,3 +68,7 @@ function detect_document_text($path)
$imageAnnotator->close();
}
// [END vision_fulltext_detection]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_document_text_gcs.php b/vision/src/detect_document_text_gcs.php
index 5a2d106ef4..6406819f87 100644
--- a/vision/src/detect_document_text_gcs.php
+++ b/vision/src/detect_document_text_gcs.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'gs://path/to/your/image.jpg'
-
-function detect_document_text_gcs($path)
+/**
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
+ */
+function detect_document_text_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -67,3 +68,7 @@ function detect_document_text_gcs($path)
$imageAnnotator->close();
}
// [END vision_fulltext_detection_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_face.php b/vision/src/detect_face.php
index 46efa4e48b..cec248b4e4 100644
--- a/vision/src/detect_face.php
+++ b/vision/src/detect_face.php
@@ -21,8 +21,12 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
// [END vision_face_detection_tutorial_imports]
-
-function detect_face($path, $outFile = null)
+/**
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
+ * @param string $outFile Saves a copy of the image supplied in $path with a
+ * rectangle drawn around the detected faces.
+ */
+function detect_face(string $path, string $outFile = null)
{
// [START vision_face_detection_tutorial_client]
$imageAnnotator = new ImageAnnotatorClient();
@@ -108,3 +112,7 @@ function detect_face($path, $outFile = null)
// [START vision_face_detection]
}
// [END vision_face_detection]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_face_gcs.php b/vision/src/detect_face_gcs.php
index 57ed042af8..0dfde0d3d6 100644
--- a/vision/src/detect_face_gcs.php
+++ b/vision/src/detect_face_gcs.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'gs://path/to/your/image.jpg'
-
-function detect_face_gcs($path)
+/**
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
+ */
+function detect_face_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -58,3 +59,7 @@ function detect_face_gcs($path)
$imageAnnotator->close();
}
// [END vision_face_detection_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_image_property.php b/vision/src/detect_image_property.php
index e6132d12b1..d21f9dd0cc 100644
--- a/vision/src/detect_image_property.php
+++ b/vision/src/detect_image_property.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'path/to/your/image.jpg'
-
-function detect_image_property($path)
+/**
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
+ */
+function detect_image_property(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -44,3 +45,7 @@ function detect_image_property($path)
$imageAnnotator->close();
}
// [END vision_image_property_detection]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_image_property_gcs.php b/vision/src/detect_image_property_gcs.php
index 03fae62ad3..9f67ae1ace 100644
--- a/vision/src/detect_image_property_gcs.php
+++ b/vision/src/detect_image_property_gcs.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'gs://path/to/your/image.jpg'
-
-function detect_image_property_gcs($path)
+/**
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
+ */
+function detect_image_property_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -47,3 +48,7 @@ function detect_image_property_gcs($path)
$imageAnnotator->close();
}
// [END vision_image_property_detection_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_label.php b/vision/src/detect_label.php
index 910a2bd8af..678145e2b1 100644
--- a/vision/src/detect_label.php
+++ b/vision/src/detect_label.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'path/to/your/image.jpg'
-
-function detect_label($path)
+/**
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
+ */
+function detect_label(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -43,3 +44,7 @@ function detect_label($path)
$imageAnnotator->close();
}
// [END vision_label_detection]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_label_gcs.php b/vision/src/detect_label_gcs.php
index cb752daef1..ca8d5744bb 100644
--- a/vision/src/detect_label_gcs.php
+++ b/vision/src/detect_label_gcs.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'gs://path/to/your/image.jpg'
-
-function detect_label_gcs($path)
+/**
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
+ */
+function detect_label_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -42,3 +43,7 @@ function detect_label_gcs($path)
$imageAnnotator->close();
}
// [END vision_label_detection_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_landmark.php b/vision/src/detect_landmark.php
index c8e1bdd517..66011af5fb 100644
--- a/vision/src/detect_landmark.php
+++ b/vision/src/detect_landmark.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'path/to/your/image.jpg1'
-
-function detect_landmark($path)
+/**
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
+ */
+function detect_landmark(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -39,3 +40,7 @@ function detect_landmark($path)
$imageAnnotator->close();
}
// [END vision_landmark_detection]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_landmark_gcs.php b/vision/src/detect_landmark_gcs.php
index 26fbdc5911..d7fb9d2112 100644
--- a/vision/src/detect_landmark_gcs.php
+++ b/vision/src/detect_landmark_gcs.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'gs://path/to/your/image.jpg'
-
-function detect_landmark_gcs($path)
+/**
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
+ */
+function detect_landmark_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -38,3 +39,7 @@ function detect_landmark_gcs($path)
$imageAnnotator->close();
}
// [END vision_landmark_detection_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_logo.php b/vision/src/detect_logo.php
index 51b5838c3c..6c629bb7f3 100644
--- a/vision/src/detect_logo.php
+++ b/vision/src/detect_logo.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'path/to/your/image.jpg'
-
-function detect_logo($path)
+/**
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
+ */
+function detect_logo(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -39,3 +40,7 @@ function detect_logo($path)
$imageAnnotator->close();
}
// [END vision_logo_detection]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_logo_gcs.php b/vision/src/detect_logo_gcs.php
index d3fb773d89..fd9d53b7ce 100644
--- a/vision/src/detect_logo_gcs.php
+++ b/vision/src/detect_logo_gcs.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'gs://path/to/your/image.jpg'
-
-function detect_logo_gcs($path)
+/**
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
+ */
+function detect_logo_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -38,3 +39,7 @@ function detect_logo_gcs($path)
$imageAnnotator->close();
}
// [END vision_logo_detection_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_object.php b/vision/src/detect_object.php
index 0bf784d435..081ea52a7b 100644
--- a/vision/src/detect_object.php
+++ b/vision/src/detect_object.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'path/to/your/image.jpg'
-
-function detect_object($path)
+/**
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
+ */
+function detect_object(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -47,3 +48,7 @@ function detect_object($path)
$imageAnnotator->close();
}
// [END vision_localize_objects]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_object_gcs.php b/vision/src/detect_object_gcs.php
index 9d1b2345b6..91cd2dd1db 100644
--- a/vision/src/detect_object_gcs.php
+++ b/vision/src/detect_object_gcs.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'gs://path/to/your/image.jpg'
-
-function detect_object_gcs($path)
+/**
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
+ */
+function detect_object_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -46,3 +47,7 @@ function detect_object_gcs($path)
$imageAnnotator->close();
}
// [END vision_localize_objects_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_pdf_gcs.php b/vision/src/detect_pdf_gcs.php
index eae77d3e5e..2082ac356b 100644
--- a/vision/src/detect_pdf_gcs.php
+++ b/vision/src/detect_pdf_gcs.php
@@ -29,10 +29,11 @@
use Google\Cloud\Vision\V1\InputConfig;
use Google\Cloud\Vision\V1\OutputConfig;
-// $path = 'gs://path/to/your/document.pdf'
-// $output = 'gs://path/to/store/results/'
-
-function detect_pdf_gcs($path, $output)
+/**
+ * @param string $path GCS path to the document, e.g. "gs://path/to/your/document.pdf"
+ * @param string $outFile GCS path to store the results, e.g. "gs://path/to/store/results/"
+ */
+function detect_pdf_gcs(string $path, string $output)
{
# select ocr feature
$feature = (new Feature())
@@ -106,3 +107,7 @@ function detect_pdf_gcs($path, $output)
$imageAnnotator->close();
}
// [END vision_text_detection_pdf_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_safe_search.php b/vision/src/detect_safe_search.php
index f01a014c37..1275329e0b 100644
--- a/vision/src/detect_safe_search.php
+++ b/vision/src/detect_safe_search.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'path/to/your/image.jpg'
-
-function detect_safe_search($path)
+/**
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
+ */
+function detect_safe_search(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -50,3 +51,7 @@ function detect_safe_search($path)
$imageAnnotator->close();
}
// [END vision_safe_search_detection]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_safe_search_gcs.php b/vision/src/detect_safe_search_gcs.php
index d81c13c7d4..1390be46af 100644
--- a/vision/src/detect_safe_search_gcs.php
+++ b/vision/src/detect_safe_search_gcs.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'gs://path/to/your/image.jpg'
-
-function detect_safe_search_gcs($path)
+/**
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
+ */
+function detect_safe_search_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -53,3 +54,7 @@ function detect_safe_search_gcs($path)
$imageAnnotator->close();
}
// [END vision_safe_search_detection_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_text.php b/vision/src/detect_text.php
index d07bf62b76..0bf10d6df0 100644
--- a/vision/src/detect_text.php
+++ b/vision/src/detect_text.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'path/to/your/image.jpg';
-
-function detect_text($path)
+/**
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
+ */
+function detect_text(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -47,3 +48,7 @@ function detect_text($path)
$imageAnnotator->close();
}
// [END vision_text_detection]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_text_gcs.php b/vision/src/detect_text_gcs.php
index 93f594af8d..ef9b548c23 100644
--- a/vision/src/detect_text_gcs.php
+++ b/vision/src/detect_text_gcs.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'gs://path/to/your/image.jpg'
-
-function detect_text_gcs($path)
+/**
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
+ */
+function detect_text_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -50,3 +51,7 @@ function detect_text_gcs($path)
$imageAnnotator->close();
}
// [END vision_text_detection_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_web.php b/vision/src/detect_web.php
index 3f58298633..a071ec2970 100644
--- a/vision/src/detect_web.php
+++ b/vision/src/detect_web.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'path/to/your/image.jpg'
-
-function detect_web($path)
+/**
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
+ */
+function detect_web(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -83,3 +84,7 @@ function detect_web($path)
$imageAnnotator->close();
}
// [END vision_web_detection]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_web_gcs.php b/vision/src/detect_web_gcs.php
index 13fbe44031..330ac95f00 100644
--- a/vision/src/detect_web_gcs.php
+++ b/vision/src/detect_web_gcs.php
@@ -20,9 +20,10 @@
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
-// $path = 'gs://path/to/your/image.jpg'
-
-function detect_web_gcs($path)
+/**
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
+ */
+function detect_web_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -85,3 +86,7 @@ function detect_web_gcs($path)
$imageAnnotator->close();
}
// [END vision_web_detection_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_web_with_geo_metadata.php b/vision/src/detect_web_with_geo_metadata.php
index 8bc28d061d..55d4751db5 100644
--- a/vision/src/detect_web_with_geo_metadata.php
+++ b/vision/src/detect_web_with_geo_metadata.php
@@ -22,13 +22,13 @@
use Google\Cloud\Vision\V1\ImageContext;
use Google\Cloud\Vision\V1\WebDetectionParams;
-// $path = 'path/to/your/image.jpg'
-
/**
* Detect web entities on an image and include the image's geo metadata
* to improve the quality of the detection.
+ *
+ * @param string $path Path to the image, e.g. "path/to/your/image.jpg"
*/
-function detect_web_with_geo_metadata($path)
+function detect_web_with_geo_metadata(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -56,3 +56,7 @@ function detect_web_with_geo_metadata($path)
$imageAnnotator->close();
}
// [END vision_web_detection_include_geo]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/src/detect_web_with_geo_metadata_gcs.php b/vision/src/detect_web_with_geo_metadata_gcs.php
index b5b80fa79d..8a0cc0d594 100644
--- a/vision/src/detect_web_with_geo_metadata_gcs.php
+++ b/vision/src/detect_web_with_geo_metadata_gcs.php
@@ -22,13 +22,13 @@
use Google\Cloud\Vision\V1\ImageContext;
use Google\Cloud\Vision\V1\WebDetectionParams;
-// $path = 'gs://path/to/your/image.jpg'
-
/**
* Detect web entities on an image and include the image's geo metadata
* to improve the quality of the detection.
+ *
+ * @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
*/
-function detect_web_with_geo_metadata_gcs($path)
+function detect_web_with_geo_metadata_gcs(string $path)
{
$imageAnnotator = new ImageAnnotatorClient();
@@ -57,3 +57,7 @@ function detect_web_with_geo_metadata_gcs($path)
$imageAnnotator->close();
}
// [END vision_web_detection_include_geo_gcs]
+
+// The following 2 lines are only needed to run the samples
+require_once __DIR__ . '/../../testing/sample_helpers.php';
+\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
diff --git a/vision/test/visionTest.php b/vision/test/visionTest.php
index 43b4b07dec..29f4b2dfb8 100644
--- a/vision/test/visionTest.php
+++ b/vision/test/visionTest.php
@@ -18,7 +18,6 @@
namespace Google\Cloud\Samples\Vision;
use Google\Cloud\TestUtils\TestTrait;
-use Google\Cloud\TestUtils\ExecuteCommandTrait;
use PHPUnit\Framework\TestCase;
use PHPUnitRetry\RetryTrait;
@@ -31,14 +30,11 @@ class visionTest extends TestCase
{
use TestTrait;
use RetryTrait;
- use ExecuteCommandTrait;
-
- private static $commandFile = __DIR__ . '/../vision.php';
public function testLabelCommand()
{
$path = __DIR__ . '/data/cat.jpg';
- $output = $this->runCommand('label', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_label', ['path' => $path]);
$this->assertStringContainsString('cat', $output);
}
@@ -47,14 +43,14 @@ public function testLabelCommandGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/cat.jpg';
- $output = $this->runCommand('label', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_label_gcs', ['path' => $path]);
$this->assertStringContainsString('cat', $output);
}
public function testTextCommand()
{
$path = __DIR__ . '/data/sabertooth.gif';
- $output = $this->runCommand('text', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_text', ['path' => $path]);
$this->assertStringContainsString('extinct', $output);
}
@@ -63,14 +59,14 @@ public function testTextCommandGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/sabertooth.gif';
- $output = $this->runCommand('text', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_text_gcs', ['path' => $path]);
$this->assertStringContainsString('extinct', $output);
}
public function testTextCommandWithImageLackingText()
{
- $path = __DIR__ . '/data/faulkner.jpg';
- $output = $this->runCommand('text', ['path' => $path]);
+ $path = __DIR__ . '/data/cat.jpg';
+ $output = $this->runFunctionSnippet('detect_text', ['path' => $path]);
$this->assertStringContainsString('0 texts found', $output);
}
@@ -78,15 +74,15 @@ public function testTextCommandWithImageLackingTextGcs()
{
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
- $path = 'gs://' . $bucketName . '/vision/faulkner.jpg';
- $output = $this->runCommand('text', ['path' => $path]);
+ $path = 'gs://' . $bucketName . '/vision/cat.jpg';
+ $output = $this->runFunctionSnippet('detect_text_gcs', ['path' => $path]);
$this->assertStringContainsString('0 texts found', $output);
}
public function testFaceCommand()
{
$path = __DIR__ . '/data/face.png';
- $output = $this->runCommand('face', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_face', ['path' => $path]);
$this->assertStringContainsString('Anger: ', $output);
$this->assertStringContainsString('Joy: ', $output);
$this->assertStringContainsString('Surprise: ', $output);
@@ -97,7 +93,7 @@ public function testFaceCommandGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/face.png';
- $output = $this->runCommand('face', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_face_gcs', ['path' => $path]);
$this->assertStringContainsString('Anger: ', $output);
$this->assertStringContainsString('Joy: ', $output);
$this->assertStringContainsString('Surprise: ', $output);
@@ -106,7 +102,7 @@ public function testFaceCommandGcs()
public function testFaceCommandWithImageLackingFaces()
{
$path = __DIR__ . '/data/tower.jpg';
- $output = $this->runCommand('face', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_face', ['path' => $path]);
$this->assertStringContainsString('0 faces found', $output);
}
@@ -115,14 +111,14 @@ public function testFaceCommandWithImageLackingFacesGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/tower.jpg';
- $output = $this->runCommand('face', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_face_gcs', ['path' => $path]);
$this->assertStringContainsString('0 faces found', $output);
}
public function testLandmarkCommand()
{
$path = __DIR__ . '/data/tower.jpg';
- $output = $this->runCommand('landmark', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_landmark', ['path' => $path]);
$this->assertRegexp(
'/Eiffel Tower|Champ de Mars|Trocadéro Gardens/',
$output
@@ -134,7 +130,7 @@ public function testLandmarkCommandGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/tower.jpg';
- $output = $this->runCommand('landmark', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_landmark_gcs', ['path' => $path]);
$this->assertRegexp(
'/Eiffel Tower|Champ de Mars|Trocadéro Gardens/',
$output
@@ -144,7 +140,7 @@ public function testLandmarkCommandGcs()
public function testLandmarkCommandWithImageLackingLandmarks()
{
$path = __DIR__ . '/data/faulkner.jpg';
- $output = $this->runCommand('landmark', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_landmark', ['path' => $path]);
$this->assertStringContainsString('0 landmark found', $output);
}
@@ -153,14 +149,14 @@ public function testLandmarkCommandWithImageLackingLandmarksGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/faulkner.jpg';
- $output = $this->runCommand('landmark', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_landmark_gcs', ['path' => $path]);
$this->assertStringContainsString('0 landmark found', $output);
}
public function testLogoCommand()
{
$path = __DIR__ . '/data/logo.jpg';
- $output = $this->runCommand('logo', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_logo', ['path' => $path]);
$this->assertStringContainsString('Google', $output);
}
@@ -169,30 +165,30 @@ public function testLogoCommandGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/logo.jpg';
- $output = $this->runCommand('logo', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_logo_gcs', ['path' => $path]);
$this->assertStringContainsString('Google', $output);
}
- public function testLocalizeObjectCommand()
+ public function testDetectObjectCommand()
{
$path = __DIR__ . '/data/puppies.jpg';
- $output = $this->runCommand('localize-object', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_object', ['path' => $path]);
$this->assertStringContainsString('Dog', $output);
}
- public function testLocalizeObjectCommandGcs()
+ public function testDetectObjectCommandGcs()
{
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/puppies.jpg';
- $output = $this->runCommand('localize-object', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_object_gcs', ['path' => $path]);
$this->assertStringContainsString('Dog', $output);
}
public function testLogoCommandWithImageLackingLogo()
{
$path = __DIR__ . '/data/tower.jpg';
- $output = $this->runCommand('logo', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_logo', ['path' => $path]);
$this->assertStringContainsString('0 logos found', $output);
}
@@ -201,14 +197,14 @@ public function testLogoCommandWithImageLackingLogoGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/tower.jpg';
- $output = $this->runCommand('logo', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_logo_gcs', ['path' => $path]);
$this->assertStringContainsString('0 logos found', $output);
}
public function testSafeSearchCommand()
{
$path = __DIR__ . '/data/logo.jpg';
- $output = $this->runCommand('safe-search', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_safe_search', ['path' => $path]);
$this->assertStringContainsString('Adult:', $output);
$this->assertStringContainsString('Racy:', $output);
}
@@ -218,7 +214,7 @@ public function testSafeSearchCommandGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/logo.jpg';
- $output = $this->runCommand('safe-search', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_safe_search_gcs', ['path' => $path]);
$this->assertStringContainsString('Adult:', $output);
$this->assertStringContainsString('Racy:', $output);
}
@@ -226,7 +222,7 @@ public function testSafeSearchCommandGcs()
public function testImagePropertyCommand()
{
$path = __DIR__ . '/data/logo.jpg';
- $output = $this->runCommand('property', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_image_property', ['path' => $path]);
$this->assertStringContainsString('Red:', $output);
$this->assertStringContainsString('Green:', $output);
$this->assertStringContainsString('Blue:', $output);
@@ -237,7 +233,7 @@ public function testImagePropertyCommandGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/logo.jpg';
- $output = $this->runCommand('property', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_image_property_gcs', ['path' => $path]);
$this->assertStringContainsString('Red:', $output);
$this->assertStringContainsString('Green:', $output);
$this->assertStringContainsString('Blue:', $output);
@@ -248,7 +244,7 @@ public function testImagePropertyCommandGcs()
public function testDocumentTextCommand()
{
$path = __DIR__ . '/data/text.jpg';
- $output = $this->runCommand('document-text', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_document_text', ['path' => $path]);
$this->assertStringContainsString('the PS4 will automatically restart', $output);
$this->assertStringContainsString('37 %', $output);
$this->assertStringContainsString('Block content:', $output);
@@ -260,7 +256,7 @@ public function testDocumentTextCommandGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/text.jpg';
- $output = $this->runCommand('document-text', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_document_text_gcs', ['path' => $path]);
$this->assertStringContainsString('the PS4 will automatically restart', $output);
$this->assertStringContainsString('37 %', $output);
$this->assertStringContainsString('Block content:', $output);
@@ -273,7 +269,7 @@ public function testPdfGcs()
$source = 'gs://' . $bucketName . '/vision/HodgeConj.pdf';
$destination = 'gs://' . $bucketName . '/OCR_PDF_TEST_OUTPUT/';
- $output = $this->runCommand('pdf', [
+ $output = $this->runFunctionSnippet('detect_pdf_gcs', [
'path' => $source,
'output' => $destination,
]);
@@ -283,7 +279,7 @@ public function testPdfGcs()
public function testDetectWebNoGeoCommand()
{
$path = __DIR__ . '/data/geotagged.jpg';
- $output = $this->runCommand('web', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_web', ['path' => $path]);
$this->assertStringContainsString('web entities found', $output);
$this->assertNotRegExp('/^0 web entities found:/', $output);
}
@@ -293,7 +289,7 @@ public function testDetectWebNoGeoCommandGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/geotagged.jpg';
- $output = $this->runCommand('web', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_web_gcs', ['path' => $path]);
$this->assertStringContainsString('web entities found', $output);
$this->assertNotRegExp('/^0 web entities found:/', $output);
}
@@ -301,7 +297,7 @@ public function testDetectWebNoGeoCommandGcs()
public function testDetectWebGeoCommand()
{
$path = __DIR__ . '/data/geotagged.jpg';
- $output = $this->runCommand('web-geo', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_web_with_geo_metadata', ['path' => $path]);
$this->assertStringContainsString('web entities found', $output);
$this->assertNotRegExp('/^0 web entities found:/', $output);
}
@@ -311,7 +307,7 @@ public function testDetectWebGeoCommandGcs()
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
$path = 'gs://' . $bucketName . '/vision/geotagged.jpg';
- $output = $this->runCommand('web-geo', ['path' => $path]);
+ $output = $this->runFunctionSnippet('detect_web_with_geo_metadata_gcs', ['path' => $path]);
$this->assertStringContainsString('web entities found', $output);
$this->assertNotRegExp('/^0 web entities found:/', $output);
}
diff --git a/vision/vision.php b/vision/vision.php
deleted file mode 100644
index 56a8f9ee38..0000000000
--- a/vision/vision.php
+++ /dev/null
@@ -1,312 +0,0 @@
-add((new Command('label'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect labels in an image using Google Cloud Vision API')
- ->setHelp(<<%command.name% command labels objects seen in an image using
-the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_label_gcs($path);
- } else {
- detect_label($path);
- }
- })
-);
-
-// detect text command
-$application->add((new Command('text'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect text in an image using '
- . 'Google Cloud Vision API')
- ->setHelp(<<%command.name% command prints text seen in an image using
-the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_text_gcs($path);
- } else {
- detect_text($path);
- }
- })
-);
-
-// detect face command
-$application->add((new Command('face'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect faces in an image using '
- . 'Google Cloud Vision API')
- ->setHelp(<<%command.name% command finds faces in an image using
-the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- $outFile = $input->getArgument('output');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_face_gcs($path, $outFile);
- } else {
- detect_face($path, $outFile);
- }
- })
-);
-
-// detect landmark command
-$application->add((new Command('landmark'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect landmarks in an image using '
- . 'Google Cloud Vision API')
- ->setHelp(<<%command.name% command finds landmarks in an image using
-the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_landmark_gcs($path);
- } else {
- detect_landmark($path);
- }
- })
-);
-
-// detect logo command
-$application->add((new Command('logo'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect logos in an image using '
- . 'Google Cloud Vision API')
- ->setHelp(<<%command.name% command finds logos in an image using
-the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_logo_gcs($path);
- } else {
- detect_logo($path);
- }
- })
-);
-
-// detect safe search command
-$application->add((new Command('safe-search'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect adult content in an image using '
- . 'Google Cloud Vision API')
- ->setHelp(<<%command.name% command detects adult content in an image using
-the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_safe_search_gcs($path);
- } else {
- detect_safe_search($path);
- }
- })
-);
-
-// detect image property command
-$application->add((new Command('property'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect image proerties in an image using '
- . 'Google Cloud Vision API')
- ->setHelp(<<%command.name% command detects image properties in an image
-using the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_image_property_gcs($path);
- } else {
- detect_image_property($path);
- }
- })
-);
-
-// detect document text command
-$application->add((new Command('document-text'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect document text in an image using '
- . 'Google Cloud Vision API')
- ->setHelp(<<%command.name% command prints document text for an image using
-the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_document_text_gcs($path);
- } else {
- detect_document_text($path);
- }
- })
-);
-
-// detect pdf command
-$application->add((new Command('pdf'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect text from PDF/TIFF using '
- . 'Google Cloud Vision API')
- ->setHelp(<<%command.name% command prints document text for a PDF/TIFF using
-the Google Cloud Vision API.
-
- php %command.full_name% gs://path/to/document.pdf gs://
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- $output = $input->getArgument('output');
- detect_pdf_gcs($path, $output);
- })
-);
-
-// detect web command
-$application->add((new Command('web'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect web references to an image using '
- . 'Google Cloud Vision API')
- ->setHelp(<<%command.name% command prints web references to an image using
-the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_web_gcs($path);
- } else {
- detect_web($path);
- }
- })
-);
-
-// detect web with geo command
-$application->add((new Command('web-geo'))
- ->setDefinition($inputDefinition)
- ->setDescription('Detect web entities to an image with geo metadata '
- . 'using Google Cloud Vision API')
- ->setHelp(<<%command.name% command prints web entities to an image with
-geo metadata using the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_web_with_geo_metadata_gcs($path);
- } else {
- detect_web_with_geo_metadata($path);
- }
- })
-);
-
-// localize object command
-$application->add((new Command('localize-object'))
- ->setDefinition($inputDefinition)
- ->setDescription('Localize object in an image using '
- . 'Google Cloud Vision API')
- ->setHelp(<<%command.name% command finds objects in an image using
-the Google Cloud Vision API.
-
- php %command.full_name% path/to/image.png
-
-EOF
- )
- ->setCode(function ($input, $output) {
- $path = $input->getArgument('path');
- if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $path)) {
- detect_object_gcs($path);
- } else {
- detect_object($path);
- }
- })
-);
-
-if (getenv('PHPUNIT_TESTS') === '1') {
- return $application;
-}
-
-$application->run();