Skip to content

Commit 582add6

Browse files
authored
Merge pull request #180 from tomwalder/feature/php-7-plus
Feature/php 7 plus
2 parents d00b41a + 44aae05 commit 582add6

Some content is hidden

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

76 files changed

+1102
-4473
lines changed

.gcloudignore

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file specifies files that are *not* uploaded to Google Cloud Platform
2+
# using gcloud. It follows the same syntax as .gitignore, with the addition of
3+
# "#!include" directives (which insert the entries of the given .gitignore-style
4+
# file at that point).
5+
#
6+
# For more information, run:
7+
# $ gcloud topic gcloudignore
8+
#
9+
.gcloudignore
10+
# If you would like to upload your .git directory, .gitignore file or files
11+
# from your .gitignore file, remove the corresponding line
12+
# below:
13+
.git
14+
.gitignore
15+
.phpunit.result.cache
16+
17+
# PHP Composer dependencies:
18+
/vendor/

.gitignore

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
vendor/
22
examples/scratch.php
3-
pb4/
4-
pb3/
53
build/
6-
_examples/
7-
vendor/
8-
app.yaml
94
index.yaml
105
composer.lock
6+
.phpunit.result.cache

.travis.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ language: php
33
dist: trusty
44

55
php:
6-
- 5.5
7-
- 5.6
8-
- 7.0
9-
- 7.1
106
- 7.2
117
- 7.3
8+
- 7.4
129

1310
before_script:
1411
- composer self-update

README.md

+76-89
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,44 @@
77

88
This library is intended to make it easier for you to get started with and to use Datastore in your applications.
99

10-
## Firestore in Datastore Mode, Dec 2019 ##
10+
## Quick Start ##
11+
```bash
12+
composer require "tomwalder/php-gds:^5.0"
13+
```
14+
```php
15+
// Build a new entity
16+
$obj_book = new GDS\Entity();
17+
$obj_book->title = 'Romeo and Juliet';
18+
$obj_book->author = 'William Shakespeare';
19+
$obj_book->isbn = '1840224339';
1120

12-
If you are using Firestore in Datastore mode and `php-gds` from App Engine standard, you may run into `Internal Error`s from the `Protobuf` gateway.
21+
// Write it to Datastore
22+
$obj_store = new GDS\Store('Book');
23+
$obj_store->upsert($obj_book);
1324

14-
You can resolve this by using the `RESTv1` Gateway & APIs. [See here for basic guidance](#using-the-datastore-rest-api-v1-sep-2016)
25+
// Fetch all books
26+
foreach($obj_store->fetchAll() as $obj_book) {
27+
echo "Title: {$obj_book->title}, ISBN: {$obj_book->isbn} <br />", PHP_EOL;
28+
}
29+
```
1530

16-
More details and recommended upgrade paths to come. Along with better gRPC support for outside App Engine.
31+
## New in Version 5.0 ##
32+
33+
**As of version 5 (May 2021), this library provides support for**
34+
35+
* PHP 7 second-generation App Engine runtimes - using the REST API by default
36+
* PHP 7 "anywhere" (e.g. Google Compute Engine, Cloud Run, GKE) - using REST or gRPC
1737

18-
## Datastore API Turn Down, Sep 2016 ##
38+
**Key features removed from version 5 onwards**
1939

20-
Google turned down the older versions of the REST API on September 30th, 2016. Version v1beta1 and v1beta2 are no longer available.
40+
* PHP 5 support
41+
* Support for the legacy "Protocol Buffer" API built into first-generation App Engine runtimes
2142

22-
* If you are using this library on App Engine, and using the default `Protobuf` gateway then NO CHANGES ARE NEEDED. Version 2.x or 3.x are both supported.
23-
* If you are using this library anywhere else, like Compute Engine, and you are using the `GoogleAPIClient` gateway (version 2.x), then you will need to upgrade to version 3.x
43+
If you need to continue running applications on that infrastructure, stick to version 4.x or earlier.
2444

2545
## Table of Contents ##
2646

2747
* [Examples](#examples)
28-
* [New in version 4.0](#new-in-version-40)
29-
* [Changes in version 3.0](#changes-in-version-30): [Datastore REST API v1 (Sep 2016)](#using-the-datastore-rest-api-v1-sep-2016)
30-
* [Changes in version 2.0](#changes-in-version-20)
3148
* [Getting Started](#getting-started) including installation with Composer and setup for GDS Emulator
3249
* [Defining Your Model](#defining-your-model)
3350
* [Creating Records](#creating-records)
@@ -41,6 +58,33 @@ Google turned down the older versions of the REST API on September 30th, 2016. V
4158
* [Unit Tests](#unit-tests)
4259
* [Footnotes](#footnotes)
4360

61+
## Using the REST API (default from 5.0) ##
62+
63+
As of PHP-GDS version 5, the REST API Gateway is the default.
64+
65+
It will attempt to auto-detect your Google Project ID - and usually the Google auth library will use the default application credentials.
66+
67+
You might need to set an environment variable with the path to your JSON credentials file first, usually if you're running outside of App Engine or Google Compute Engine.
68+
69+
```php
70+
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/credentials.json');
71+
72+
// A regular Store, but with a custom Gateway
73+
$obj_book_store = new GDS\Store('Book', new \GDS\Gateway\RESTv1('my-project-id'));
74+
```
75+
76+
You can find out more about the auth system here: [Google Auth Library for PHP](https://github.com/google/google-auth-library-php)
77+
78+
You can download a service account JSON file from the Google Cloud Console `API Manager > Credentials`.
79+
80+
## Firestore in Datastore Mode ##
81+
82+
If you are using PHP-GDS version 4 or earlier, and Firestore in Datastore mode from App Engine standard (first generation), you may run into `Internal Error`s from the `Protobuf` gateway.
83+
84+
You can resolve this by using the `RESTv1` Gateway & APIs. [See here for basic guidance](#using-the-datastore-rest-api-v1-sep-2016)
85+
86+
More details and recommended upgrade paths to come. Along with better gRPC support for outside App Engine.
87+
4488
## Examples ##
4589

4690
I find examples a great way to decide if I want to even try out a library, so here's a couple for you.
@@ -79,14 +123,12 @@ foreach($obj_store->fetchAll() as $obj_book) {
79123
### More about the Examples ###
80124

81125
These initial examples assume you are either running a Google AppEngine application or in a local AppEngine dev environment.
82-
In both of these cases, we can auto detect the **dataset** and use the default ***Protocol Buffer Gateway***.
126+
In both of these cases, we can auto detect the **dataset**.
83127

84128
We use a `GDS\Store` to read and write `GDS\Entity` objects to and from Datastore.
85129

86130
These examples use the generic `GDS\Entity` class with a dynamic Schema. See [Defining Your Model](#defining-your-model) below for more details on custom Schemas and indexed fields.
87131

88-
Check out the [examples](examples/) folder for many more and fuller code samples.
89-
90132
### Demo Application ###
91133

92134
A simple guest book application
@@ -95,71 +137,23 @@ Application: http://php-gds-demo.appspot.com/
95137

96138
Code: https://github.com/tomwalder/php-gds-demo
97139

98-
## New in Version 4.0 ##
140+
## Changes in Version 5 ##
141+
142+
* Add PHP 7 support
143+
* Remove PHP 5 support
144+
* Remove App Engine first-generation runtime support (inc direct Protocol Buffer API)
145+
146+
## Changes in Version 4 ##
99147

100148
* More consistent use of `DateTime` objects - now all result sets will use them instead of `Y-m-d H:i:s` strings
101149
* Move the `google/auth` to an optional dependency - if you need the REST API
102150

103-
## Changes in Version 3.0 ##
151+
## Changes in Version 3 ##
104152

105-
* Support for the new **Datastore API, v1 - via REST** (gRPC to come)
153+
* Support for the new **Datastore API, v1 - via REST**
106154
* Removal of support for the old 1.x series "PHP Google API Client"
107155
* **GeoPoint data is now supported over the REST API** v1 as well as ProtoBuf
108156

109-
### Using the Datastore REST API v1 (Sep 2016) ###
110-
111-
The Datastore REST API v1 went Generally Available (GA) in 2016. The previous REST API will be deprecated after September 2016.
112-
113-
If you are running PHP-GDS from somewhere other than App Engine, you need to use the REST API v1.
114-
115-
You just have to pass an instance of the RESTv1 gateway into your Store objects on construction.
116-
117-
You might need to set an environment variable with the path to your JSON credentials file first.
118-
119-
```php
120-
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/credentials.json');
121-
122-
// A regular Store, but with a custom Gateway
123-
$obj_book_store = new GDS\Store('Book', new \GDS\Gateway\RESTv1(PROJECT_ID));
124-
```
125-
126-
You can find out more about the auth system here: [Google Auth Library for PHP](https://github.com/google/google-auth-library-php)
127-
128-
You can download a service account JSON file from the Google Cloud Console `API Manager > Credentials`.
129-
130-
## Changes in Version 2.0 ##
131-
132-
Features in 2.0 included
133-
* **Faster** - use of Google Protocol Buffer allows faster, low-level access to Datastore
134-
* **Easier to use** - sensible defaults and auto-detection for AppEngine environments
135-
* **Less dependencies** - no need for the Google PHP API Client, unless running remote or from non-AppEngine environments
136-
* **Local development** - Using the Protocol Buffers allows us to access the development server Datastore
137-
* **Local GQL support** - By default, the local development server does not support GQL. I've included a basic GQL parser that makes this work.
138-
* **Data Migrations** - leverage multiple Gateways to ship data between local and live Datastore
139-
* **Contention Exceptions** - standardised Exception for handling Datastore transaction contention
140-
* **Unit tests**
141-
* Optional drop-in JSON API Gateway for remote or non-AppEngine environments (this was the only Gateway in 1.x)
142-
143-
### Backwards Compatibility ###
144-
145-
#### v3 over v2 ####
146-
147-
The REST API v1 implementation now follows the same datetime response formats at the ProtoBuf API. (Y-m-d H:i:s).
148-
149-
#### v2 over v1 ####
150-
151-
The library is *almost* fully backwards compatible. And in fact, the main operations of the `GDS\Store` class are identical.
152-
153-
There is one BC-break in 2.0 - the re-ordering of construction parameters for the `GDS\Store` class.
154-
155-
`GDS\Store::__construct(<Kind or Schema>, <Gateway>)`
156-
157-
instead of
158-
159-
`GDS\Store::__construct(<Gateway>, <Kind or Schema>)`
160-
161-
This is because the Gateway is now optional, and has a sensible, automated, default - the new Protocol Buffer implementation.
162-
163157
## Getting Started ##
164158

165159
Are you sitting comfortably? Before we begin, you will need:
@@ -172,22 +166,17 @@ If you want to use the JSON API from remote or non-App Engine environments, you
172166

173167
### Composer, Dependencies ###
174168

175-
To install using Composer, use this require line
176-
177-
`"tomwalder/php-gds": "v4.*"`
178-
179-
For older series
180-
181-
`"tomwalder/php-gds": "v3.*"`
169+
To install using Composer
182170

183-
`"tomwalder/php-gds": "v2.*"`
184-
185-
and for bleeding-edge features, dev-master
171+
```bash
172+
composer require "tomwalder/php-gds:^5.0"
173+
```
186174

187-
`"tomwalder/php-gds": "dev-master"`
175+
### Use with the Datastore Emulator ###
176+
Local development is supported using the REST Gateway and the Datastore Emulator.
188177

189-
### Use with the GDS emulator ###
190-
If you want to use it with the GDS emulator make sure the environment variable `DATASTORE_EMULATOR_HOST` is set with the host, for example `localhost:8081`
178+
Detailed instructions can be found here:
179+
https://cloud.google.com/datastore/docs/tools/datastore-emulator
191180

192181
## Defining Your Model ##
193182

@@ -274,11 +263,9 @@ echo $obj_person->location->getLongitude();
274263

275264
**It is not currently possible to query Geopoint fields, although this feature is in Alpha with Google**
276265

277-
**Geopoint data is only supported using the native Protocol Buffer API. It will work well on App Engine and in development, but not via the JSON API**
278-
279266
## Queries, GQL & The Default Query ##
280267

281-
At the time of writing, the `GDS\Store` object uses Datastore GQL as its query language. Here is an example:
268+
The `GDS\Store` object uses Datastore GQL as its query language. Here is an example:
282269

283270
```php
284271
$obj_book_store->fetchOne("SELECT * FROM Book WHERE isbn = '1853260304'");
@@ -457,8 +444,8 @@ Using multiple Gateway classes, you can move data between namespaces
457444

458445
```php
459446
// Name-spaced Gateways
460-
$obj_gateway_one = new \GDS\Gateway\ProtoBuf('dataset', 'namespace_one');
461-
$obj_gateway_two = new \GDS\Gateway\ProtoBuf('dataset', 'namespace_two');
447+
$obj_gateway_one = new \GDS\Gateway\RESTv1('project-id', 'namespace_one');
448+
$obj_gateway_two = new \GDS\Gateway\RESTv1('project-id', 'namespace_two');
462449

463450
// Grab some books from one
464451
$arr_books = (new \GDS\Store('Book', $obj_gateway_one))->fetchPage(20);

app.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Simple app.yaml for the PHP GDS demo app
2+
3+
runtime: php74
4+
5+
handlers:
6+
- url: .*
7+
script: auto

composer.json

100644100755
+15-8
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,30 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.5.0",
16-
"ext-bcmath" : "*"
15+
"php": ">=7.0",
16+
"ext-bcmath" : "*",
17+
"google/auth": "^1.0"
1718
},
1819
"require-dev": {
19-
"google/auth": "v1.0.*",
20-
"google/appengine-php-sdk": ">=1.9.22",
21-
"phpunit/phpunit": "~4.8",
22-
"satooshi/php-coveralls": "v2.0.*"
20+
"google/cloud-datastore": "^v1.12",
21+
"phpunit/phpunit": "~8",
22+
"satooshi/php-coveralls": "^v2.2"
2323
},
2424
"suggest": {
25-
"google/auth": "If you need to use the REST API (i.e. not on AppEngine Standard) Tested with v1.0.1"
25+
"google/cloud-datastore": "If you need to use the gRPC API & Gateway"
2626
},
2727
"autoload": {
2828
"classmap": [
2929
"src/"
3030
],
3131
"psr-4": {"GDS\\": "src/GDS/"}
3232
},
33-
"include-path": ["src/"]
33+
"include-path": ["src/"],
34+
"config": {
35+
"platform": {
36+
"php": "7.2.0"
37+
},
38+
"optimize-autoloader": true,
39+
"sort-packages": true
40+
}
3441
}

examples/Book.php

-10
This file was deleted.

examples/BookStore.php

-24
This file was deleted.

examples/README.md

-9
This file was deleted.

0 commit comments

Comments
 (0)