@@ -20,12 +20,21 @@ You can install the package via composer:
20
20
composer require ahsankhatri/firestore-php
21
21
```
22
22
23
+ or install it by adding it to ` composer.json ` then run ` composer update `
24
+
25
+ ``` javascript
26
+ " require" : {
27
+ " ahsankhatri/ahsankhatri/firestore-php" : " ^2.0" ,
28
+ }
29
+ ```
30
+
23
31
## Dependencies
24
32
25
33
The bindings require the following extensions in order to work properly:
26
34
27
35
- [ ` curl ` ] ( https://secure.php.net/manual/en/book.curl.php )
28
36
- [ ` json ` ] ( https://secure.php.net/manual/en/book.json.php )
37
+ - [ ` guzzlehttp/guzzle ` ] ( https://packagist.org/packages/guzzlehttp/guzzle )
29
38
30
39
If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.
31
40
@@ -34,7 +43,7 @@ If you use Composer, these dependencies should be handled automatically. If you
34
43
#### Initialization
35
44
36
45
``` php
37
- $firestoreClient = new FireStoreApiClient ('project-id', 'AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', [
46
+ $firestoreClient = new FirestoreApiClient ('project-id', 'AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', [
38
47
'database' => '(default)',
39
48
]);
40
49
```
@@ -51,32 +60,35 @@ $firestoreClient->addDocument($collection, [
51
60
'arrayRaw' => [
52
61
'string' => 'abc123',
53
62
],
54
- 'array' => new FireStoreArray([
63
+ 'bytes' => new FirestoreBytes('bytesdata'),
64
+ 'array' => new FirestoreArray([
55
65
'string' => 'abc123',
56
66
]),
57
- 'reference' => new FireStoreReference ('/users/23'),
58
- 'object' => new FireStoreObject (['nested1' => new FireStoreObject (['nested2' => new FireStoreObject (['nested3' => 'test'])])]),
59
- 'timestamp' => new FireStoreTimestamp ,
60
- 'geopoint' => new FireStoreGeoPoint (1,1),
67
+ 'reference' => new FirestoreReference ('/users/23'),
68
+ 'object' => new FirestoreObject (['nested1' => new FirestoreObject (['nested2' => new FirestoreObject (['nested3' => 'test'])])]),
69
+ 'timestamp' => new FirestoreTimestamp ,
70
+ 'geopoint' => new FirestoreGeoPoint (1,1),
61
71
]);
62
72
```
63
73
64
- ** NOTE:** Pass third argument if you want your custom _ document id _ to set else auto-id will generate it for you.
74
+ ** NOTE:** Pass third argument if you want your custom ** document id ** to set else auto-id will generate it for you.
65
75
66
76
Or
67
77
68
78
``` php
69
- $document = new FireStoreDocument ;
70
- $document->setObject('sdf', new FireStoreObject (['nested1' => new FireStoreObject (['nested2' => new FireStoreObject (['nested3' => 'test'])])]));
79
+ $document = new FirestoreDocument ;
80
+ $document->setObject('sdf', new FirestoreObject (['nested1' => new FirestoreObject (['nested2' => new FirestoreObject (['nested3' => 'test'])])]));
71
81
$document->setBoolean('booleanTrue', true);
72
82
$document->setBoolean('booleanFalse', false);
73
83
$document->setNull('null', null);
74
84
$document->setString('string', 'abc123');
75
85
$document->setInteger('integer', 123456);
76
86
$document->setArray('arrayRaw', ['string'=>'abc123']);
77
- $document->setArray('arrayObject', new FireStoreArray(['string' => 'abc123']));
78
- $document->setTimestamp('timestamp', new FireStoreTimestamp);
79
- $document->setGeoPoint('geopoint', new FireStoreGeoPoint(1.11,1.11));
87
+ $document->setBytes('bytes', 'bytesdata');
88
+ $document->setArray('arrayObject', new FirestoreArray(['string' => 'abc123']));
89
+ $document->setTimestamp('timestamp', new FirestoreTimestamp);
90
+ $document->setGeoPoint('geopoint', new FirestoreGeoPoint(1.11,1.11));
91
+
80
92
$firestoreClient->addDocument($collection, $document, 'customDocumentId');
81
93
```
82
94
@@ -89,25 +101,36 @@ $document->fillValues([
89
101
]);
90
102
```
91
103
92
- #### Updating a document
104
+ #### Inserting/ Updating a document
93
105
94
- - Update existing document
106
+ - Update (Merge) or Insert document
107
+
108
+ Following will merge document (if exist) else insert the data.
95
109
96
110
``` php
97
- $firestoreClient->updateDocument($collection, $documentId , [
98
- 'newFieldToAdd' => new FireStoreTimestamp (new DateTime('2018-04-20 15:00:00')),
99
- 'existingFieldToRemove' => new FireStoreDeleteAttribute
100
- ], true );
111
+ $firestoreClient->updateDocument($documentRoot , [
112
+ 'newFieldToAdd' => new FirestoreTimestamp (new DateTime('2018-04-20 15:00:00')),
113
+ 'existingFieldToRemove' => new FirestoreDeleteAttribute
114
+ ]);
101
115
```
102
116
103
- ** NOTE:** Passing 3rd argument as a boolean _ true_ will indicate that document must exist and vice-versa.
117
+ ** NOTE:** Passing 3rd argument as a boolean _ true_ will force check that document must exist and vice-versa in order to perform update operation.
118
+
119
+ For example: If you want to update document only if exist else ` MrShan0\PHPFirestore\Exceptions\Client\NotFound ` (Exception) will be thrown.
104
120
105
- - Overwrite existing document
121
+ ``` php
122
+ $firestoreClient->updateDocument($documentPath, [
123
+ 'newFieldToAdd' => new FirestoreTimestamp(new DateTime('2018-04-20 15:00:00')),
124
+ 'existingFieldToRemove' => new FirestoreDeleteAttribute
125
+ ], true);
126
+ ```
127
+
128
+ - Overwirte or Insert document
106
129
107
130
``` php
108
131
$firestoreClient->setDocument($collection, $documentId, [
109
- 'newFieldToAdd' => new FireStoreTimestamp (new DateTime('2018-04-20 15:00:00')),
110
- 'existingFieldToRemove' => new FireStoreDeleteAttribute
132
+ 'newFieldToAdd' => new FirestoreTimestamp (new DateTime('2018-04-20 15:00:00')),
133
+ 'existingFieldToRemove' => new FirestoreDeleteAttribute
111
134
], [
112
135
'exists' => true, // Indicate document must exist
113
136
]);
@@ -120,12 +143,49 @@ $collection = 'collection/document/innerCollection';
120
143
$firestoreClient->deleteDocument($collection, $documentId);
121
144
```
122
145
146
+ #### List documents with pagination (or custom parameters)
147
+
148
+ ``` php
149
+ $collections = $firestoreClient->listDocuments('users', [
150
+ 'pageSize' => 1,
151
+ 'pageToken' => 'nextpagetoken'
152
+ ]);
153
+ ```
154
+
155
+ ** Note:** You can pass custom parameters as supported by [ firestore list document] ( https://firebase.google.com/docs/firestore/reference/rest/v1/projects.databases.documents/list#query-parameters )
156
+
157
+ ### Firebase Authentication
158
+
159
+ #### Sign in with Email and Password.
160
+
161
+ ``` php
162
+ $firestoreClient
163
+ ->authenticator()
164
+ ->signInEmailPassword('testuser@example.com', 'abc123');
165
+ ```
166
+
167
+ #### Sign in Anonymously.
168
+
169
+ ``` php
170
+ $firestoreClient
171
+ ->authenticator()
172
+ ->signInAnonymously();
173
+ ```
174
+
175
+ ### Retrieve Auth Token
176
+
177
+ ``` php
178
+ $authToken = $firestoreClient->authenticator()->getAuthToken();
179
+ ```
180
+
123
181
### TODO
124
182
- [x] Added delete attribute support.
125
- - [x] Add Support for Object, Boolean, Null, String, Integer, Array, Timestamp, GeoPoint
126
- - [ ] Add Exception Handling.
127
- - [ ] List all documents and collections.
128
- - [ ] Filters and pagination support.
183
+ - [x] Add Support for Object, Boolean, Null, String, Integer, Array, Timestamp, GeoPoint, Bytes
184
+ - [x] Add Exception Handling.
185
+ - [x] List all documents.
186
+ - [ ] List all collections.
187
+ - [x] Filters and pagination support.
188
+ - [ ] Structured Query support.
129
189
- [ ] Transaction support.
130
190
- [ ] Indexes support.
131
191
- [ ] Entire collection delete support.
0 commit comments