1717
1818declare (strict_types=1 );
1919
20+ namespace Google \Cloud \Samples \Kms ;
21+
2022// [START kms_create_key_symmetric_encrypt_decrypt]
2123use Google \Cloud \Kms \V1 \CryptoKey ;
2224use Google \Cloud \Kms \V1 \CryptoKey \CryptoKeyPurpose ;
2325use Google \Cloud \Kms \V1 \CryptoKeyVersion \CryptoKeyVersionAlgorithm ;
2426use Google \Cloud \Kms \V1 \CryptoKeyVersionTemplate ;
2527use Google \Cloud \Kms \V1 \KeyManagementServiceClient ;
2628
27- function create_key_symmetric_encrypt_decrypt_sample (
29+ function create_key_symmetric_encrypt_decrypt (
2830 string $ projectId = 'my-project ' ,
2931 string $ locationId = 'us-east1 ' ,
3032 string $ keyRingId = 'my-key-ring ' ,
@@ -46,16 +48,11 @@ function create_key_symmetric_encrypt_decrypt_sample(
4648 // Call the API.
4749 $ createdKey = $ client ->createCryptoKey ($ keyRingName , $ id , $ key );
4850 printf ('Created symmetric key: %s ' . PHP_EOL , $ createdKey ->getName ());
51+
4952 return $ createdKey ;
5053}
5154// [END kms_create_key_symmetric_encrypt_decrypt]
5255
53- if (isset ($ argv )) {
54- if (count ($ argv ) === 0 ) {
55- return printf ("Usage: php %s PROJECT_ID LOCATION_ID KEY_RING_ID ID \n" , basename (__FILE__ ));
56- }
57-
58- require_once __DIR__ . '/../vendor/autoload.php ' ;
59- list ($ _ , $ projectId , $ locationId , $ keyRingId , $ id ) = $ argv ;
60- create_key_symmetric_encrypt_decrypt_sample ($ projectId , $ locationId , $ keyRingId , $ id );
61- }
56+ // The following 2 lines are only needed to run the samples
57+ require_once __DIR__ . '/../../testing/sample_helpers.php ' ;
58+ return \Google \Cloud \Samples \execute_sample (__FILE__ , __NAMESPACE__ , $ argv );
0 commit comments