Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit ecdd92b

Browse files
committed
Fixed errors and typos
1 parent 78aad07 commit ecdd92b

14 files changed

+59
-11
lines changed

CHANGELOG.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22

33
All notable changes to `Firestore PHP` will be documented in this file.
44

5-
## 2.0.0 - 2019-02-XX
5+
## 2.0.1 - 2019-02-25
6+
- Documentation error and typos fixed.
7+
- Saving last response when Guzzle's `BadResponseException` exception throws.
8+
- Had to use `git mv` to rename files changed in `2.0.0`
9+
- Added `has` method to validate key existence.
10+
11+
## 2.0.0 - 2019-02-23
612
- Added Firebase Authentication
7-
- All files prefixed changed from `FireStore` to `Firestore`
13+
- All files prefixed changed from `FireStore` to `Firestore` (notice the `s` in *store*)
814
- Added `Bytes` support.
915
- Exception handling support added.
1016
- Support added to list all documents, batch listing with query parameter.
1117
- Pagination support for bulk and document listing.
1218
- Improved naming convention throughout the package.
13-
- Many more..
19+
- `FireStoreApiClient` changed to `FirestoreClient`
20+
- Documentation updated
1421

1522
## 1.0.1 - 2019-01-16
1623
- Add method for casting floating point values

README.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ or install it by adding it to `composer.json` then run `composer update`
2424

2525
```javascript
2626
"require": {
27-
"ahsankhatri/ahsankhatri/firestore-php": "^2.0",
27+
"ahsankhatri/firestore-php": "^2.0",
2828
}
2929
```
3030

@@ -43,7 +43,7 @@ If you use Composer, these dependencies should be handled automatically. If you
4343
#### Initialization
4444

4545
```php
46-
$firestoreClient = new FirestoreApiClient('project-id', 'AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', [
46+
$firestoreClient = new FirestoreClient('project-id', 'AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', [
4747
'database' => '(default)',
4848
]);
4949
```
@@ -84,7 +84,7 @@ $document->setNull('null', null);
8484
$document->setString('string', 'abc123');
8585
$document->setInteger('integer', 123456);
8686
$document->setArray('arrayRaw', ['string'=>'abc123']);
87-
$document->setBytes('bytes', 'bytesdata');
87+
$document->setBytes('bytes', new FirestoreBytes('bytesdata'));
8888
$document->setArray('arrayObject', new FirestoreArray(['string' => 'abc123']));
8989
$document->setTimestamp('timestamp', new FirestoreTimestamp);
9090
$document->setGeoPoint('geopoint', new FirestoreGeoPoint(1.11,1.11));
@@ -154,6 +154,19 @@ $collections = $firestoreClient->listDocuments('users', [
154154

155155
**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)
156156

157+
#### Get field from document
158+
159+
```php
160+
$document->get('bytes')->parseValue(); // will return bytes decoded value.
161+
162+
// Catch field that doesn't exist in document
163+
try {
164+
$document->get('allowed_notification');
165+
} catch (\MrShan0\PHPFirestore\Exceptions\Client\FieldNotFound $e) {
166+
// Set default value
167+
}
168+
```
169+
157170
### Firebase Authentication
158171

159172
#### Sign in with Email and Password.

src/Authentication/FirestoreAuthentication.php

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ private function authRequest($method, $resource, array $options = [])
152152

153153
return FirestoreHelper::decode((string) $this->client->getLastResponse()->getBody());
154154
} catch (BadResponseException $exception) {
155+
$this->setLastResponse($exception->getResponse());
155156
$this->handleError($exception);
156157
}
157158
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace MrShan0\PHPFirestore\Exceptions\Client;
4+
5+
class FieldTypeError extends \Exception
6+
{
7+
public function __construct($response)
8+
{
9+
$message = 'Unexpected field type detected. Received type: '.$response;
10+
parent::__construct($message);
11+
}
12+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/FirestoreClient.php

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ public function request($method, $path, array $options = [], array $parameters =
350350
$this->setLastResponse($response);
351351
$body = FirestoreHelper::decode((string) $response->getBody());
352352
} catch (BadResponseException $exception) {
353+
$this->setLastResponse($exception->getResponse());
353354
$this->handleError($exception);
354355
}
355356

src/FireStoreDocument.php src/FirestoreDocument.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
namespace MrShan0\PHPFirestore;
44

5-
use Exception;
65
use DateTime;
6+
use Exception;
77
use MrShan0\PHPFirestore\Attributes\FirestoreDeleteAttribute;
88
use MrShan0\PHPFirestore\Exceptions\Client\FieldNotFound;
9+
use MrShan0\PHPFirestore\Exceptions\Client\FieldTypeError;
910
use MrShan0\PHPFirestore\Fields\FirestoreArray;
11+
use MrShan0\PHPFirestore\Fields\FirestoreBytes;
1012
use MrShan0\PHPFirestore\Fields\FirestoreGeoPoint;
1113
use MrShan0\PHPFirestore\Fields\FirestoreObject;
1214
use MrShan0\PHPFirestore\Fields\FirestoreReference;
1315
use MrShan0\PHPFirestore\Fields\FirestoreTimestamp;
14-
use MrShan0\PHPFirestore\Fields\FirestoreBytes;
1516
use MrShan0\PHPFirestore\Helpers\FirestoreHelper;
1617

1718
class FirestoreDocument {
@@ -347,7 +348,7 @@ public function getNull($value)
347348
/**
348349
* @return void
349350
*/
350-
public function setBytes($fieldName, $value)
351+
public function setBytes($fieldName, FirestoreBytes $value)
351352
{
352353
$this->fields[$fieldName] = [
353354
'bytesValue' => FirestoreHelper::base64encode($value->getData()),
@@ -365,6 +366,8 @@ public function getBytes($value)
365366
}
366367

367368
/**
369+
* A placeholder to delete particular keys from database
370+
*
368371
* @param string $fieldName
369372
*
370373
* @return string
@@ -375,7 +378,7 @@ public function setDelete($fieldName)
375378
}
376379

377380
/**
378-
* A placeholder to delete particular keys from database
381+
* Delete keys in bulk
379382
*
380383
* @param string|array
381384
*
@@ -409,6 +412,17 @@ public function _getRawField($fieldName)
409412
throw new FieldNotFound($fieldName);
410413
}
411414

415+
/**
416+
* Check whether document has such field or not.
417+
*
418+
* @param string $fieldName
419+
* @return boolean
420+
*/
421+
public function has($fieldName)
422+
{
423+
return (array_key_exists($fieldName, $this->fields) && !$this->fields[$fieldName] instanceof FirestoreDeleteAttribute);
424+
}
425+
412426
/**
413427
* Extract value from object by key
414428
*
@@ -419,7 +433,7 @@ public function _getRawField($fieldName)
419433
*/
420434
public function get($fieldName)
421435
{
422-
if (array_key_exists($fieldName, $this->fields) && !$this->fields[$fieldName] instanceof FirestoreDeleteAttribute) {
436+
if ($this->has($fieldName)) {
423437
$result = $this->castValue($this->fields[$fieldName]);
424438

425439
return $result;
File renamed without changes.

0 commit comments

Comments
 (0)