1. Go to this page and download the library: Download tomwalder/php-gds library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tomwalder / php-gds example snippets
// Build a new entity
$obj_book = new GDS\Entity();
$obj_book->title = 'Romeo and Juliet';
$obj_book->author = 'William Shakespeare';
$obj_book->isbn = '1840224339';
// Write it to Datastore
$obj_store = new GDS\Store('Book');
$obj_store->upsert($obj_book);
// Fetch all books
foreach($obj_store->fetchAll() as $obj_book) {
echo "Title: {$obj_book->title}, ISBN: {$obj_book->isbn} <br />", PHP_EOL;
}
\GDS\Gateway::exponentialBackoff(true);
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/credentials.json');
// A regular Store, but with a custom Gateway
$obj_book_store = new GDS\Store('Book', new \GDS\Gateway\RESTv1('my-project-id'));
// Build a new entity
$obj_book = new GDS\Entity();
$obj_book->title = 'Romeo and Juliet';
$obj_book->author = 'William Shakespeare';
$obj_book->isbn = '1840224339';
// Write it to Datastore
$obj_store = new GDS\Store('Book');
$obj_store->upsert($obj_book);
$obj_book = $obj_store->createEntity([
'title' => 'The Merchant of Venice',
'author' => 'William Shakespeare',
'isbn' => '1840224312'
]);
$obj_store = new GDS\Store('Book');
foreach($obj_store->fetchAll() as $obj_book) {
echo "Title: {$obj_book->title}, ISBN: {$obj_book->isbn} <br />", PHP_EOL;
}
$obj_schema = (new GDS\Schema('Book'))
->addString('title')
->addString('author')
->addString('isbn');
// The Store accepts a Schema object or Kind name as its first parameter
$obj_book_store = new GDS\Store($obj_schema);
$obj_book = $obj_book_store->createEntity([
'title' => 'The Merchant of Venice',
'author' => 'William Shakespeare',
'isbn' => '1840224312'
]);
$obj_book = $obj_book_store->createEntity([
'title' => 'Some Book',
'author' => 'A N Other Guy',
'isbn' => '1840224313',
'published' => new DateTime('-5 years')
]);
$obj_schema->addGeopoint('location');
$obj_person->location = new GDS\Property\Geopoint(53.4723272, -2.2936314);
// Create a store for a particular customer or 'application namespace'
$obj_gateway = new \GDS\Gateway\RESTv1('project-id', 'namespace');
$obj_store = new \GDS\Store('Book', $obj_gateway);
$obj_store->beginTransaction();
// Data changed within a transaction
$obj_store->upsert($obj_entity);
// Not transactional
$obj_store->delete($obj_entity);
class Book extends GDS\Entity { /* ... */ }
$obj_store->setEntityClass('\\Book');
// Name-spaced Gateways
$obj_gateway_one = new \GDS\Gateway\RESTv1('project-id', 'namespace_one');
$obj_gateway_two = new \GDS\Gateway\RESTv1('project-id', 'namespace_two');
// Grab some books from one
$arr_books = (new \GDS\Store('Book', $obj_gateway_one))->fetchPage(20);
// And insert to two
(new \GDS\Store('Book', $obj_gateway_two))->upsert($arr_books);
// Local and Remote Gateways
$obj_gateway_local = new \GDS\Gateway\ProtoBuf();
$obj_gateway_remote = new \GDS\Gateway\RESTv1('project-name');
// Grab some books from local
$arr_books = (new \GDS\Store('Book', $obj_gateway_local))->fetchPage(20);
// And insert to remote
(new \GDS\Store('Book', $obj_gateway_remote))->upsert($arr_books);
bash
composer
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.