Skip to content

Commit 73b58e4

Browse files
authored
appengine/php72/getting-started: update region tags & index.php comments (GoogleCloudPlatform#828)
1 parent 0a1922d commit 73b58e4

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

appengine/php72/getting-started/index.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,25 @@
1616
*/
1717

1818
/**
19-
* This front controller is called by the App Engine web server to handle all
20-
* incoming requests. To change this, you will need to modify the "entrypoint"
21-
* directive in `app.yaml`.
19+
* This front controller is called by the App Engine web server to handle
20+
* incoming requests.
21+
*
22+
* To use another file, modify the "entrypoint" directive in `app.yaml`.
23+
*
2224
* @see https://cloud.google.com/appengine/docs/standard/php/config/appref
2325
*/
26+
27+
// [START gae_php_app_bootstrap]
28+
29+
// Use the composer autoloader to load dependencies.
2430
require_once __DIR__ . '/vendor/autoload.php';
2531

32+
// Load the application code.
2633
/** @var Slim\App $app */
2734
$app = require __DIR__ . '/src/app.php';
2835
require __DIR__ . '/src/controllers.php';
2936

37+
// Bootstrap the slim framework to handle the request.
3038
$app->run();
39+
40+
// [END gae_php_app_bootstrap]

appengine/php72/getting-started/src/CloudSqlDataModel.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ private function verifyBook($book)
7474
public function listBooks($limit = 10, $cursor = 0)
7575
{
7676
$pdo = $this->pdo;
77-
// [START run_cloudsql_query_multiple_rows]
7877
$query = 'SELECT * FROM books WHERE id > :cursor ORDER BY id LIMIT :limit';
7978
$statement = $pdo->prepare($query);
8079
$statement->bindValue(':cursor', $cursor, PDO::PARAM_INT);
@@ -84,7 +83,6 @@ public function listBooks($limit = 10, $cursor = 0)
8483
// while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
8584
// var_dump($row);
8685
// }
87-
// [END run_cloudsql_query_multiple_rows]
8886
$rows = array();
8987
$nextCursor = null;
9088
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
@@ -109,27 +107,25 @@ public function create($book, $id = null)
109107
return ":$key";
110108
}, $names);
111109
$pdo = $this->pdo;
112-
// [START cloudsql_write]
113110
$sql = sprintf(
114111
'INSERT INTO books (%s) VALUES (%s)',
115112
implode(', ', $names),
116113
implode(', ', $placeHolders)
117114
);
118115
$statement = $pdo->prepare($sql);
119116
$statement->execute($book);
120-
// [END cloudsql_write]
121117
return $this->pdo->lastInsertId();
122118
}
123119

124120
public function read($id)
125121
{
126122
$pdo = $this->pdo;
127-
// [START run_cloudsql_query]
123+
// [START gae_php_app_cloudsql_query]
128124
$statement = $pdo->prepare('SELECT * FROM books WHERE id = :id');
129125
$statement->bindValue('id', $id, PDO::PARAM_INT);
130126
$statement->execute();
131127
$result = $statement->fetch(PDO::FETCH_ASSOC);
132-
// [END run_cloudsql_query]
128+
// [END gae_php_app_cloudsql_query]
133129
return $result;
134130
}
135131

appengine/php72/getting-started/src/app.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
* Follows Silex Skeleton pattern.
2222
*/
2323
use Google\Cloud\Samples\AppEngine\GettingStarted\CloudSqlDataModel;
24-
// [START storage_client_import]
24+
// [START gae_php_app_storage_client_import]
2525
use Google\Cloud\Storage\StorageClient;
2626

27-
// [END storage_client_import]
27+
// [END gae_php_app_storage_client_import]
2828

2929
$app = new Slim\App([
3030
'settings' => [
@@ -43,7 +43,7 @@
4343
// Cloud Storage bucket
4444
$container['bucket'] = function ($container) {
4545
$bucketName = getenv('GOOGLE_STORAGE_BUCKET');
46-
// [START setup_storage_client]
46+
// [START gae_php_app_storage_client_setup]
4747
// Your Google Cloud Storage bucket name and Project ID can be configured
4848
// however fits your application best.
4949
// $projectId = 'YOUR_PROJECT_ID';
@@ -52,7 +52,7 @@
5252
'projectId' => $projectId,
5353
]);
5454
$bucket = $storage->bucket($bucketName);
55-
// [END setup_storage_client]
55+
// [END gae_php_app_storage_client_setup]
5656
return $bucket;
5757
};
5858

@@ -63,15 +63,15 @@
6363
$dbConn = getenv('CLOUDSQL_CONNECTION_NAME');
6464
$dbUser = getenv('CLOUDSQL_USER');
6565
$dbPass = getenv('CLOUDSQL_PASSWORD');
66-
// [START setup_cloudsql_client]
66+
// [START gae_php_app_cloudsql_client_setup]
6767
// Fill the variables below to match your Cloud SQL configuration.
6868
// $dbConn = 'YOUR_CLOUDSQL_CONNECTION_NAME';
6969
// $dbName = 'YOUR_CLOUDSQL_DATABASE_NAME';
7070
// $dbUser = 'YOUR_CLOUDSQL_USER';
7171
// $dbPass = 'YOUR_CLOUDSQL_PASSWORD';
7272
$dsn = "mysql:unix_socket=/cloudsql/${dbConn};dbname=${dbName}";
7373
$pdo = new PDO($dsn, $dbUser, $dbPass);
74-
// [END setup_cloudsql_client]
74+
// [END gae_php_app_cloudsql_client_setup]
7575
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
7676
return new CloudSqlDataModel($pdo);
7777
};

appengine/php72/getting-started/src/controllers.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
$bucket = $this->bucket;
9696
$imageStream = $image->getStream();
9797
$imageContentType = $image->getClientMediaType();
98-
// [START upload_image]
98+
// [START gae_php_app_upload_image]
9999
// Set your own image file path and content type below to upload an
100100
// image to Cloud Storage.
101101
// $imageStream = fopen('/path/to/your_image.jpg', 'r');
@@ -105,7 +105,7 @@
105105
'predefinedAcl' => 'publicRead',
106106
]);
107107
$imageUrl = $object->info()['mediaLink'];
108-
// [END upload_image]
108+
// [END gae_php_app_upload_image]
109109
$book['image_url'] = $imageUrl;
110110
}
111111
if ($this->cloudsql->update($book)) {
@@ -123,10 +123,10 @@
123123
$objectName = parse_url(basename($book['image_url']), PHP_URL_PATH);
124124
$bucket = $this->bucket;
125125
// get bucket name from image
126-
// [START delete_image]
126+
// [START gae_php_app_delete_image]
127127
$object = $bucket->object($objectName);
128128
$object->delete();
129-
// [END delete_image]
129+
// [END gae_php_app_delete_image]
130130
}
131131
return $response->withRedirect('/books');
132132
}

0 commit comments

Comments
 (0)