Skip to content

Commit 0fdaf9c

Browse files
committed
chore: upgrade PHP samples to use namespaces
1 parent 6e00380 commit 0fdaf9c

Some content is hidden

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

43 files changed

+230
-157
lines changed

admin-sdk/directory/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"google/apiclient": "^2.2"
3+
"google/apiclient": "^2.10"
44
}
55
}

admin-sdk/directory/quickstart.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
throw new Exception('This application must be run on the command line.');
2222
}
2323

24+
use Google\Client;
25+
use Google\Service\Directory;
26+
2427
/**
2528
* Returns an authorized API client.
26-
* @return Google_Client the authorized client object
29+
* @return Client the authorized client object
2730
*/
2831
function getClient()
2932
{
30-
$client = new Google_Client();
33+
$client = new Client();
3134
$client->setApplicationName('G Suite Directory API PHP Quickstart');
3235
$client->setScopes('https://www.googleapis.com/auth/admin.directory.user.readonly');
3336
$client->setAuthConfig('credentials.json');
@@ -77,7 +80,7 @@ function getClient()
7780

7881
// Get the API client and construct the service object.
7982
$client = getClient();
80-
$service = new Google_Service_Directory($client);
83+
$service = new Directory($client);
8184

8285
// Print the first 10 users in the domain.
8386
try{

admin-sdk/reports/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"google/apiclient": "^2.2"
3+
"google/apiclient": "^2.10"
44
}
55
}

admin-sdk/reports/quickstart.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
throw new Exception('This application must be run on the command line.');
2222
}
2323

24+
use Google\Client;
25+
use Google\Service\Reports;
26+
2427
/**
2528
* Returns an authorized API client.
26-
* @return Google_Client the authorized client object
29+
* @return Client the authorized client object
2730
*/
2831
function getClient()
2932
{
30-
$client = new Google_Client();
33+
$client = new Client();
3134
$client->setApplicationName('Reports API PHP Quickstart');
3235
$client->setScopes('https://www.googleapis.com/auth/admin.reports.audit.readonly');
3336
$client->setAuthConfig('credentials.json');
@@ -77,7 +80,7 @@ function getClient()
7780

7881
// Get the API client and construct the service object.
7982
$client = getClient();
80-
$service = new Google_Service_Reports($client);
83+
$service = new Reports($client);
8184

8285
// Print the last 10 login events.
8386
$userKey = 'all';

admin-sdk/reseller/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"google/apiclient": "^2.2"
3+
"google/apiclient": "^2.10"
44
}
55
}

admin-sdk/reseller/quickstart.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
throw new Exception('This application must be run on the command line.');
2222
}
2323

24+
use Google\Client;
25+
use Google\Service\Reseller;
26+
2427
/**
2528
* Returns an authorized API client.
26-
* @return Google_Client the authorized client object
29+
* @return Client the authorized client object
2730
*/
2831
function getClient()
2932
{
30-
$client = new Google_Client();
33+
$client = new Client();
3134
$client->setApplicationName('G Suite Reseller API PHP Quickstart');
3235
$client->setScopes("https://www.googleapis.com/auth/apps.order");
3336
$client->setAuthConfig('credentials.json');
@@ -77,7 +80,7 @@ function getClient()
7780

7881
// Get the API client and construct the service object.
7982
$client = getClient();
80-
$service = new Google_Service_Reseller($client);
83+
$service = new Reseller($client);
8184

8285
// Print the first 10 subscriptions you manage.
8386
$optParams = array(

apps-script/execute/execute.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
// [START apps_script_api_execute]
1919
require __DIR__ . '/vendor/autoload.php';
2020

21+
use Google\Service\Script;
22+
2123
// Get the API client and construct the service object.
2224
$client = getClient();
23-
$service = new Google_Service_Script($client);
25+
$service = new Script($client);
2426

2527
$scriptId = 'ENTER_YOUR_SCRIPT_ID_HERE';
2628

2729
// Create an execution request object.
28-
$request = new Google_Service_Script_ExecutionRequest();
30+
$request = new Script\ExecutionRequest();
2931
$request->setFunction('getFoldersUnderRoot');
3032

3133
try {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"google/apiclient": "^2.2"
3+
"google/apiclient": "^2.10"
44
}
55
}

apps-script/quickstart/quickstart.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
throw new Exception('This application must be run on the command line.');
2222
}
2323

24+
use Google\Client;
25+
use Google\Service\Script;
26+
2427
/**
2528
* Returns an authorized API client.
26-
* @return Google_Client the authorized client object
29+
* @return Client the authorized client object
2730
*/
2831
function getClient()
2932
{
30-
$client = new Google_Client();
33+
$client = new Client();
3134
$client->setApplicationName('Google Apps Script API PHP Quickstart');
3235
$client->setScopes("https://www.googleapis.com/auth/script.projects");
3336
$client->setAuthConfig('credentials.json');
@@ -82,12 +85,12 @@ function getClient()
8285
* project, and log the script's URL to the user.
8386
*/
8487
$client = getClient();
85-
$service = new Google_Service_Script($client);
88+
$service = new Script($client);
8689

8790
// Create a management request object.
8891
try{
8992

90-
$request = new Google_Service_Script_CreateProjectRequest();
93+
$request = new Script\CreateProjectRequest();
9194
$request->setTitle('My Script');
9295
$response = $service->projects->create($request);
9396

@@ -98,7 +101,7 @@ function helloWorld() {
98101
console.log('Hello, world!');
99102
}
100103
EOT;
101-
$file1 = new Google_Service_Script_ScriptFile();
104+
$file1 = new Script\ScriptFile();
102105
$file1->setName('hello');
103106
$file1->setType('SERVER_JS');
104107
$file1->setSource($code);
@@ -109,12 +112,12 @@ function helloWorld() {
109112
"exceptionLogging": "CLOUD"
110113
}
111114
EOT;
112-
$file2 = new Google_Service_Script_ScriptFile();
115+
$file2 = new Script\ScriptFile();
113116
$file2->setName('appsscript');
114117
$file2->setType('JSON');
115118
$file2->setSource($manifest);
116119

117-
$request = new Google_Service_Script_Content();
120+
$request = new Script\Content();
118121
$request->setScriptId($scriptId);
119122
$request->setFiles([$file1, $file2]);
120123

calendar/quickstart/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"google/apiclient": "^2.2"
3+
"google/apiclient": "^2.10"
44
}
55
}

0 commit comments

Comments
 (0)