Skip to content

Commit 38e43be

Browse files
committed
Merge pull request GoogleCloudPlatform#14 from bshaffer/add-datastore
Adds a datastore sample
2 parents 2b46845 + 4e5eda3 commit 38e43be

File tree

11 files changed

+1794
-0
lines changed

11 files changed

+1794
-0
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ script:
3131
- composer install
3232
- phpunit mainTest.php
3333
- phpunit utilTest.php
34+
- cd ../..
35+
# run datastore tests
36+
- cd datastore
37+
- composer install
38+
- phpunit test
39+
- cd ..

datastore/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Google Datastore PHP Sample Application
2+
3+
A simple app to make calls to the Datastore API
4+
5+
## Register your application
6+
7+
- Go to
8+
[Google Developers Console](https://console.developers.google.com/project)
9+
and create a new project. This will automatically enable an App
10+
Engine application with the same ID as the project.
11+
12+
- Enable the "Google Cloud Datastore API" under "APIs & auth > APIs."
13+
14+
- edit `app.yaml` and change `MY_GCP_PROJECT_ID` to your App Engine project ID
15+
16+
- For local development also follow the instructions below.
17+
18+
- Go to "Credentials" and create a new Service Account.
19+
20+
- Select "Generate new JSON key", then download a new JSON file.
21+
22+
- Set the following environment variables:
23+
24+
- `GOOGLE_APPLICATION_CREDENTIALS`: the file path to the downloaded JSON file.
25+
- `GCP_PROJECT_ID`: Your app engine project ID
26+
27+
## Prerequisites
28+
29+
- Install [`composer`](https://getcomposer.org)
30+
- Install Google API client library for PHP by running:
31+
32+
```sh
33+
composer install
34+
```
35+
36+
## Run locally
37+
38+
you can run locally using PHP's built-in web server:
39+
40+
```sh
41+
cd php-docs-samples/datastore
42+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
43+
export GCP_PROJECT_ID=my-project-id
44+
php -S localhost:8080 -t web/
45+
```
46+
47+
Now you can view the app running at [http://localhost:8080](http://localhost:8080)
48+
in your browser.
49+
50+
## Deploy to App Engine
51+
52+
**Prerequisites**
53+
54+
- Install the App Engine PHP SDK.
55+
We recommend you install
56+
[Cloud SDK](https://developers.google.com/cloud/sdk/) rather than
57+
just installing App Engine SDK.
58+
59+
**Deploy with gcloud**
60+
61+
```
62+
$ gcloud preview app deploy app.yaml --set-default --project YOUR_GCP_PROJECT_ID
63+
```
64+
65+
Then access the following URL:
66+
https://{YOUR_GCP_PROJECT_ID}.appspot.com/
67+
68+
### Run for App Engine locally
69+
70+
```
71+
$ dev_appserver.py -A your-project-id .
72+
```
73+
74+
## Contributing changes
75+
76+
* See [CONTRIBUTING.md](../CONTRIBUTING.md)
77+
78+
## Licensing
79+
80+
* See [LICENSE](../LICENSE)
81+
82+

datastore/app.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtime: php55
2+
api_version: 1
3+
threadsafe: true
4+
5+
handlers:
6+
- url: /.*
7+
script: web/index.php
8+
9+
env_variables:
10+
GCP_PROJECT_ID: "YOUR_GCP_PROJECT_ID"

datastore/composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"autoload": {
3+
"psr-4": {
4+
"Google\\Cloud\\Samples\\Datastore\\": "src"
5+
}
6+
},
7+
"require": {
8+
"php": ">=5.4",
9+
"silex/silex": "~1.3",
10+
"twig/twig": "~1.8|~2.0",
11+
"symfony/twig-bridge": "~2.7|3.0.*",
12+
"google/apiclient": "~2.0@RC"
13+
},
14+
"require-dev": {
15+
"symfony/dom-crawler": "~2.0",
16+
"symfony/css-selector": "~2.0",
17+
"symfony/browser-kit": "~2.7"
18+
}
19+
}

0 commit comments

Comments
 (0)