Skip to content

Commit

Permalink
feat: Add Firestore session handler. (#2258)
Browse files Browse the repository at this point in the history
* adds Firestore session handler

* Update Firestore/src/FirestoreSessionHandler.php

Co-Authored-By: John Pedrie <[email protected]>

* wraps writes in transactions

* removes collection name validation, mocks runTransaction better

* Add snippet and system tests

* remove extraneous doc lines

* Skip tests if grpc missing

* updates sessionhandler to use transactions

* first round of test fixes

* fixes syntax error

* adds GC test, fixes remaining tests

* fixes cs

* fixes test snippets

* removes unnecessary changes and adds test for coverage

* adds options comment, adds collectionNameTemplate option

* removes redundant optional identifier

* addresses review comments

* addresses more review comments

* adds back  variable to callables

* adds try/catch around beginTransaction
  • Loading branch information
bshaffer authored and dwsupplee committed Sep 24, 2019
1 parent 7e133f1 commit f5f006b
Show file tree
Hide file tree
Showing 7 changed files with 1,212 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Firestore/src/FirestoreClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,51 @@ public function fieldPath(array $fieldNames)
{
return new FieldPath($fieldNames);
}

/**
* Returns a FirestoreSessionHandler.
*
* Example:
* ```
* $handler = $firestore->sessionHandler();
*
* // Configure PHP to use the Firestore session handler.
* session_set_save_handler($handler, true);
* session_save_path('sessions');
* session_start();
*
* // Then write and read the $_SESSION array.
* $_SESSION['name'] = 'Bob';
* echo $_SESSION['name'];
* ```
*
* @param array $options [optional] {
* Configuration Options.
*
* @type int $gcLimit The number of entities to delete in the garbage
* collection. Values larger than 1000 will be limited to 1000.
* **Defaults to** `0`, indicating garbage collection is disabled by
* default.
* @type string $collectionNameTemplate A sprintf compatible template
* for formatting the collection name where sessions will be stored.
* The template receives two values, the first being the save path
* and the latter being the session name.
* @type array $begin Configuration options for beginTransaction.
* @type array $commit Configuration options for commit.
* @type array $rollback Configuration options for rollback.
* @type array $read Configuration options for read.
* @type array $query Configuration options for runQuery.
* }
* @return FirestoreSessionHandler
*/
public function sessionHandler(array $options = [])
{
return new FirestoreSessionHandler(
$this->connection,
$this->valueMapper,
$this->projectId,
$this->database,
$options
);
}
}
Loading

0 comments on commit f5f006b

Please sign in to comment.